nix-community / nixd

Nix language server, based on nix libraries [maintainer=@inclyc,@Aleksanaa]
https://github.com/nix-community/nixd
GNU Lesser General Public License v3.0
820 stars 25 forks source link

No completion available in flakes #567

Open antoineco opened 1 month ago

antoineco commented 1 month ago

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

Screenshots

Example: no completion of nixpkgs.outputs.lib or nixpkgs.outputs.legacyPackages:

Screenshot 2024-08-03 at 10 15 17

Additional context

-

antoineco commented 1 month ago

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
inclyc commented 1 month ago

Seems to be an unimplemented feature.

antoineco commented 1 month ago

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 commented 1 month ago

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.

inclyc commented 1 month ago

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.

fzakaria commented 1 month ago

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.