-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlsp-command.lua
More file actions
53 lines (49 loc) · 1.36 KB
/
lsp-command.lua
File metadata and controls
53 lines (49 loc) · 1.36 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
53
local config = require("java-deps.config")
local M = {}
M.JAVA_PROJECT_LIST = "java.project.list"
M.GET_ALL_PROJECTS = "java.project.getAll"
M.JAVA_PROJECT_REFRESH_LIB_SERVER = "java.project.refreshLib"
M.JAVA_GETPACKAGEDATA = "java.getPackageData"
M.JAVA_RESOLVEPATH = "java.resolvePath"
M.JAVA_PROJECT_GETMAINCLASSES = "java.project.getMainClasses"
---@return vim.lsp.Client?
M.get_client = function()
local clients = vim.lsp.get_clients({ name = config.jdtls_name or "jdtls" })
if not clients or #clients == 0 then
vim.notify("No jdtls client found", vim.log.levels.WARN)
return
end
return clients[1]
end
-- 使用异步没有错误信输出
M.execute_command_async = function(command, callback, bufnr)
local client = M.get_client()
if not client then
return
end
local co
if not callback then
co = coroutine.running()
if co then
callback = function(err, resp)
coroutine.resume(co, err, resp)
end
end
end
client.request("workspace/executeCommand", command, callback, bufnr)
if co then
return coroutine.yield()
end
end
M.execute_command = function(command, bufnr)
local client = M.get_client()
if not client then
return
end
local resp = client.request_sync("workspace/executeCommand", command, 20000, bufnr)
if not resp then
return "No response"
end
return nil, resp.result
end
return M