Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixd: path completion #530

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup codes
  • Loading branch information
Origami404 committed Jun 24, 2024
commit f1d74ed519fdccfc1cc683562ebfdc2beff77810
2 changes: 1 addition & 1 deletion libnixf/test/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <gtest/gtest.h>

#include "Lexer.h"

#include "Token.h"
Origami404 marked this conversation as resolved.
Show resolved Hide resolved

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Basic/TokenKinds.h"

Expand Down
40 changes: 16 additions & 24 deletions nixd/lib/Controller/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,11 @@ void Controller::onCompletion(const CompletionParams &Params,
}
CompletionList List;
try {
bool FinishedCompletion = false;
const ParentMapAnalysis &PM = *TU->parentMap();

// if we are in an attribute path, use AttrCompletionProvider only
std::vector<std::string> Scope;
if (findAttrPath(*Desc, PM, Scope) == FindAttrPathResult::OK) {
using PathResult = FindAttrPathResult;
auto R = findAttrPath(*Desc, PM, Scope);
if (R == PathResult::OK) {
// Construct request.
std::string Prefix = Scope.back();
Scope.pop_back();
Expand All @@ -338,32 +337,25 @@ void Controller::onCompletion(const CompletionParams &Params,
completeAttrName(Scope, Prefix, Options,
ClientCaps.CompletionSnippets, List.items);
}
FinishedCompletion = true;
}

// if we are in a literal path, use PathCompletionProvider only
if (!FinishedCompletion) {
} else {
const auto *Parent = PM.upExpr(*Desc);
// if we are in a literal path, use PathCompletionProvider
if (Parent->kind() == Node::NK_ExprPath) {
const auto &Path = static_cast<const nixf::ExprPath &>(*Parent);
if (Path.parts().isLiteral()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Path.parts().isLiteral()) {
if (Path.parts().isLiteral())

remove this curly brace?

completeExprPath(File, Path, List.items);
FinishedCompletion = true;
}
}
}

// otherwise, fallback to VLACompletionProvider
if (!FinishedCompletion) {
const VariableLookupAnalysis &VLA = *TU->variableLookup();
VLACompletionProvider VLAP(VLA);
VLAP.complete(*Desc, List.items, PM);
if (havePackageScope(*Desc, VLA, PM)) {
// Append it with nixpkgs completion
// FIXME: handle null nixpkgsClient()
NixpkgsCompletionProvider NCP(*nixpkgsClient());
auto [Scope, Prefix] = getScopeAndPrefix(*Desc, PM);
NCP.completePackages(Scope, Prefix, List.items);
} else {
const VariableLookupAnalysis &VLA = *TU->variableLookup();
VLACompletionProvider VLAP(VLA);
VLAP.complete(*Desc, List.items, PM);
if (havePackageScope(*Desc, VLA, PM)) {
// Append it with nixpkgs completion
// FIXME: handle null nixpkgsClient()
NixpkgsCompletionProvider NCP(*nixpkgsClient());
auto [Scope, Prefix] = getScopeAndPrefix(*Desc, PM);
NCP.completePackages(Scope, Prefix, List.items);
}
}
}
// Next, add nixpkgs provided names.
Expand Down
Loading