diff --git a/nixd/lib/Controller/Completion.cpp b/nixd/lib/Controller/Completion.cpp index 6f7347f32..efce25955 100644 --- a/nixd/lib/Controller/Completion.cpp +++ b/nixd/lib/Controller/Completion.cpp @@ -6,6 +6,8 @@ #include "AST.h" #include "Convert.h" +#include "lspserver/Protocol.h" + #include "nixd/Controller/Controller.h" #include @@ -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(); diff --git a/nixd/tools/nixd/test/completion-comment.md b/nixd/tools/nixd/test/completion-comment.md new file mode 100644 index 000000000..8e6c05387 --- /dev/null +++ b/nixd/tools/nixd/test/completion-comment.md @@ -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"} +```