Skip to content

Commit

Permalink
fix(lsp): only setup vim.lsp.commands for rust-analyzer on first init
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 27, 2024
1 parent 961bab3 commit a24df27
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 4.0.1 - 2024-01-27

### Fixed

- Only setup `vim.lsp.commands` for rust-analyzer on the first
initialization.

## 4.0.0 - 2024-01-25

### BREAKING CHANGES
Expand Down
55 changes: 30 additions & 25 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,42 @@ local config = require('rustaceanvim.config.internal')
local types = require('rustaceanvim.types.internal')
local lsp = require('rustaceanvim.lsp')

local auto_attach = types.evaluate(config.server.auto_attach)
if not auto_attach then
return
end
if not vim.g.did_rustaceanvim_setup_commands then
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
local runnables = require('rustaceanvim.runnables')
local cached_commands = require('rustaceanvim.cached_commands')
cached_commands.set_last_runnable(1, command.arguments)
runnables.run_command(1, command.arguments)
end

vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
local runnables = require('rustaceanvim.runnables')
local cached_commands = require('rustaceanvim.cached_commands')
cached_commands.set_last_runnable(1, command.arguments)
runnables.run_command(1, command.arguments)
end
vim.lsp.commands['rust-analyzer.gotoLocation'] = function(command, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client then
vim.lsp.util.jump_to_location(command.arguments[1], client.offset_encoding)
end
end

vim.lsp.commands['rust-analyzer.gotoLocation'] = function(command, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client then
vim.lsp.util.jump_to_location(command.arguments[1], client.offset_encoding)
vim.lsp.commands['rust-analyzer.showReferences'] = function(_)
vim.lsp.buf.implementation()
end
end

vim.lsp.commands['rust-analyzer.showReferences'] = function(_)
vim.lsp.buf.implementation()
vim.lsp.commands['rust-analyzer.debugSingle'] = function(command)
local overrides = require('rustaceanvim.overrides')
local args = command.arguments[1].args
overrides.sanitize_command_for_debugging(args.cargoArgs)
local cached_commands = require('rustaceanvim.cached_commands')
cached_commands.set_last_debuggable(args)
local rt_dap = require('rustaceanvim.dap')
rt_dap.start(args)
end
end

vim.lsp.commands['rust-analyzer.debugSingle'] = function(command)
local overrides = require('rustaceanvim.overrides')
local args = command.arguments[1].args
overrides.sanitize_command_for_debugging(args.cargoArgs)
local cached_commands = require('rustaceanvim.cached_commands')
cached_commands.set_last_debuggable(args)
local rt_dap = require('rustaceanvim.dap')
rt_dap.start(args)
vim.g.did_rustaceanvim_setup_commands = true

local auto_attach = types.evaluate(config.server.auto_attach)

if not auto_attach then
return
end

lsp.start()

0 comments on commit a24df27

Please sign in to comment.