aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r--runtime/lua/vim/lsp/_snippet_grammar.lua34
-rw-r--r--runtime/lua/vim/lsp/protocol.lua1
-rw-r--r--runtime/lua/vim/lsp/util.lua30
3 files changed, 31 insertions, 34 deletions
diff --git a/runtime/lua/vim/lsp/_snippet_grammar.lua b/runtime/lua/vim/lsp/_snippet_grammar.lua
index 0a4d669fb9..9318fefcbc 100644
--- a/runtime/lua/vim/lsp/_snippet_grammar.lua
+++ b/runtime/lua/vim/lsp/_snippet_grammar.lua
@@ -81,14 +81,40 @@ local Type = {
M.NodeType = Type
--- @class vim.snippet.Node<T>: { type: vim.snippet.Type, data: T }
---- @class vim.snippet.TabstopData: { tabstop: number }
+--- @class vim.snippet.TabstopData: { tabstop: integer }
--- @class vim.snippet.TextData: { text: string }
---- @class vim.snippet.PlaceholderData: { tabstop: vim.snippet.TabstopData, value: vim.snippet.Node<any> }
---- @class vim.snippet.ChoiceData: { tabstop: vim.snippet.TabstopData, values: string[] }
+--- @class vim.snippet.PlaceholderData: { tabstop: integer, value: vim.snippet.Node<any> }
+--- @class vim.snippet.ChoiceData: { tabstop: integer, values: string[] }
--- @class vim.snippet.VariableData: { name: string, default?: vim.snippet.Node<any>, regex?: string, format?: vim.snippet.Node<vim.snippet.FormatData|vim.snippet.TextData>[], options?: string }
--- @class vim.snippet.FormatData: { capture: number, modifier?: string, if_text?: string, else_text?: string }
--- @class vim.snippet.SnippetData: { children: vim.snippet.Node<any>[] }
+--- @type vim.snippet.Node<any>
+local Node = {}
+
+--- @return string
+--- @diagnostic disable-next-line: inject-field
+function Node:__tostring()
+ local node_text = {}
+ local type, data = self.type, self.data
+ if type == Type.Snippet then
+ --- @cast data vim.snippet.SnippetData
+ for _, child in ipairs(data.children) do
+ table.insert(node_text, tostring(child))
+ end
+ elseif type == Type.Choice then
+ --- @cast data vim.snippet.ChoiceData
+ table.insert(node_text, data.values[1])
+ elseif type == Type.Placeholder then
+ --- @cast data vim.snippet.PlaceholderData
+ table.insert(node_text, tostring(data.value))
+ elseif type == Type.Text then
+ --- @cast data vim.snippet.TextData
+ table.insert(node_text, data.text)
+ end
+ return table.concat(node_text)
+end
+
--- Returns a function that constructs a snippet node of the given type.
---
--- @generic T
@@ -96,7 +122,7 @@ M.NodeType = Type
--- @return fun(data: T): vim.snippet.Node<T>
local function node(type)
return function(data)
- return { type = type, data = data }
+ return setmetatable({ type = type, data = data }, Node)
end
end
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 0755fa991f..3a1b16c450 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -742,7 +742,6 @@ function protocol.make_client_capabilities()
-- this should be disabled out of the box.
-- However, users can turn this back on if they have a snippet plugin.
snippetSupport = false,
-
commitCharactersSupport = false,
preselectSupport = false,
deprecatedSupport = false,
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index d525cae4c0..42c1508cbf 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -616,35 +616,7 @@ function M.parse_snippet(input)
return input
end
- --- @param node vim.snippet.Node<any>
- --- @return string
- local function node_to_string(node)
- local insert_text = {}
- if node.type == snippet.NodeType.Snippet then
- for _, child in
- ipairs((node.data --[[@as vim.snippet.SnippetData]]).children)
- do
- table.insert(insert_text, node_to_string(child))
- end
- elseif node.type == snippet.NodeType.Choice then
- table.insert(insert_text, (node.data --[[@as vim.snippet.ChoiceData]]).values[1])
- elseif node.type == snippet.NodeType.Placeholder then
- table.insert(
- insert_text,
- node_to_string((node.data --[[@as vim.snippet.PlaceholderData]]).value)
- )
- elseif node.type == snippet.NodeType.Text then
- table.insert(
- insert_text,
- node
- .data --[[@as vim.snippet.TextData]]
- .text
- )
- end
- return table.concat(insert_text)
- end
-
- return node_to_string(parsed)
+ return tostring(parsed)
end
--- Sorts by CompletionItem.sortText.