aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/buf.lua
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-11-20 16:03:32 -0800
committerAshkan Kiani <ashkan.k.kiani@gmail.com>2019-11-20 16:03:32 -0800
commita4b7004f489030d9ee7e3bbfc156ab540744279b (patch)
tree216450a3988d02c844a8417f3c4b02e6cdfca970 /runtime/lua/vim/lsp/buf.lua
parent2d580756ca707945c01703d404e10f4bf412a72c (diff)
downloadrneovim-a4b7004f489030d9ee7e3bbfc156ab540744279b.tar.gz
rneovim-a4b7004f489030d9ee7e3bbfc156ab540744279b.tar.bz2
rneovim-a4b7004f489030d9ee7e3bbfc156ab540744279b.zip
Move everything to buf & default_callbacks
- Rename builtin_callbacks to default_callbacks and slightly change its semantics: - No longer contains the default implementations. Instead, any default_callbacks will be used in preference for our .buf methods. - Add this to the docs.
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r--runtime/lua/vim/lsp/buf.lua86
1 files changed, 84 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 5f54196dcc..e8a38aa6ef 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -33,7 +33,7 @@ end
local function request(method, params, callback)
-- TODO(ashkan) enable this.
- -- callback = vim.lsp.default_callback[method] or callback
+ -- callback = vim.lsp.default_callbacks[method] or callback
validate {
method = {method, 's'};
callback = {callback, 'f'};
@@ -172,9 +172,78 @@ function M.implementation()
request('textDocument/implementation', params, location_callback)
end
+--- Convert SignatureHelp response to preview contents.
+-- https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_signatureHelp
+local function signature_help_to_preview_contents(input)
+ if not input.signatures then
+ return
+ end
+ --The active signature. If omitted or the value lies outside the range of
+ --`signatures` the value defaults to zero or is ignored if `signatures.length
+ --=== 0`. Whenever possible implementors should make an active decision about
+ --the active signature and shouldn't rely on a default value.
+ local contents = {}
+ local active_signature = input.activeSignature or 0
+ -- If the activeSignature is not inside the valid range, then clip it.
+ if active_signature >= #input.signatures then
+ active_signature = 0
+ end
+ local signature = input.signatures[active_signature + 1]
+ if not signature then
+ return
+ end
+ vim.list_extend(contents, split_lines(signature.label))
+ if signature.documentation then
+ util.convert_input_to_markdown_lines(signature.documentation, contents)
+ end
+ if input.parameters then
+ local active_parameter = input.activeParameter or 0
+ -- If the activeParameter is not inside the valid range, then clip it.
+ if active_parameter >= #input.parameters then
+ active_parameter = 0
+ end
+ local parameter = signature.parameters and signature.parameters[active_parameter]
+ if parameter then
+ --[=[
+ --Represents a parameter of a callable-signature. A parameter can
+ --have a label and a doc-comment.
+ interface ParameterInformation {
+ --The label of this parameter information.
+ --
+ --Either a string or an inclusive start and exclusive end offsets within its containing
+ --signature label. (see SignatureInformation.label). The offsets are based on a UTF-16
+ --string representation as `Position` and `Range` does.
+ --
+ --*Note*: a label of type string should be a substring of its containing signature label.
+ --Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`.
+ label: string | [number, number];
+ --The human-readable doc-comment of this parameter. Will be shown
+ --in the UI but can be omitted.
+ documentation?: string | MarkupContent;
+ }
+ --]=]
+ -- TODO highlight parameter
+ if parameter.documentation then
+ util.convert_input_to_markdown_lines(parameter.documentation, contents)
+ end
+ end
+ end
+ return contents
+end
+
function M.signature_help()
local params = protocol.make_text_document_position_params()
- request('textDocument/signatureHelp', params, location_callback)
+ focusable_preview('textDocument/signatureHelp', params, function(result)
+ if not (result and result.signatures and result.signatures[1]) then return end
+
+ -- TODO show empty popup when signatures is empty?
+ local lines = signature_help_to_preview_contents(result)
+ lines = util.trim_empty_lines(lines)
+ if vim.tbl_isempty(lines) then
+ return { 'No signature available' }
+ end
+ return lines, util.try_trim_markdown_code_blocks(lines)
+ end)
end
-- TODO(ashkan) ?
@@ -195,4 +264,17 @@ end
function M.range_formatting()
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()
+ 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
+ request('textDocument/rename', params, function(_, _, result)
+ if not result then return end
+ util.workspace_apply_workspace_edit(result)
+ end)
+end
+
return M