mirror of
https://github.com/neovim/neovim.git
synced 2025-12-07 23:22:39 +00:00
Fix position params for encoding.
This commit is contained in:
@@ -327,12 +327,10 @@ vim.lsp.protocol
|
||||
vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
|
||||
|
||||
Utility functions used internally are:
|
||||
`vim.lsp.make_client_capabilities()`
|
||||
`vim.lsp.protocol.make_client_capabilities()`
|
||||
Make a ClientCapabilities object. These are the builtin
|
||||
capabilities.
|
||||
`vim.lsp.make_text_document_position_params()`
|
||||
Make a TextDocumentPositionParams object.
|
||||
`vim.lsp.resolve_capabilities(server_capabilites)`
|
||||
`vim.lsp.protocol.resolve_capabilities(server_capabilites)`
|
||||
Creates a normalized object describing capabilities from the server
|
||||
capabilities.
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ local function focusable_preview(method, params, fn)
|
||||
end
|
||||
|
||||
function M.hover()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
focusable_preview('textDocument/hover', params, function(result)
|
||||
if not (result and result.contents) then return end
|
||||
|
||||
@@ -79,7 +79,7 @@ function M.hover()
|
||||
end
|
||||
|
||||
function M.peek_definition()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/peekDefinition', params, function(_, _, result, _)
|
||||
if not (result and result[1]) then return end
|
||||
local loc = result[1]
|
||||
@@ -153,22 +153,22 @@ local function location_callback(_, method, result)
|
||||
end
|
||||
|
||||
function M.declaration()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/declaration', params, location_callback)
|
||||
end
|
||||
|
||||
function M.definition()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/definition', params, location_callback)
|
||||
end
|
||||
|
||||
function M.type_definition()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/typeDefinition', params, location_callback)
|
||||
end
|
||||
|
||||
function M.implementation()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
request('textDocument/implementation', params, location_callback)
|
||||
end
|
||||
|
||||
@@ -232,7 +232,7 @@ local function signature_help_to_preview_contents(input)
|
||||
end
|
||||
|
||||
function M.signature_help()
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
focusable_preview('textDocument/signatureHelp', params, function(result)
|
||||
if not (result and result.signatures and result.signatures[1]) then return end
|
||||
|
||||
@@ -248,7 +248,7 @@ end
|
||||
|
||||
-- TODO(ashkan) ?
|
||||
function M.completion(context)
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
params.context = context
|
||||
return request('textDocument/completion', params, function(_, _, result)
|
||||
if vim.tbl_isempty(result or {}) then return end
|
||||
@@ -306,7 +306,7 @@ end
|
||||
function M.rename(new_name)
|
||||
-- TODO(ashkan) use prepareRename
|
||||
-- * result: [`Range`](#range) \| `{ range: Range, placeholder: string }` \| `null` describing the range of the string to rename and optionally a placeholder text of the string content to be renamed. If `null` is returned then it is deemed that a 'textDocument/rename' request is not valid at the given position.
|
||||
local params = protocol.make_text_document_position_params()
|
||||
local params = util.make_position_params()
|
||||
new_name = new_name or npcall(vfn.input, "New Name: ")
|
||||
if not (new_name and #new_name > 0) then return end
|
||||
params.newName = new_name
|
||||
|
||||
@@ -680,19 +680,6 @@ function protocol.make_client_capabilities()
|
||||
}
|
||||
end
|
||||
|
||||
function protocol.make_text_document_position_params()
|
||||
local position = vim.api.nvim_win_get_cursor(0)
|
||||
return {
|
||||
textDocument = {
|
||||
uri = vim.uri_from_bufnr()
|
||||
};
|
||||
position = {
|
||||
line = position[1] - 1;
|
||||
character = position[2];
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
--[=[
|
||||
export interface DocumentFilter {
|
||||
--A language id, like `typescript`.
|
||||
|
||||
@@ -638,6 +638,17 @@ function M.try_trim_markdown_code_blocks(lines)
|
||||
return 'markdown'
|
||||
end
|
||||
|
||||
function M.make_position_params()
|
||||
local row, col = unpack(api.nvim_win_get_cursor(0))
|
||||
row = row - 1
|
||||
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
|
||||
col = vim.str_utfindex(line, col)
|
||||
return {
|
||||
textDocument = { uri = vim.uri_from_bufnr(0) };
|
||||
position = { line = row; character = col; }
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
-- vim:sw=2 ts=2 et
|
||||
|
||||
Reference in New Issue
Block a user