This repository was archived by the owner on Jan 25, 2024. It is now read-only.
Commit fd1ad49
Enhance completion details for builtins if Nix 2.4 is available (#27)
A hidden feature of Nix 2.4+ (a.k.a. `nixUnstable`) is `nix
__dump-builtins` which returns a JSON giving details about built in
functions.
This change basically does the following things:
* It checks whether Nix 2.4 is available on `$PATH`[1]. In that case
built-in functions are retrieved via `nix __dump-builtins`[2].
If not, the hard-coded list of builtins is used as a fallback.
* If builtins can be retrieved from Nix, the following additional things
are added to `CompletionItem`:
* The `documentation`[3] field containing markdown documentation for the
function is added. This will be shown in editors as one is used to
it from e.g. doc-block comments in other languages.
* A very basic parameter info is provided. E.g. for
`builtins.removeAttrs` the popup shows `Lambda: set -> list ->
Result`. While this is fairly basic, it's IMHO a small benefit to
make sure one's not forgetting the order of parameters.
Please note that this will currently display *wrong* info if
a built-in is called via `lib.flip`.
* If `**DEPRECATED.**` is at the beginning of `documentation`, the
built-in is marked in the LSP response as `deprecated`. While this
is a gross hack, it ensures that the only deprecated builtin
(`builtins.toPath`) is actually marked as such.
[1] Please note that this means that you can wrap `$PATH` for `rnix-lsp`
to have this feature without being forced to use `nixUnstable` on
your system.
[2] As this is only an optional feature (and hence a loose dependency to
Nix) I decided against using an FFI and thus keeping the build
process rather simple.
[3] https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
Co-authored-by: jD91mZM2 <me@krake.one>1 parent 6c12d7f commit fd1ad49
4 files changed
+110
-13
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
32 | 81 | | |
33 | 82 | | |
34 | 83 | | |
35 | 84 | | |
36 | 85 | | |
37 | 86 | | |
38 | | - | |
| 87 | + | |
| 88 | + | |
39 | 89 | | |
40 | 90 | | |
41 | 91 | | |
42 | 92 | | |
43 | 93 | | |
44 | | - | |
| 94 | + | |
45 | 95 | | |
46 | 96 | | |
47 | 97 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 98 | + | |
52 | 99 | | |
53 | 100 | | |
54 | | - | |
| 101 | + | |
55 | 102 | | |
56 | 103 | | |
57 | 104 | | |
58 | 105 | | |
59 | | - | |
| 106 | + | |
60 | 107 | | |
61 | 108 | | |
62 | 109 | | |
| |||
118 | 165 | | |
119 | 166 | | |
120 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
121 | 213 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
276 | 276 | | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
| 280 | + | |
| 281 | + | |
279 | 282 | | |
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
283 | | - | |
| 286 | + | |
284 | 287 | | |
285 | 288 | | |
286 | 289 | | |
| |||
0 commit comments