aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/buf.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2023-03-12 09:45:28 +0100
committerGitHub <noreply@github.com>2023-03-12 09:45:28 +0100
commitd15abd1be4ae85b10174e3ee139d3b7605e87577 (patch)
treeed40845811b796d2b80a42a8a8be9cf5716c6d6b /runtime/lua/vim/lsp/buf.lua
parent314f20a44fdfdc382b0ce9d124290d3e7d702d42 (diff)
downloadrneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.tar.gz
rneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.tar.bz2
rneovim-d15abd1be4ae85b10174e3ee139d3b7605e87577.zip
fix(lsp): use line start/end for visual line selection (#22632)
Fixes https://github.com/neovim/neovim/issues/22629
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r--runtime/lua/vim/lsp/buf.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 6ac885c78f..0e16e8f820 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -118,8 +118,10 @@ function M.completion(context)
end
---@private
+---@param bufnr integer
+---@param mode "v"|"V"
---@return table {start={row, col}, end={row, col}} using (1, 0) indexing
-local function range_from_selection()
+local function range_from_selection(bufnr, mode)
-- TODO: Use `vim.region()` instead https://github.com/neovim/neovim/pull/13896
-- [bufnum, lnum, col, off]; both row and column 1-indexed
@@ -138,6 +140,11 @@ local function range_from_selection()
start_row, end_row = end_row, start_row
start_col, end_col = end_col, start_col
end
+ if mode == 'V' then
+ start_col = 1
+ local lines = api.nvim_buf_get_lines(bufnr, end_row - 1, end_row, true)
+ end_col = #lines[1]
+ end
return {
['start'] = { start_row, start_col - 1 },
['end'] = { end_row, end_col - 1 },
@@ -200,7 +207,7 @@ function M.format(options)
local mode = api.nvim_get_mode().mode
local range = options.range
if not range and mode == 'v' or mode == 'V' then
- range = range_from_selection()
+ range = range_from_selection(bufnr, mode)
end
local method = range and 'textDocument/rangeFormatting' or 'textDocument/formatting'
@@ -772,7 +779,7 @@ function M.code_action(options)
local end_ = assert(options.range['end'], 'range must have a `end` property')
params = util.make_given_range_params(start, end_)
elseif mode == 'v' or mode == 'V' then
- local range = range_from_selection()
+ local range = range_from_selection(0, mode)
params = util.make_given_range_params(range.start, range['end'])
else
params = util.make_range_params()