-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathlsp.lua
More file actions
66 lines (54 loc) · 1.6 KB
/
lsp.lua
File metadata and controls
66 lines (54 loc) · 1.6 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
54
55
56
57
58
59
60
61
62
63
64
65
66
local M = {}
---Get JDTLS LSP client
---@return vim.lsp.Client
function M.get_jdtls()
local err = require('java-core.utils.errors')
local clients = vim.lsp.get_clients({ name = 'jdtls' })
if #clients == 0 then
vim.print(debug.traceback())
err.throw('No JDTLS client found')
end
return clients[1]
end
--- Returns the path to the jdtls cache directory
---@return string
function M.get_jdtls_cache_root_path()
local path = require('java-core.utils.path')
local cache_root = path.join(vim.fn.stdpath('cache'), 'jdtls')
return cache_root
end
--- Returns the path to the jdtls config file
---@return string
function M.get_jdtls_cache_conf_path()
local path = require('java-core.utils.path')
local cache_root = M.get_jdtls_cache_root_path()
local conf_path = path.join(cache_root, 'config')
return conf_path
end
--- Returns the path to the workspace cache directory
---@param cwd string
---@return string
function M.get_jdtls_cache_data_path(cwd)
cwd = cwd or vim.fn.getcwd()
local path = require('java-core.utils.path')
local cache_root = M.get_jdtls_cache_root_path()
local workspace_path = path.join(cache_root, 'workspace', 'proj_' .. vim.fn.sha256(cwd))
return workspace_path
end
---Restart given LSP server
---@param ls string
function M.restart_ls(ls)
if vim.lsp.config[ls] == nil then
vim.notify(("Invalid server name '%s'"):format(ls))
else
vim.lsp.enable(ls, false)
vim.iter(vim.lsp.get_clients({ name = ls })):each(function(client)
client:stop(true)
end)
end
local timer = assert(vim.uv.new_timer())
timer:start(500, 0, function()
vim.schedule_wrap(vim.lsp.enable)(ls)
end)
end
return M