Skip to content

Commit 93d37be

Browse files
nixd: enable autocomplete and hover info in config sets
In NixOS modules options can be defined at the top-level, e.g: { foo = true; } or inside of `config`, e.g: { config = { foo = true; }; } Autocompletion and hover information before only worked for the former because the option resolving code had no special handling for `config`. Fixes #566.
1 parent 3aa27fd commit 93d37be

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

nixd/lib/Controller/Completion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ void completeAttrPath(const Node &N, const ParentMapAnalysis &PM,
280280
// Construct request.
281281
std::string Prefix = Scope.back();
282282
Scope.pop_back();
283+
if (!Scope.empty() && Scope[0] == "config") {
284+
Scope.erase(Scope.begin());
285+
}
283286
{
284287
std::lock_guard _(OptionsLock);
285288
completeAttrName(Scope, Prefix, Options, Snippets, Items);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# RUN: nixd --lit-test \
2+
# RUN: --nixos-options-expr="{ foo.bar = { _type = \"option\"; }; }" \
3+
# RUN: < %s | FileCheck %s
4+
5+
<-- initialize(0)
6+
7+
```json
8+
{
9+
"jsonrpc":"2.0",
10+
"id":0,
11+
"method":"initialize",
12+
"params":{
13+
"processId":123,
14+
"rootPath":"",
15+
"capabilities":{
16+
},
17+
"trace":"off"
18+
}
19+
}
20+
```
21+
22+
23+
<-- textDocument/didOpen
24+
25+
26+
```json
27+
{
28+
"jsonrpc":"2.0",
29+
"method":"textDocument/didOpen",
30+
"params":{
31+
"textDocument":{
32+
"uri":"file:///completion.nix",
33+
"languageId":"nix",
34+
"version":1,
35+
"text":"{ config = { fo }; }"
36+
}
37+
}
38+
}
39+
```
40+
41+
```json
42+
{
43+
"jsonrpc": "2.0",
44+
"id": 1,
45+
"method": "textDocument/completion",
46+
"params": {
47+
"textDocument": {
48+
"uri": "file:///completion.nix"
49+
},
50+
"position": {
51+
"line": 0,
52+
"character": 15
53+
},
54+
"context": {
55+
"triggerKind": 1
56+
}
57+
}
58+
}
59+
```
60+
61+
```
62+
CHECK: "id": 1,
63+
CHECK-NEXT: "jsonrpc": "2.0",
64+
CHECK-NEXT: "result": {
65+
CHECK-NEXT: "isIncomplete": false,
66+
CHECK-NEXT: "items": [
67+
CHECK-NEXT: {
68+
CHECK-NEXT: "data": "",
69+
CHECK-NEXT: "detail": "nixos",
70+
CHECK-NEXT: "kind": 7,
71+
CHECK-NEXT: "label": "foo",
72+
CHECK-NEXT: "score": 0
73+
CHECK-NEXT: }
74+
CHECK-NEXT: ]
75+
CHECK-NEXT: }
76+
```
77+
78+
79+
```json
80+
{"jsonrpc":"2.0","method":"exit"}
81+
```

0 commit comments

Comments
 (0)