-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlspconfig.lua
315 lines (290 loc) · 8.56 KB
/
lspconfig.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
local nvim_lsp = require("lspconfig")
local lspconfig_util = require("lspconfig.util")
-- prevent setting home-directory as root (at least as long as root_pattern is
-- used for resolving root).
lspconfig_util.root_pattern = function(...)
local patterns = vim.tbl_flatten { ... }
local function matcher(path)
for _, pattern in ipairs(patterns) do
for _, p in ipairs(vim.fn.glob(lspconfig_util.path.join(lspconfig_util.path.escape_wildcards(path), pattern), true, true)) do
if lspconfig_util.path.exists(p) and p ~= "/home/simon/.git" then
return path
end
end
end
end
return function(startpath)
startpath = lspconfig_util.strip_archive_subpath(startpath)
return lspconfig_util.search_ancestors(startpath, matcher)
end
end
local util = require("util")
-- local function sem_token_attach(_)
-- vim.lsp.buf.semantic_tokens_full()
-- vim.cmd [[autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.buf.semantic_tokens_full()]]
-- end
local lsp_attach = function(client)
vim.api.nvim_buf_set_keymap(0, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', 'gd', '<cmd>lua vim.lsp.buf.declaration()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', 'gD', '<cmd>lua vim.lsp.buf.definition()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>d', '<cmd>lua vim.diagnostic.open_float()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>n', '<cmd>lua vim.lsp.buf.rename()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>v', '<cmd>lua Toggle_virtual_text()<CR>:e<CR>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>ci', '<cmd>lua vim.lsp.buf.incoming_calls()<cr>', {noremap = true})
vim.api.nvim_buf_set_keymap(0, 'n', '<space>co', '<cmd>lua vim.lsp.buf.outgoing_calls()<cr>', {noremap = true})
-- require("lsp_signature").on_attach({
-- always_trigger = false,
-- toggle_key = "<C-S>",
-- hint_enable = false,
-- hi_parameter = "UnderlineTransparent"
-- })
end
Diag_params = {signs = true, virtual_text = true}
function Toggle_virtual_text()
Diag_params.virtual_text = not Diag_params.virtual_text
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, Diag_params)
end
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, Diag_params)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
local session = require("session")
local function completion_intercept(client, method_cb_map)
local orig_rpc_request = client.rpc.request
client.rpc.request = function(method, params, handler, ...)
local orig_handler = handler
return orig_rpc_request(method, params, function(...)
local err, result = ...
if method_cb_map[method] and not err and result then
-- method can return false to prevent
if method_cb_map[method](result) then
return orig_handler(...)
end
else
return orig_handler(...)
end
end, ...)
end
end
nvim_lsp.clangd.setup({
cmd = {"clangd", [[--completion-style=detailed]], [[--enable-config]]},
on_attach = function(client)
completion_intercept(client,
{
["textDocument/completion"] = function(result)
local items = result.items or result
for _, item in ipairs(items) do
local item_text = item.textEdit.newText
if item_text:match("^[%w_]+%(.*%)$") then
local name = item_text:match("^[%w_]+")
local content = item_text:match("%((.*)%)$")
if content:match("$0") then
content = content:gsub("$0", "$1000")
elseif content:match("${0") then
content = content:gsub("${0", "${1000")
end
ls.setup_snip_env()
session.lsp_override_snips[item_text] = s("", {
t(name),
c(1, {
{t"(", r(1, "type", ls.parser.parse_snippet(1, content)), t")"},
{t"{", r(1, "type"), t"}"},
})
})
item.insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet
elseif item.insertTextFormat == vim.lsp.protocol.InsertTextFormat.Snippet then
item.textEdit.newText = item_text:gsub("${0", "${100")
end
end
-- accept all completions.
return true
end,
["textDocument/inlayHint"] = function(result)
util.filter_list(result, function(item)
-- glm::
if item.label == "x:" or
item.label == "y:" or
item.label == "z:" or
item.label == "a:" or
item.label == "b:" or
item.label == "v:" or
item.label == "m:" or
-- std::
item.label == "s:" or
item.label == "nptr:" or
item.label == "scalar:" or
item.lable == "argv0" then
return false
end
-- local line = item.position.line
-- local col = item.position.character
-- local node = vim.treesitter.get_node({pos = {line,col}})
-- I(vim.treesitter.get_node_text(node:parent(), 0))
return true
end)
-- accept request.
return true
end
})
lsp_attach(client)
end,
capabilities = capabilities
})
require("clangd_extensions").setup({
extensions = {
inlay_hints = {
parameter_hints_prefix = "⟵ ",
other_hints_prefix = "⟼ ",
highlight = "GruvboxBg1"
}
}
})
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
nvim_lsp.texlab.setup{
cmd = { "texlab" },
filetypes = { "tex", "bib" },
settings = {
texlab = {
build = {
executable = "latexmk",
args = { "-f", "--shell-escape", "-pdf", "-interaction=nonstopmode", "%f" },
onSave = true,
onChange = false
},
forwardSearch = {
args = {},
onSave = false
},
lint = {
onChange = false,
onSave = false
},
latexFormatter = "texlab"
},
},
on_attach = function(client)
lsp_attach(client)
-- sem_token_attach(client)
end,
capabilities = capabilities
}
nvim_lsp.pyright.setup{
capabilities = capabilities,
on_attach = lsp_attach,
settings = {
python = {
analysis = {
autoSearchPaths = false
}
}
}
}
nvim_lsp.julials.setup{
cmd = {"julia", "--startup-file=no", "-e", "using LanguageServer; runserver()", "-J", "/home/simon/.julia/sysimages/img.so"},
capabilities = capabilities,
on_attach = function(client)
lsp_attach(client)
end,
}
nvim_lsp.cmake.setup{
on_attach = lsp_attach
}
nvim_lsp.zls.setup{
on_attach = function(...)
lsp_attach(...)
end,
settings = {
enable_autofix = true
}
}
nvim_lsp.lua_ls.setup {
cmd = {"lua-language-server", "--logpath", "/home/simon/.cache/lua-language-server/", "--metapath", "/home/simon/.cache/lua-language-server/meta/"},
settings = {
Lua = {
completion = {
callSnippet = "Both"
},
capabilities = capabilities,
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
path = {
"lua/?.lua",
"lua/?/init.lua",
-- meta & template seem to refer to /usr/lib/lua-language-server/meta.
"meta/template/?.lua",
"meta/template/?/init.lua",
}
},
diagnostics = {
-- Get the language server to recognize the `vim` and luasnip globals.
globals = {
"vim",
"s",
"sn",
"t",
"i",
"f",
"c",
"end",
"d",
"isn",
"psn",
"l",
"rep",
"r",
"p",
"types",
"events",
"util",
"fmt",
"ls",
"ins_generate",
"parse",
"parse_add",
"s_add",
"dl",
},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
ignoreDir = {
".cache",
"Packages",
"deps"
}
},
},
},
on_attach = function(...)
lsp_attach(...)
-- sem_token_attach(...)
end,
capabilities = capabilities
}
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(client)
lsp_attach(client)
-- sem_token_attach(client)
end,
settings = {
["rust-analyzer"] = {
linksInHover = false
}
},
capabilities = capabilities,
}
})
nvim_lsp.cssls.setup{
on_attach = lsp_attach
}
nvim_lsp.html.setup{
on_attach = lsp_attach
}