diff --git a/CHANGELOG.md b/CHANGELOG.md index 078cd181..a01dfe4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `:RustLsp logFile` command, which opens the rust-analyzer log file. +- `:RustLsp flyCheck`: Support `run`, `clear` and `cancel` subcommands. - Executors: Support commands without `cwd`. ### Fixed diff --git a/README.md b/README.md index 8f3c22fa..b1609d62 100644 --- a/README.md +++ b/README.md @@ -365,10 +365,13 @@ for more configuration options. can be costly. ```vimscript - :RustLsp flyCheck + :RustLsp flyCheck [run?|clear?|cancel?] ``` ```lua - vim.cmd.RustLsp('flyCheck') + vim.cmd.RustLsp('flyCheck') -- defaults to 'run' + vim.cmd.RustLsp { 'flyCheck', 'run' } + vim.cmd.RustLsp { 'flyCheck', 'clear' } + vim.cmd.RustLsp { 'flyCheck', 'cancel' } ``` diff --git a/doc/rustaceanvim.txt b/doc/rustaceanvim.txt index eac137e6..e70af04d 100644 --- a/doc/rustaceanvim.txt +++ b/doc/rustaceanvim.txt @@ -35,11 +35,13 @@ It accepts the following subcommands: `ssr [query]` - Structural search and replace. `crateGraph [backend]` - Create and view a crate graph with graphviz. `syntaxTree` - View the syntax tree. - `flyCheck` - Run `cargo check` or another compatible command (f.x. `clippy`) + `flyCheck` [run?|clear?|cancel?] + - Run `cargo check` or another compatible command (f.x. `clippy`) in a background thread and provide LSP diagnostics based on the output of the command. Useful in large projects where running `cargo check` on each save can be costly. + Defaults to `flyCheck run` if called without an argument. `logFile` - Open the rust-analyzer log file. ============================================================================== diff --git a/lua/rustaceanvim/commands/fly_check.lua b/lua/rustaceanvim/commands/fly_check.lua index 8579d04e..82e77c07 100644 --- a/lua/rustaceanvim/commands/fly_check.lua +++ b/lua/rustaceanvim/commands/fly_check.lua @@ -1,9 +1,13 @@ local M = {} local rl = require('rustaceanvim.rust_analyzer') -function M.fly_check() - local params = vim.lsp.util.make_text_document_params() - rl.notify('rust-analyzer/runFlyCheck', params) + +---@alias flyCheckCommand 'run' | 'clear' | 'cancel' + +---@param cmd flyCheckCommand +function M.fly_check(cmd) + local params = cmd == 'run' and vim.lsp.util.make_text_document_params() or {} + rl.notify('rust-analyzer/' .. cmd .. 'FlyCheck', params) end return M.fly_check diff --git a/lua/rustaceanvim/commands/init.lua b/lua/rustaceanvim/commands/init.lua index 0550f155..08734c86 100644 --- a/lua/rustaceanvim/commands/init.lua +++ b/lua/rustaceanvim/commands/init.lua @@ -98,8 +98,9 @@ local command_tbl = { syntaxTree = function() require('rustaceanvim.commands.syntax_tree')() end, - flyCheck = function() - require('rustaceanvim.commands.fly_check')() + flyCheck = function(args) + local cmd = args[1] or 'run' + require('rustaceanvim.commands.fly_check')(cmd) end, logFile = function() vim.cmd.e(config.server.logfile) @@ -129,19 +130,26 @@ function M.create_rust_lsp_command() complete = function(arg_lead, cmdline, _) local commands = vim.tbl_keys(command_tbl) local match_start = '^' .. rust_lsp_cmd_name + local subcmd_match = '%s+%w*$' -- special case: crateGraph comes with graphviz backend completions - if cmdline:match(match_start .. ' debuggables%s+%w*$') or cmdline:match(match_start .. ' runnables%s+%w*$') then + if + cmdline:match(match_start .. ' debuggables' .. subcmd_match) + or cmdline:match(match_start .. ' runnables%s+%w*$') + then return { 'last' } end - if cmdline:match(match_start .. ' hover%s+%w*$') then + if cmdline:match(match_start .. ' hover' .. subcmd_match) then return { 'actions', 'range' } end - if cmdline:match(match_start .. ' moveItem%s+%w*$') then + if cmdline:match(match_start .. ' moveItem' .. subcmd_match) then return { 'up', 'down' } end - if cmdline:match(match_start .. ' crateGraph%s+%w*$') then + if cmdline:match(match_start .. ' crateGraph' .. subcmd_match) then return config.tools.crate_graph.enabled_graphviz_backends or {} end + if cmdline:match(match_start .. ' flyCheck' .. subcmd_match) then + return { 'run', 'clear', 'cancel' } + end if cmdline:match(match_start .. '%s+%w*$') then return vim.tbl_filter(function(command) return command:find(arg_lead) ~= nil diff --git a/lua/rustaceanvim/init.lua b/lua/rustaceanvim/init.lua index b33b844a..f1ab1d79 100644 --- a/lua/rustaceanvim/init.lua +++ b/lua/rustaceanvim/init.lua @@ -29,11 +29,13 @@ --- `ssr [query]` - Structural search and replace. --- `crateGraph [backend]` - Create and view a crate graph with graphviz. --- `syntaxTree` - View the syntax tree. ---- `flyCheck` - Run `cargo check` or another compatible command (f.x. `clippy`) +--- `flyCheck` [run?|clear?|cancel?] +--- - Run `cargo check` or another compatible command (f.x. `clippy`) --- in a background thread and provide LSP diagnostics based on --- the output of the command. --- Useful in large projects where running `cargo check` on each save --- can be costly. +--- Defaults to `flyCheck run` if called without an argument. --- `logFile` - Open the rust-analyzer log file. ---@brief ]]