diff options
author | notomo <notomo.motono@gmail.com> | 2020-09-25 04:53:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 21:53:08 +0200 |
commit | 4a996bc431163b2a7b8e4bf3351d862887a78f83 (patch) | |
tree | ee5f9e05fecfdca9a65379a5cadcd455460bbecf /runtime/lua/vim/lsp/util.lua | |
parent | f1fbb9e9ca26a7111dc384951c600bf4dc4ebbfb (diff) | |
download | rneovim-4a996bc431163b2a7b8e4bf3351d862887a78f83.tar.gz rneovim-4a996bc431163b2a7b8e4bf3351d862887a78f83.tar.bz2 rneovim-4a996bc431163b2a7b8e4bf3351d862887a78f83.zip |
lsp: Add vim.lsp.buf.range_code_action() (#12962)
Allows to execute code_action for a given range.
:'<,'>lua vim.lsp.buf.range_code_action()
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 28bc8cb736..d94a8bb774 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1465,11 +1465,46 @@ end function M.make_range_params() local position = make_position_param() return { - textDocument = { uri = vim.uri_from_bufnr(0) }, + textDocument = M.make_text_document_params(), range = { start = position; ["end"] = position; } } end +--- Using the given range in the current buffer, creates an object that +--- is similar to |vim.lsp.util.make_range_params()|. +--- +--@param start_pos ({number, number}, optional) mark-indexed position. +---Defaults to the start of the last visual selection. +--@param end_pos ({number, number}, optional) mark-indexed position. +---Defaults to the end of the last visual selection. +--@returns { textDocument = { uri = `current_file_uri` }, range = { start = +---`start_position`, end = `end_position` } } +function M.make_given_range_params(start_pos, end_pos) + validate { + start_pos = {start_pos, 't', true}; + end_pos = {end_pos, 't', true}; + } + local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) + local B = list_extend({}, end_pos or api.nvim_buf_get_mark(0, '>')) + -- convert to 0-index + A[1] = A[1] - 1 + B[1] = B[1] - 1 + -- account for encoding. + if A[2] > 0 then + A = {A[1], M.character_offset(0, A[1], A[2])} + end + if B[2] > 0 then + B = {B[1], M.character_offset(0, B[1], B[2])} + end + return { + textDocument = M.make_text_document_params(), + range = { + start = {line = A[1], character = A[2]}, + ['end'] = {line = B[1], character = B[2]} + } + } +end + --- Creates a `TextDocumentIdentifier` object for the current buffer. --- --@returns `TextDocumentIdentifier` |