Skip to content

Commit

Permalink
nixd/Controller: fix crashing on empty selector idiom in completion (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Jul 26, 2024
1 parent cee9c27 commit 4c306e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 6 additions & 2 deletions nixd/lib/Controller/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void completeAttrPath(const Node &N, const ParentMapAnalysis &PM,
}

AttrPathCompleteParams mkParams(nixd::Selector Sel, bool IsComplete) {
if (IsComplete) {
if (IsComplete || Sel.empty()) {
return {
.Scope = std::move(Sel),
.Prefix = "",
Expand All @@ -314,9 +314,13 @@ void completeVarName(const VariableLookupAnalysis &VLA,
// Try to complete the name by known idioms.
try {
Selector Sel = mkIdiomSelector(N, VLA, PM);
NixpkgsCompletionProvider NCP(Client);

// Clickling "pkgs" does not make sense for variable completion
if (Sel.empty())
return;

// Invoke nixpkgs provider to get the completion list.
NixpkgsCompletionProvider NCP(Client);
// Variable names are always incomplete.
NCP.completePackages(mkParams(Sel, /*IsComplete=*/false), List);
} catch (ExceedSizeError &) {
Expand Down
16 changes: 6 additions & 10 deletions nixd/tools/nixd/test/completion/pkgs.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# RUN: nixd --lit-test \
# RUN: --nixpkgs-expr="{ lib.hello.meta.description = \"Very Nice\"; }" \
# RUN: --nixpkgs-expr='--nixpkgs-expr={ x = 1; y = 2; };' \
# RUN: < %s | FileCheck %s
# XFAIL: *


<-- initialize(0)
Expand Down Expand Up @@ -61,15 +60,12 @@
```

```
CHECK: "isIncomplete": false,
CHECK-NEXT: "items": [
CHECK-NEXT: {
CHECK-NEXT: "data": "{\"Prefix\":\"hel\",\"Scope\":[\"lib\"]}",
CHECK-NEXT: "kind": 5,
CHECK-NEXT: "label": "hello",
CHECK-NEXT: "score": 0
CHECK: "id": 1,
CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": {
CHECK-NEXT: "isIncomplete": false,
CHECK-NEXT: "items": []
CHECK-NEXT: }
CHECK-NEXT: ]
```


Expand Down

0 comments on commit 4c306e7

Please sign in to comment.