Skip to content

Commit e9db3d5

Browse files
authored
feat(lsp): join multiple visually selected lines (RustLsp joinLines) (#339)
1 parent d107d75 commit e9db3d5

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- LSP: Join multiple visually selected lines with `:RustLsp joinLines`.
14+
1115
### Fixed
1216

13-
- Escape character inserted before `}` when applying code action
17+
- LSP: Escape character inserted before `}` when applying code action
1418
with `SnippetTextEdit` [[#303](https://github.com/mrcjkb/rustaceanvim/issues/303)].
1519

1620
## [4.18.2] - 2024-03-28

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,8 @@ by setting the rust-analyzer
513513
<b>Join lines</b>
514514
</summary>
515515

516-
Join selected lines into one,
517-
smartly fixing up whitespace,
518-
trailing commas, and braces.
516+
Join selected lines into one, smartly fixing up whitespace, trailing commas, and braces.
517+
Works with individual lines in normal mode and multiple lines in visual mode.
519518

520519
```vimscript
521520
:RustLsp joinLines

lua/rustaceanvim/commands/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ local rustlsp_command_tbl = {
109109
bang = true,
110110
},
111111
joinLines = {
112-
impl = function(_)
113-
require('rustaceanvim.commands.join_lines')()
112+
impl = function(_, opts)
113+
local visual_mode = opts.range ~= 0
114+
require('rustaceanvim.commands.join_lines')(visual_mode)
114115
end,
115116
},
116117
moveItem = {

lua/rustaceanvim/commands/join_lines.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ local M = {}
22

33
---@alias lsp_join_lines_params { textDocument: lsp_text_document, ranges: lsp_range[] }
44

5+
---@param visual_mode boolean
56
---@return lsp_join_lines_params
6-
local function get_params()
7-
local params = vim.lsp.util.make_range_params()
7+
local function get_params(visual_mode)
8+
local params = visual_mode and vim.lsp.util.make_given_range_params() or vim.lsp.util.make_range_params()
89
local range = params.range
910

1011
params.range = nil
@@ -21,8 +22,9 @@ local rl = require('rustaceanvim.rust_analyzer')
2122

2223
--- Sends the request to rust-analyzer to get the TextEdits to join the lines
2324
--- under the cursor and applies them
24-
function M.join_lines()
25-
rl.buf_request(0, 'experimental/joinLines', get_params(), handler)
25+
---@param visual_mode boolean
26+
function M.join_lines(visual_mode)
27+
rl.buf_request(0, 'experimental/joinLines', get_params(visual_mode), handler)
2628
end
2729

2830
return M.join_lines

0 commit comments

Comments
 (0)