nixd icon indicating copy to clipboard operation
nixd copied to clipboard

No completion available in flakes

Open antoineco opened this issue 1 year ago • 8 comments

Describe the bug

Inside Neovim, I am not seeing any relevant completion, or even hover information, while editing a flake.

I do see LSP progress events emitted by nixd (below), but no relevant LSP feature seems to be functional.

# lsp progress
nixd [evaluating nixpkgs entries]
nixd [evaluating nixos options]
nixd [evaluating nixpkgs entries] evaluated nixpkgs entries
nixd [evaluating nixos options] evaluated nixos options

Logs (Required)

[START][2024-08-03 10:21:29] LSP logging initiated
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:29.372] 81282: <-- "
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"initialize(1)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.372] 81282: --> reply:initialize(1)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.372] 81282: --> call window/workDoneProgress/create(1)\nI[10:21:29.373] 81282: --> notify $/progress\nI[10:21:29.373] 81282: --> call attrset/evalExpr(1)\nI[10:21:29.373] 81282: --> call window/workDoneProgress/create(2)\nI[10:21:29.373] 81282: --> notify $/progress\nI[10:21:29.373] 81282: --> call attrset/evalExpr(1)\nI[10:21:29.373"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"] 81282: --> call workspace/configuration(3)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.373] 81282: <-- initialized\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.373] 81282: <-- textDocument/didOpen\nI[10:21:29.373] 81282: --> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.373] 81282: <-- textDocument/semanticTokens/full(2)\nI[10:21:29.373] 81282: --> reply:textDocument/semanticTokens/full(2)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.374] 81282: <-- reply(1)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.374] 81282: <-- reply(2)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.374] 81282: <-- reply(3)\nE[10:21:29.374] 81282: workspace/configuration: parse error expected object\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.662] 81282: <-- reply(1)\n"
[ERROR][2024-08-03 10:21:29] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:29.662] 81282: --> notify $/progress\n"
[ERROR][2024-08-03 10:21:30] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:30.065] 81282: <-- reply(1)\n"
[ERROR][2024-08-03 10:21:30] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:30.065] 81282: --> notify $/progress\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:34.603] 81282: <-- textDocument/didChange\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:34.603] 81282: --> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:34.652"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"] 81282: <-- textDocument/semanticTokens/full(3)\nI[10:21:34.653] 81282: --> reply:textDocument/semanticTokens/full(3)\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:34.669] 81282: <-- textDocument/didChange\nI[10:21:34.669] 81282: --> notify textDocument/publishDiagnostics\nI[10:21:34.669] 81282: <-- textDocument/completion(4)\nI[10:21:34.669] 81282: --> call attrset/optionComplete(2)\nI[10:21:34.670] 81282: <-- reply(2)\nI[10:21:34.670] 81282: --> reply:textDocument/completion(4)\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:34.819] 81282: <-- textDocument/didChange\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:34.820] 81282: "
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"--> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:34.972] 81282: <-- textDocument/semanticTokens/full(5)\nI[10:21:34.972] 81282: --> reply:textDocument/semanticTokens/full(5)\n"
[ERROR][2024-08-03 10:21:34] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:34.985] 81282: <-- textDocument/didChange\nI[10:21:34.985] 81282: --> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:35.135] 81282: <-- textDocument/didChange\n"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:35.135] 81282: "
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"--> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:35.271] 81282: <-- textDocument/semanticTokens/full(6)\nI[10:21:35.271] 81282: --> reply:textDocument/semanticTokens/full"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"(6)\n"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:35.285] 81282: <-- textDocument/didChange\nI[10:21:35.285] 81282: --> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:35] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:35.473] 81282: <-- textDocument/semanticTokens/full(7)\nI[10:21:35.473] 81282: --> reply:textDocument/semanticTokens/full(7)\n"
[ERROR][2024-08-03 10:21:36] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:36.549] 81282: <-- textDocument/completion(8)\nI[10:21:36.550] 81282: --> call attrset/optionComplete(3)\nI["
[ERROR][2024-08-03 10:21:36] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:36.550] 81282: <-- reply(3)\nI[10:21:36.551] 81282: --> reply:textDocument/completion(8)\n"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:38.688] 81282: <-- textDocument/didChange\n"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:38.689] 81282: --> notify textDocument/publishDiagnostics\n"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:38.838] 81282: <-- textDocument/didChange\n"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:38.838] 81282: --> notify textDocument/publishDiagnostics"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"\n"
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-08-03 10:21:38] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"10:21:38.889] 81282: <-- textDocument/semanticTokens/full(9)\nI[10:21:38.889] 81282: --> reply:textDocument/semanticTokens/full(9)\n"
[ERROR][2024-08-03 10:21:39] .../vim/lsp/rpc.lua:772	"rpc"	"/nix/store/9y0zng78x996v0i0fh1yys87z9ysils1-nixd-2.3.0/bin/nixd"	"stderr"	"I[10:21:39.558] 81282: <-- shutdown(10)\nI[10:21:39.558] 81282: --> reply:shutdown(10)\n"

Configuration

None (nvim-lspconfig's default)

To Reproduce

  1. Open a Nix shell that includes the nixd package from Nixpkgs:

    $ nix shell 'nixpkgs#nixd'
    
  2. Add the following line to Neovim's init.lua, assuming that the neovim/nvim-lspconfig plugin is installed:

    require "lspconfig".nixd.setup {}
    
  3. Open the following flake.nix at https://github.com/antoineco/dotfiles/blob/ae64add/nix/flakes/shells/go in Neovim.

  4. Attempt to complete something from the nixpkgs input variable, or to hover an attribute from it.

Expected behavior

  • The language server offers completion options for the flake's inputs and outputs attributes.
  • The language server offers information about attributes upon performing a LSP hover.

Screenshots

Example: no completion of nixpkgs.outputs.lib or nixpkgs.outputs.legacyPackages: Screenshot 2024-08-03 at 10 15 17

Additional context

-

antoineco avatar Aug 03 '24 08:08 antoineco

As an additional information, I am observing the same behaviour using the output of github:nix-community/nixd#nvim (nvim-lsp command) in a development shell:

Screenshot 2024-08-03 at 10 28 53

antoineco avatar Aug 03 '24 08:08 antoineco

Seems to be an unimplemented feature.

inclyc avatar Aug 03 '24 09:08 inclyc

Ah right, I just stumbled upon https://github.com/nix-community/nixd/blob/2.3.0/nixd/docs/features.md. I did not understand that nixd was only providing inlay hints and semantic highlights. Sorry for the noise!

antoineco avatar Aug 03 '24 09:08 antoineco

Note that https://www.reddit.com/r/NixOS/s/Tsp4msODn3 is claiming that these features are in fact implemented, just to provide context about where I'm coming from.

antoineco avatar Aug 03 '24 09:08 antoineco

Note that https://www.reddit.com/r/NixOS/s/Tsp4msODn3 is claiming that these features are in fact implemented, just to provide context about where I'm coming from.

Currently only some idioms in Nix language are implemented. So it can be expected that nixd cannot deal with the general case (at least for now).

I'd like to reopen this issue because the reporting is valid and maybe we'd like to have this feature in the future.

inclyc avatar Aug 03 '24 12:08 inclyc

I noticed this in my VsCode as well; my project is flake based and it only seems to go to definition of where it's declared in my flake not any further.

fzakaria avatar Aug 03 '24 14:08 fzakaria

how non-trivial is this to implement? I think we could do it in parts. we kindof already have completion in flakes through flake-parts modules. so I (in my inexperienced opinion) think it might be possible to implement the modules. or maybe treat the flake.nix as a regular file for nixpkgs.<> completion. I would be willing to help with this, but I fear both that the memory usage will only get worse, and that it will take more time to teach me both hte codebase and the underlying cpp(I only have introductory cpp experience) if anyone is willing to help I would be more than willing to put in the time to learn it atm. wont be the case in a few months though

DrTeagle avatar Jun 04 '25 17:06 DrTeagle