Skip to content

Commit

Permalink
feat(lsp): smart completions for :RustAnalyzer subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 11, 2024
1 parent 8b3c225 commit 5ee9a98
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `:RustAnalyzer restart` command.
- Smarter completions for `:RustAnalyzer` commands.
- Only suggest `start` command if there is no
active client for the current buffer
- Only suggest `stop` and `restart` if there is an
active client for the current buffer

## [3.14.0] - 2024-01-10

Expand Down
1 change: 1 addition & 0 deletions lua/rustaceanvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
---
--- `:RustAnalyzer start` - Start the LSP client.
--- `:RustAnalyzer stop` - Stop the LSP client.
--- `:RustAnalyzer restart` - Restart the LSP client.
---
---The `:RustLsp` command is available after the LSP client has initialized.
---It accepts the following subcommands:
Expand Down
3 changes: 2 additions & 1 deletion lua/rustaceanvim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ vim.api.nvim_create_user_command('RustAnalyzer', rust_analyzer_cmd, {
nargs = '+',
desc = 'Starts or stops the rust-analyzer LSP client',
complete = function(arg_lead, cmdline, _)
local clients = rust_analyzer.get_active_rustaceanvim_clients()
---@type RustAnalyzerCmd[]
local commands = vim.tbl_keys(RustAnalyzerCmd)
local commands = #clients == 0 and { 'start' } or { 'stop', 'restart' }
if cmdline:match('^RustAnalyzer%s+%w*$') then
return vim.tbl_filter(function(command)
return command:find(arg_lead) ~= nil
Expand Down

0 comments on commit 5ee9a98

Please sign in to comment.