Skip to content

Commit

Permalink
feat!(commands): use a single command with subcommands (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Oct 21, 2023
2 parents 02eff31 + ece16dc commit a622c62
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 214 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ 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).

## [2.0.0] - 2023-11-21

### Breaking changes

- Don't pollute the command space:
Use a single command with subcommands and completions.
- `RustAnalyzer [start|stop]`
(always available in Rust projects)
- `RustLsp [subcommand]`
(available when the LSP client is running)
e.g. `RustLsp moveItem [up|down]`

## [1.0.1] - 2023-11-21

### Fixed
Expand Down
37 changes: 16 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ local bufnr = vim.api.nvim_get_current_buf()
vim.keymap.set(
"n",
"<leader>a",
vim.cmd.RustCodeAction,
function()
vim.cmd.RustLsp('codeAction'),
end,
{ silent = true, buffer = bufnr }
)
```
Expand All @@ -144,9 +146,8 @@ for more configuration options.
<b>Runnables</b>
</summary>

![runnables](https://github.com/simrat39/rust-tools-demos/raw/master/runnables.gif)
```vimscript
:RustRunnables
:RustLsp runnables [last?]
```
</details>

Expand All @@ -155,9 +156,8 @@ for more configuration options.
<b>Expand Macros Recursively</b>
</summary>

![expand macros](https://github.com/simrat39/rust-tools-demos/raw/master/expand_macros_recursively.gif)
```vimscript
:RustExpandMacro
:RustLsp expandMacro
```
</details>

Expand All @@ -166,10 +166,9 @@ for more configuration options.
<b>Move Item Up/Down</b>
</summary>

![move items](https://github.com/simrat39/rust-tools-demos/raw/master/move_item.gif)
```vimscript
:RustMoveItemUp
:RustMoveItemDown
:RustLsp moveItem up
:RustLsp moveItem down
```
</details>

Expand All @@ -178,10 +177,9 @@ for more configuration options.
<b>Hover Actions</b>
</summary>

![hover actions](https://github.com/simrat39/rust-tools-demos/raw/master/hover_actions.gif)
Note: To activate hover actions, run the command twice. This will move you into the window, then press enter on the selection you want. Alternatively, you can set ```auto_focus``` to true in your config and you will automatically enter the hover actions window.
```vimscript
:RustHoverActions
:RustLsp hover actions
```
</details>

Expand All @@ -191,7 +189,7 @@ for more configuration options.
</summary>

```vimscript
:RustHoverRange
:RustLsp hover range
```
</details>

Expand All @@ -200,9 +198,8 @@ for more configuration options.
<b>Open Cargo.toml</b>
</summary>

![open cargo](https://github.com/simrat39/rust-tools-demos/raw/master/open_cargo_toml.gif)
```vimscript
:RustOpenCargo
:RustLsp openCargo
```
</details>

Expand All @@ -211,9 +208,8 @@ for more configuration options.
<b>Parent Module</b>
</summary>

![parent module](https://github.com/simrat39/rust-tools-demos/raw/master/parent_module.gif)
```vimscript
:RustParentModule
:RustLsp parentModule
```
</details>

Expand All @@ -222,9 +218,8 @@ for more configuration options.
<b>Join Lines</b>
</summary>

![join lines](https://github.com/simrat39/rust-tools-demos/raw/master/join_lines.gif)
```vimscript
:RustJoinLines
:RustLsp joinLines
```
</details>

Expand All @@ -234,7 +229,7 @@ for more configuration options.
</summary>

```vimscript
:RustSSR [query]
:RustLsp ssr [query]
```
</details>

Expand All @@ -244,7 +239,7 @@ for more configuration options.
</summary>

```vimscript
:RustViewCrateGraph [backend [output]]
:RustLsp crateGraph [backend [output]]
```
</details>

Expand All @@ -254,7 +249,7 @@ for more configuration options.
</summary>

```vimscript
:RustSyntaxTree
:RustLsp sytaxTree
```
</details>

Expand All @@ -271,7 +266,7 @@ for more configuration options.
can be costly.

```vimscript
:RustFlyCheck
:RustLsp flyCheck
```
</details>

Expand Down
42 changes: 22 additions & 20 deletions doc/ferris.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ and integrates with other rust tools.

Commands:

`:RustAnalyzerStart` - Start the LSP client.
`:RustAnalyzerStop` - Stop the LSP client.

The following commands are available after the LSP client has initialized:

`:RustRunnables` - Run tests, etc.
`:RustExpandMacro` - Expand macros recursively.
`:RustMoveItemUp`, `:RustMoveItemDown` - Move items up or down
`:RustHoverRange` - Hover over visually selected range.
`:RustOpenCargo` - Open the Cargo.toml file for the current package.
`:RustParentModule` - Open the current module's parent module.
`:RustJoinLines` - Join adjacent lines.
`:RustSSR [query]` - Structural search and replace.
`:RustViewCrateGraph` - Create and view a crate graph with graphviz.
`:RustSyntaxTree` - View the syntax tree.
`:RustFlyCheck` - 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.
`:RustAnalyzer start` - Start the LSP client.
`:RustAnalyzer stop` - Stop the LSP client.

The `:RustLsp` command is available after the LSP client has initialized.
It accepts the following subcommands:

`runnables [last]?` - Run tests, etc.
`last` means run the last test that was run.
`expandMacro` - Expand macros recursively.
`moveItem [up|down]` - Move items up or down.
`hover [action|range]` - Hover actions, or hover over visually selected range.
`openCargo` - Open the Cargo.toml file for the current package.
`parentModule` - Open the current module's parent module.
`joinLines` - Join adjacent lines.
`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`)
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.

==============================================================================
plugin configuration *ferris.config*
Expand Down
12 changes: 3 additions & 9 deletions lua/ferris/config/internal.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
local vim = vim

---@type FerrisConfig
local FerrisConfig = {}

-- Needed for autocompletion to work
_G.rust_tools_get_graphviz_backends = function()
return FerrisConfig.tools.crate_graph.enabled_graphviz_backends
end

---@class FerrisConfig
local FerrisDefaultConfig = {
---@class FerrisToolsConfig
Expand Down Expand Up @@ -188,7 +180,9 @@ local opts = type(ferris) == 'function' and ferris() or ferris
if opts.tools and opts.tools.executor and type(opts.tools.executor) == 'string' then
opts.tools.executor = assert(require('ferris.executors')[opts.tools.executor], 'Unknown FerrisExecutor')
end
FerrisConfig = vim.tbl_deep_extend('force', {}, FerrisDefaultConfig, opts)

---@type FerrisConfig
local FerrisConfig = vim.tbl_deep_extend('force', {}, FerrisDefaultConfig, opts)

local check = require('ferris.config.check')
local ok, err = check.validate(FerrisConfig)
Expand Down
38 changes: 20 additions & 18 deletions lua/ferris/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@
---
---Commands:
---
--- `:RustAnalyzerStart` - Start the LSP client.
--- `:RustAnalyzerStop` - Stop the LSP client.
--- `:RustAnalyzer start` - Start the LSP client.
--- `:RustAnalyzer stop` - Stop the LSP client.
---
---The following commands are available after the LSP client has initialized:
---The `:RustLsp` command is available after the LSP client has initialized.
---It accepts the following subcommands:
---
--- `:RustRunnables` - Run tests, etc.
--- `:RustExpandMacro` - Expand macros recursively.
--- `:RustMoveItemUp`, `:RustMoveItemDown` - Move items up or down
--- `:RustHoverRange` - Hover over visually selected range.
--- `:RustOpenCargo` - Open the Cargo.toml file for the current package.
--- `:RustParentModule` - Open the current module's parent module.
--- `:RustJoinLines` - Join adjacent lines.
--- `:RustSSR [query]` - Structural search and replace.
--- `:RustViewCrateGraph` - Create and view a crate graph with graphviz.
--- `:RustSyntaxTree` - View the syntax tree.
--- `:RustFlyCheck` - 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.
--- `runnables [last]?` - Run tests, etc.
--- `last` means run the last test that was run.
--- `expandMacro` - Expand macros recursively.
--- `moveItem [up|down]` - Move items up or down.
--- `hover [action|range]` - Hover actions, or hover over visually selected range.
--- `openCargo` - Open the Cargo.toml file for the current package.
--- `parentModule` - Open the current module's parent module.
--- `joinLines` - Join adjacent lines.
--- `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`)
--- 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.
---@brief ]]

local M = {}
Expand Down
Loading

0 comments on commit a622c62

Please sign in to comment.