mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
Fix encoding translation in other places.
This commit is contained in:
@@ -862,7 +862,7 @@ function lsp.omnifunc(findstart, base)
|
||||
position = {
|
||||
-- 0-indexed for both line and character
|
||||
line = pos[1] - 1,
|
||||
character = pos[2],
|
||||
character = vim.str_utfindex(line, pos[2]),
|
||||
};
|
||||
-- The completion context. This is only available if the client specifies
|
||||
-- to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
|
||||
|
||||
@@ -2,8 +2,8 @@ local validate = vim.validate
|
||||
local api = vim.api
|
||||
local vfn = vim.fn
|
||||
local util = require 'vim.lsp.util'
|
||||
local protocol = require 'vim.lsp.protocol'
|
||||
local log = require 'vim.lsp.log'
|
||||
local list_extend = vim.list_extend
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -192,7 +192,7 @@ local function signature_help_to_preview_contents(input)
|
||||
if not signature then
|
||||
return
|
||||
end
|
||||
vim.list_extend(contents, vim.split(signature.label, '\n', true))
|
||||
list_extend(contents, vim.split(signature.label, '\n', true))
|
||||
if signature.documentation then
|
||||
util.convert_input_to_markdown_lines(signature.documentation, contents)
|
||||
end
|
||||
@@ -287,13 +287,23 @@ function M.range_formatting(options, start_pos, end_pos)
|
||||
tabSize = api.nvim_buf_get_option(0, 'tabstop');
|
||||
insertSpaces = api.nvim_buf_get_option(0, 'expandtab');
|
||||
})
|
||||
start_pos = start_pos or vim.api.nvim_buf_get_mark(0, '<')
|
||||
end_pos = end_pos or vim.api.nvim_buf_get_mark(0, '>')
|
||||
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], util.character_offset(0, unpack(A))}
|
||||
end
|
||||
if B[2] > 0 then
|
||||
B = {B[1], util.character_offset(0, unpack(B))}
|
||||
end
|
||||
local params = {
|
||||
textDocument = { uri = vim.uri_from_bufnr(0) };
|
||||
range = {
|
||||
start = { line = start_pos[1]; character = start_pos[2]; };
|
||||
["end"] = { line = end_pos[1]; character = end_pos[2]; };
|
||||
start = { line = A[1]; character = A[2]; };
|
||||
["end"] = { line = B[1]; character = B[2]; };
|
||||
};
|
||||
options = options;
|
||||
}
|
||||
|
||||
@@ -649,6 +649,13 @@ function M.make_position_params()
|
||||
}
|
||||
end
|
||||
|
||||
-- @param buf buffer handle or 0 for current.
|
||||
-- @param row 0-indexed line
|
||||
-- @param col 0-indexed byte offset in line
|
||||
function M.character_offset(buf, row, col)
|
||||
local line = api.nvim_buf_get_lines(buf, row, row+1, true)[1]
|
||||
return vim.str_utfindex(line, col)
|
||||
end
|
||||
|
||||
return M
|
||||
-- vim:sw=2 ts=2 et
|
||||
|
||||
Reference in New Issue
Block a user