This repository was archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcommand.lua
More file actions
52 lines (43 loc) · 1.41 KB
/
command.lua
File metadata and controls
52 lines (43 loc) · 1.41 KB
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
local BaseAction = require('code_action_menu.lsp_objects.actions.base_action')
local TextDocumentEdit = require(
'code_action_menu.lsp_objects.edits.text_document_edit'
)
local WorkspaceEdit = require(
'code_action_menu.lsp_objects.edits.workspace_edit'
)
local config = require('code_action_menu.config')
local Command = BaseAction:new({})
function Command:new(server_data)
local instance = BaseAction:new(server_data)
setmetatable(instance, self)
self.__index = self
return instance
end
function Command:get_kind()
return 'command'
end
function Command:get_name()
return self.server_data.command or 'undefined'
end
-- Though commands do nowdays actually not include edits anymore, some LSP
-- servers still use them like that. This can be detected by inspecting the
-- commands arguments.
function Command:get_workspace_edit()
local workspace_edit = WorkspaceEdit:new()
for _, argument in ipairs(self.server_data.arguments or {}) do
for _, data in ipairs(argument.documentChanges or {}) do
local text_document_edit = TextDocumentEdit:new(data)
workspace_edit:add_text_document_edit(text_document_edit)
end
end
return workspace_edit
end
function Command:execute()
local source = config.source
if source == 'nvim_lsp' then
vim.lsp.buf.execute_command(self.server_data)
elseif source == 'coc' then
vim.fn.CocActionAsync('doCodeAction', self.server_data)
end
end
return Command