diff options
| author | Dubakula Sai Venkata Chaitanya <chaitanyarp4@gmail.com> | 2025-10-29 18:39:50 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-29 06:09:50 -0700 |
| commit | 1c3da72569cca0d372c2a344a83f6272a493f2cb (patch) | |
| tree | 88dba35ec9114d9f895a68838ec9b070facebe91 /lsp/rust_analyzer.lua | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar.gz nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar.bz2 nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar.lz nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar.xz nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.tar.zst nvim-lspconfig-1c3da72569cca0d372c2a344a83f6272a493f2cb.zip | |
feat(rust-analyzer): out-of-the-box support for codelens #4165
Codelens requires a bit of special configuration to work on rust-analyzer as described here:
neovim/neovim#34353 (comment)
Diffstat (limited to 'lsp/rust_analyzer.lua')
| -rw-r--r-- | lsp/rust_analyzer.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lsp/rust_analyzer.lua b/lsp/rust_analyzer.lua index a699c7f4..efac25a6 100644 --- a/lsp/rust_analyzer.lua +++ b/lsp/rust_analyzer.lua @@ -105,6 +105,13 @@ return { capabilities = { experimental = { serverStatusNotification = true, + commands = { + commands = { + 'rust-analyzer.showReferences', + 'rust-analyzer.runSingle', + 'rust-analyzer.debugSingle', + }, + }, }, }, before_init = function(init_params, config) @@ -112,6 +119,24 @@ return { if config.settings and config.settings['rust-analyzer'] then init_params.initializationOptions = config.settings['rust-analyzer'] end + ---@param command table{ title: string, command: string, arguments: any[] } + vim.lsp.commands['rust-analyzer.runSingle'] = function(command) + local r = command.arguments[1] + local cmd = { 'cargo', unpack(r.args.cargoArgs) } + if r.args.executableArgs and #r.args.executableArgs > 0 then + vim.list_extend(cmd, { '--', unpack(r.args.executableArgs) }) + end + + local proc = vim.system(cmd, { cwd = r.args.cwd }) + + local result = proc:wait() + + if result.code == 0 then + vim.notify(result.stdout, vim.log.levels.INFO) + else + vim.notify(result.stderr, vim.log.levels.ERROR) + end + end end, on_attach = function(_, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'LspCargoReload', function() |
