Skip to content

Commit

Permalink
nixd: suppress completion if the node is not leaf (#522)
Browse files Browse the repository at this point in the history
Fixes: #521
  • Loading branch information
inclyc authored Jun 11, 2024
1 parent be5ad5e commit e7e37d9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nixd/lib/Controller/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "AST.h"
#include "Convert.h"

#include "lspserver/Protocol.h"

#include "nixd/Controller/Controller.h"

#include <boost/asio/post.hpp>
Expand Down Expand Up @@ -277,6 +279,10 @@ void Controller::onCompletion(const CompletionParams &Params,
Reply(error("cannot find corresponding node on given position"));
return;
}
if (!Desc->children().empty()) {
Reply(CompletionList{});
return;
}
CompletionList List;
try {
const ParentMapAnalysis &PM = *TU->parentMap();
Expand Down
73 changes: 73 additions & 0 deletions nixd/tools/nixd/test/completion-comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# RUN: nixd --lit-test \
# RUN: --nixos-options-expr="{ foo.bar = { _type = \"option\"; }; }" \
# RUN: < %s | FileCheck %s

<-- initialize(0)

```json
{
"jsonrpc":"2.0",
"id":0,
"method":"initialize",
"params":{
"processId":123,
"rootPath":"",
"capabilities": {
},
"trace":"off"
}
}
```


<-- textDocument/didOpen


```json
{
"jsonrpc":"2.0",
"method":"textDocument/didOpen",
"params":{
"textDocument":{
"uri":"file:///completion.nix",
"languageId":"nix",
"version":1,
"text":"{ x = 1; y = /* */2;}"
}
}
}
```

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "textDocument/completion",
"params": {
"textDocument": {
"uri": "file:///completion.nix"
},
"position": {
"line": 0,
"character": 16
},
"context": {
"triggerKind": 1
}
}
}
```

```
CHECK: "id": 1,
CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": {
CHECK-NEXT: "isIncomplete": false,
CHECK-NEXT: "items": []
CHECK-NEXT: }
```


```json
{"jsonrpc":"2.0","method":"exit"}
```

0 comments on commit e7e37d9

Please sign in to comment.