diff options
Diffstat (limited to 'pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix')
-rw-r--r-- | pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix b/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix index 963e134075ed7..49be63a2b99c2 100644 --- a/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix +++ b/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix @@ -9,20 +9,33 @@ runCommand "test-neovim-rust-analyzer" { } ''; + # NB. Wait for server done type calculations before sending `hover` request, + # otherwise it would return `{unknown}`. + # Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status nvimConfig = /* lua */ '' + local caps = vim.lsp.protocol.make_client_capabilities() + caps["experimental"] = { serverStatusNotification = true } vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({ cmd = { "rust-analyzer" }, + capabilities = caps, handlers = { - ["$/progress"] = function(_, msg, ctx) - if msg.token == "rustAnalyzer/Indexing" and msg.value.kind == "end" then - vim.cmd("goto 23") -- let mut |var =... - vim.lsp.buf.hover() + ["experimental/serverStatus"] = function(_, msg, ctx) + if msg.health == "ok" then + if msg.quiescent then + vim.cmd("goto 23") -- let mut |var =... + vim.lsp.buf.hover() + end + else + print("error: server status is not ok: ") + vim.cmd("q") end end, ["textDocument/hover"] = function(_, msg, ctx) - -- Keep newlines. - io.write(msg.contents.value) - vim.cmd("q") + if msg then + -- Keep newlines. + io.write(msg.contents.value) + vim.cmd("q") + end end, }, on_error = function(code) |