You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2024. It is now read-only.
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 <[email protected]>
0 commit comments