Skip to content

Commit

Permalink
fix: use line start/end for visual line selection; neovim/neovim#22632
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Mar 11, 2023
1 parent 9159ee7 commit 38188b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lua/actions-preview/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ local M = {}

-- based on https://github.com/neovim/neovim/blob/v0.8.0/runtime/lua/vim/lsp/buf.lua#L153-L178
---@private
---@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(mode)
-- TODO: Use `vim.region()` instead https://github.com/neovim/neovim/pull/13896

-- [bufnum, lnum, col, off]; both row and column 1-indexed
Expand All @@ -17,6 +18,11 @@ local function range_from_selection()
local start_col = start[3]
local end_row = end_[2]
local end_col = end_[3]
if mode == "V" then
start_col = 1
local lines = vim.api.nvim_buf_get_lines(0, end_row-1, end_row, true)
end_col = #lines[1]
end

-- A user can start visual selection at the end and move backwards
-- Normalize the range to start < end
Expand Down Expand Up @@ -96,7 +102,7 @@ function M.code_actions(options)
local end_ = assert(options.range["end"], "range must have a `end` property")
params = vim.lsp.util.make_given_range_params(start, end_)
elseif mode == "v" or mode == "V" then
local range = range_from_selection()
local range = range_from_selection(mode)
params = vim.lsp.util.make_given_range_params(range.start, range["end"])
else
params = vim.lsp.util.make_range_params()
Expand Down

0 comments on commit 38188b5

Please sign in to comment.