From dad49ea93797833eed2dee288c15c8130953406b Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Mon, 29 Apr 2024 09:20:12 +0800 Subject: [PATCH] libnixt: stop at concrete options, rather than select into it. (#474) Fixes: https://github.com/nix-community/nixd/issues/469#issuecomment-2081107429 --- nixd/lib/Eval/AttrSetProvider.cpp | 5 ++ .../tools/nixd/test/completion-option-stop.md | 72 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 nixd/tools/nixd/test/completion-option-stop.md diff --git a/nixd/lib/Eval/AttrSetProvider.cpp b/nixd/lib/Eval/AttrSetProvider.cpp index 9ae8cd635..b626a291c 100644 --- a/nixd/lib/Eval/AttrSetProvider.cpp +++ b/nixd/lib/Eval/AttrSetProvider.cpp @@ -264,6 +264,11 @@ void AttrSetProvider::onOptionComplete( return; } + if (nixt::isOption(state(), Scope)) { + Reply(error("scope is already an option")); + return; + } + std::vector Response; // FIXME: we may want to use "Trie" to speedup the string searching. diff --git a/nixd/tools/nixd/test/completion-option-stop.md b/nixd/tools/nixd/test/completion-option-stop.md new file mode 100644 index 000000000..56a430873 --- /dev/null +++ b/nixd/tools/nixd/test/completion-option-stop.md @@ -0,0 +1,72 @@ +# 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":"{ bar = 1; foo.bar. }" + } + } +} +``` + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "textDocument/completion", + "params": { + "textDocument": { + "uri": "file:///completion.nix" + }, + "position": { + "line": 0, + "character": 19 + }, + "context": { + "triggerKind": 1 + } + } +} +``` + +``` + CHECK: "id": 1, +CHECK-NEXT: "jsonrpc": "2.0", +CHECK-NEXT: "result": { +CHECK-NEXT: "isIncomplete": false, +CHECK-NEXT: "items": [] +``` + + +```json +{"jsonrpc":"2.0","method":"exit"} +```