aboutsummaryrefslogtreecommitdiffstats
path: root/lsp/rust_analyzer.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lsp/rust_analyzer.lua')
-rw-r--r--lsp/rust_analyzer.lua25
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()