From 16764dcc00ff06bb3ae015455334663e6dd1174c Mon Sep 17 00:00:00 2001 From: Andrew Onyshchuk Date: Tue, 17 Jun 2025 17:41:48 -0700 Subject: [PATCH 1/3] Fix attrset completions Display all available completion options within the current attrset even if it's empty or there is no text under the cursor. --- nixd/lib/Controller/AST.cpp | 10 ++++++++++ nixd/lib/Controller/Completion.cpp | 5 +++-- nixd/tools/nixd/test/completion/comment.md | 10 +++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/nixd/lib/Controller/AST.cpp b/nixd/lib/Controller/AST.cpp index 061bc87cb..c37032b80 100644 --- a/nixd/lib/Controller/AST.cpp +++ b/nixd/lib/Controller/AST.cpp @@ -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; } diff --git a/nixd/lib/Controller/Completion.cpp b/nixd/lib/Controller/Completion.cpp index 0e5e08621..14938feea 100644 --- a/nixd/lib/Controller/Completion.cpp +++ b/nixd/lib/Controller/Completion.cpp @@ -384,13 +384,14 @@ void Controller::onCompletion(const CompletionParams &Params, return Reply([&]() -> llvm::Expected { 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); 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; diff --git a/nixd/tools/nixd/test/completion/comment.md b/nixd/tools/nixd/test/completion/comment.md index a7c78609c..2a46e6d95 100644 --- a/nixd/tools/nixd/test/completion/comment.md +++ b/nixd/tools/nixd/test/completion/comment.md @@ -52,7 +52,15 @@ CHECK-NEXT: "jsonrpc": "2.0", CHECK-NEXT: "result": { CHECK-NEXT: "isIncomplete": false, -CHECK-NEXT: "items": [] +CHECK-NEXT: "items": [ +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: } ``` From 8452e4ac5ca6887ca0069e437c73328fb50c2c67 Mon Sep 17 00:00:00 2001 From: Andrew Onyshchuk Date: Tue, 24 Jun 2025 17:59:53 -0700 Subject: [PATCH 2/3] Increase max completion items --- nixd/lib/Controller/Completion.cpp | 2 +- nixd/lib/Eval/AttrSetProvider.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nixd/lib/Controller/Completion.cpp b/nixd/lib/Controller/Completion.cpp index 14938feea..04b80cb31 100644 --- a/nixd/lib/Controller/Completion.cpp +++ b/nixd/lib/Controller/Completion.cpp @@ -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; diff --git a/nixd/lib/Eval/AttrSetProvider.cpp b/nixd/lib/Eval/AttrSetProvider.cpp index 41ac27f25..e0e356cb8 100644 --- a/nixd/lib/Eval/AttrSetProvider.cpp +++ b/nixd/lib/Eval/AttrSetProvider.cpp @@ -14,7 +14,7 @@ using namespace lspserver; namespace { -constexpr int MaxItems = 30; +constexpr int MaxItems = 1000; void fillString(nix::EvalState &State, nix::Value &V, const std::vector &AttrPath, From 4cd9d17b30fc3bdc8becdd98d91dc3e305c6eb3d Mon Sep 17 00:00:00 2001 From: Andrew Onyshchuk Date: Tue, 24 Jun 2025 17:59:53 -0700 Subject: [PATCH 3/3] Remove completion prefix filtering --- nixd/lib/Controller/Completion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixd/lib/Controller/Completion.cpp b/nixd/lib/Controller/Completion.cpp index 04b80cb31..983a71877 100644 --- a/nixd/lib/Controller/Completion.cpp +++ b/nixd/lib/Controller/Completion.cpp @@ -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);