forked from vscode-neovim/vscode-neovim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buf.lua
77 lines (71 loc) · 2.39 KB
/
buf.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- Shim vim.lsp.buf calls to vscode equivalent commands.
local vscode = require("vscode")
local M = {}
local map = {
hover = "editor.action.showHover",
declaration = "editor.action.peekDeclaration",
definition = "editor.action.peekDefinition",
type_definition = "editor.action.peekTypeDefinition",
implementation = "editor.action.peekImplementation",
signature_help = "editor.action.triggerParameterHints",
completion = "editor.action.triggerSuggest",
format = "editor.action.formatDocument",
rename = "editor.action.rename",
references = "editor.action.referenceSearch.trigger",
document_symbol = "workbench.action.gotoSymbol",
incoming_calls = "editor.showIncomingCalls",
outgoing_calls = "editor.showOutgoingCalls",
---@param kind "subtypes"|"supertypes"
typehierarchy = function(kind)
local cmd
if kind == "subtypes" then
cmd = "editor.showSubtypes"
elseif kind == "supertypes" then
cmd = "editor.showSupertypes"
else
cmd = "editor.showTypeHierarchy"
end
vscode.action(cmd)
end,
list_workspace_folders = function()
return vscode.eval("return (vscode.workspace.workspaceFolders || []).map((folder) => folder.name);")
end,
add_workspace_folder = "workbench.action.addRootFolder",
remove_workspace_folder = "workbench.action.removeRootFolder",
workspace_symbol = function(query)
vscode.action("workbench.action.quickOpen", { args = { "#" .. (query or "") } })
end,
document_highlight = "editor.action.wordHighlight.trigger",
clear_references = vim.NIL,
code_action = "editor.action.sourceAction",
execute_command = vim.NIL,
}
for method, cmd in pairs(map) do
local cmd_type = type(cmd)
if cmd == vim.NIL then
M[method] = function()
vscode.notify(string.format("vim.lsp.buf.%s is not supported in vscode.", method), vim.log.levels.WARN)
end
elseif cmd_type == "string" then
M[method] = function()
vscode.action(cmd)
end
elseif cmd_type == "function" then
M[method] = cmd
end
end
vim.lsp.buf = setmetatable(M, {
__index = function(t, method)
t[method] = function()
vscode.notify(
string.format(
"vim.lsp.buf.%s is not handled by vscode-neovim. %s",
method,
"Please report this issue at [vscode-neovim](https://github.com/vscode-neovim/vscode-neovim/issues)"
),
vim.log.levels.WARN
)
end
return t[method]
end,
})