Skip to content

Commit

Permalink
feat(flyCheck): Support run, clear and cancel subcommands (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Dec 1, 2023
1 parent 86d1683 commit 3e66b18
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
```
</details>

Expand Down
4 changes: 3 additions & 1 deletion doc/rustaceanvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

==============================================================================
Expand Down
10 changes: 7 additions & 3 deletions lua/rustaceanvim/commands/fly_check.lua
Original file line number Diff line number Diff line change
@@ -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
20 changes: 14 additions & 6 deletions lua/rustaceanvim/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lua/rustaceanvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]]

Expand Down

0 comments on commit 3e66b18

Please sign in to comment.