forked from georgewfraser/java-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable.lua
More file actions
106 lines (86 loc) · 2.32 KB
/
enable.lua
File metadata and controls
106 lines (86 loc) · 2.32 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local debug = require("lsp-debug-tools")
local function filter_by(expected)
return function(bufnr)
if #expected == 0 then
return true
end
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype");
local found = false
for i = 1, #expected do
if filetype == expected[i] then
found = true
break
end
end
return found
end
end
local id = nil
local filter = filter_by({})
local config = nil
local function attach_lsp(args)
if id == nil then
return
end
local bufnr = args.buffer or args.buf;
if not bufnr or not filter(bufnr) then
return;
end
if not vim.lsp.buf_is_attached(args.buffer, id) then
vim.lsp.buf_attach_client(args.buffer, id);
end
end
vim.api.nvim_create_autocmd("BufNew", {
callback = attach_lsp
});
vim.api.nvim_create_autocmd("BufEnter", {
callback = attach_lsp,
});
local function start(opts)
if id ~= nil then
return
end
config = vim.tbl_deep_extend("force", {}, {
expected = { "javascript", "javascriptreact", "typescript", "typescriptreact" },
name = "jsperf-lsp",
cmd = { "jsperf-lsp", "--level", "DEBUG" },
root_dir = vim.fs.dirname(
vim.fs.find({ "package.json" }, { upward = true })[1]
)
}, opts or {})
id = vim.lsp.start_client({
name = opts.name,
cmd = opts.cmd,
root_dir = opts.root_dir,
handlers = opts.handlers,
})
filter = filter_by(config.expected)
local bufnr = vim.api.nvim_get_current_buf()
print("lsp attaching...")
attach_lsp({ buffer = bufnr })
print("lsp attached")
end
local function stop()
if id == nil then
return
end
vim.lsp.stop_client(id)
id = nil
end
function restart_java_lsp()
stop();
start({
expected = {},
name = "java-lsp",
cmd = {
"/home/henrique/repositorios/java-language-server/dist/java_lsp",
},
root_dir = vim.loop.cwd(),
handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics,
{ virtual_text = false, signs = true, update_in_insert = false, underline = true}
),
}
});
end