Skip to content

Completion fixes #698

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions nixd/lib/Controller/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ nixd::FindAttrPathResult nixd::findAttrPath(const nixf::Node &N,
}
}

if (const Node *ExprAttrs = PM.upTo(N, Node::NK_ExprAttrs)) {
try {
getValueAttrPath(*ExprAttrs, PM, Path);
Path.emplace_back("");
return R::OK;
} catch (AttrPathHasDynamicError &E) {
return R::WithDynamic;
}
}

return R::NotAttrPath;
}

Expand Down
9 changes: 5 additions & 4 deletions nixd/lib/Controller/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace {
/// Set max completion size to this value, we don't want to send large lists
/// because of slow IO.
/// Items exceed this size should be marked "incomplete" and recomputed.
constexpr int MaxCompletionSize = 30;
constexpr int MaxCompletionSize = 1000;

CompletionItemKind OptionKind = CompletionItemKind::Constructor;
CompletionItemKind OptionAttrKind = CompletionItemKind::Class;
Expand Down Expand Up @@ -278,7 +278,7 @@ void completeAttrPath(const Node &N, const ParentMapAnalysis &PM,
auto R = findAttrPathForOptions(N, PM, Scope);
if (R == PathResult::OK) {
// Construct request.
std::string Prefix = Scope.back();
std::string Prefix = "";
Scope.pop_back();
{
std::lock_guard _(OptionsLock);
Expand Down Expand Up @@ -384,13 +384,14 @@ void Controller::onCompletion(const CompletionParams &Params,
return Reply([&]() -> llvm::Expected<CompletionList> {
const auto TU = CheckDefault(getTU(File));
const auto AST = CheckDefault(getAST(*TU));

const auto *Desc = AST->descend({Pos, Pos});
CheckDefault(Desc && Desc->children().empty());
CheckDefault(Desc);
Copy link
Member

Choose a reason for hiding this comment

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

This line of code previously protected us from providing code completions within "comments."


const auto &N = *Desc;
const auto &PM = *TU->parentMap();
const auto &UpExpr = *CheckDefault(PM.upExpr(N));
CheckDefault(Desc->children().empty() ||
UpExpr.kind() == Node::NK_ExprAttrs);

return [&]() {
CompletionList List;
Expand Down
2 changes: 1 addition & 1 deletion nixd/lib/Eval/AttrSetProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace lspserver;

namespace {

constexpr int MaxItems = 30;
constexpr int MaxItems = 1000;
Copy link
Member

Choose a reason for hiding this comment

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

What is the motivation or necessity behind this?


void fillString(nix::EvalState &State, nix::Value &V,
const std::vector<std::string_view> &AttrPath,
Expand Down
10 changes: 9 additions & 1 deletion nixd/tools/nixd/test/completion/comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@
CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": {
CHECK-NEXT: "isIncomplete": false,
CHECK-NEXT: "items": []
CHECK-NEXT: "items": [
Copy link
Member

Choose a reason for hiding this comment

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

I think the previous version gave more accurate results because the current "completion" feature is essentially providing completions within the "comments," which might confuse users.

CHECK-NEXT: {
CHECK-NEXT: "data": "",
CHECK-NEXT: "detail": "nixos",
CHECK-NEXT: "kind": 7,
CHECK-NEXT: "label": "foo",
CHECK-NEXT: "score": 0
CHECK-NEXT: }
CHECK-NEXT: ]
CHECK-NEXT: }
```

Expand Down