This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathinit.lua
404 lines (388 loc) · 11.7 KB
/
init.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
local lsp = {}
--- Internal state of LSP module
-- Flag to enable/disable completions for <leader>tc keybind.
lsp.__completions_enabled = true
lsp.settings = {
snippets = {
history = true,
updateevents = "TextChanged,TextChangedI",
},
signature = {
bind = true,
doc_lines = 10,
floating_window = false, -- show hint in a floating window, set to false for virtual text only mode
floating_window_above_cur_line = true,
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = true, -- virtual hint enable
hint_prefix = " ",
hint_scheme = "String",
hi_parameter = "Search", -- how your parameter will be highlight
max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
transparency = 80,
extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom
debug = false, -- set to true to enable debug logging
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
shadow_blend = 36, -- if you using shadow as border use this set the opacity
shadow_guibg = "Black", -- if you using shadow as border use this set the color e.g. 'Green' or '#121315'
},
icons = {
error = "",
warn = "",
hint = "",
info = "",
},
severity_sort = true,
completion = {
kinds = {
Text = " ",
Method = " ",
Function = " ",
Constructor = " ",
Field = "ﴲ ",
Variable = " ",
Class = " ",
Interface = "ﰮ ",
Module = " ",
Property = "ﰠ ",
Unit = " ",
Value = " ",
Enum = "練",
Keyword = " ",
Snippet = " ",
Color = " ",
File = " ",
Reference = " ",
Folder = " ",
EnumMember = " ",
Constant = "ﲀ ",
Struct = "ﳤ ",
Event = " ",
Operator = " ",
TypeParameter = " ",
},
experimental = {
ghost_text = true,
},
completeopt = "menu,menuone,preview,noinsert",
window = {
documentation = {
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
},
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
sources = {
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer" },
},
},
sorting = {
"offset",
"exact",
"score",
"kind",
"sort_text",
"length",
"order",
},
}
lsp.packages = {
["nvim-lspconfig"] = {
"neovim/nvim-lspconfig",
},
["nvim-cmp"] = {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"L3MON4D3/LuaSnip",
},
},
["cmp-nvim-lua"] = {
"hrsh7th/cmp-nvim-lua",
-- after = "nvim-cmp",
dependencies = {
"hrsh7th/nvim-cmp",
}
},
["cmp-nvim-lsp"] = {
"hrsh7th/cmp-nvim-lsp",
-- after = "nvim-cmp",
dependencies = {
"hrsh7th/nvim-cmp",
}
},
["cmp-path"] = {
"hrsh7th/cmp-path",
-- after = "nvim-cmp",
dependencies = {
"hrsh7th/nvim-cmp",
}
},
["cmp-buffer"] = {
"hrsh7th/cmp-buffer",
-- after = "nvim-cmp",
dependencies = {
"hrsh7th/nvim-cmp",
}
},
["cmp_luasnip"] = {
"saadparwaiz1/cmp_luasnip",
-- after = "nvim-cmp",
dependencies = {
"hrsh7th/nvim-cmp",
}
},
["lsp_signature.nvim"] = {
"ray-x/lsp_signature.nvim",
-- after = "nvim-lspconfig",
dependencies = {
"neovim/nvim-lspconfig",
},
event = "VeryLazy",
},
}
lsp.configs = {}
lsp.configs["nvim-lspconfig"] = function()
-- Lsp Symbols
local signs = {
Error = doom.features.lsp.settings.icons.error,
Warn = doom.features.lsp.settings.icons.warn,
Info = doom.features.lsp.settings.icons.info,
Hint = doom.features.lsp.settings.icons.hint,
}
local hl = "DiagnosticSign"
for severity, icon in pairs(signs) do
local highlight = hl .. severity
vim.fn.sign_define(highlight, {
text = icon,
texthl = highlight,
numhl = highlight,
})
end
vim.diagnostic.config({
virtual_text = doom.features.lsp.settings.virtual_text,
severity_sort = doom.features.lsp.settings.severity_sort,
float = {
show_header = false,
border = "rounded",
},
})
-- Border for lsp_popups
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = doom.border_style,
})
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = doom.border_style,
})
-- symbols for autocomplete
local kinds = {}
for typ, icon in pairs(doom.features.lsp.settings.completion.kinds) do
table.insert(kinds, " " .. icon .. " (" .. typ .. ") ")
end
vim.lsp.protocol.CompletionItemKind = kinds
-- suppress error messages from lang servers
vim.notify = function(msg, log_level, _)
if msg:match("exit code") then
return
end
if log_level == vim.log.levels.ERROR then
vim.api.nvim_err_writeln(msg)
else
vim.api.nvim_echo({ { msg } }, true, {})
end
end
end
lsp.configs["nvim-cmp"] = function()
local utils = require("doom.utils")
local cmp_ok, cmp = pcall(require, "cmp")
local luasnip_ok, luasnip = pcall(require, "luasnip")
if not cmp_ok or not luasnip_ok then
return
end
luasnip.config.set_config(doom.features.lsp.settings.snippets)
local replace_termcodes = utils.replace_termcodes
--- Helper function to check what <Tab> behaviour to use
--- @return boolean
local function check_backspace()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
-- Initalize the cmp toggle if it doesn't exist.
if _doom.cmp_enable == nil then
_doom.cmp_enable = true
end
-- Fetch the comparators from cmp
local comparators = require("cmp.config.compare")
doom.features.lsp.settings.sorting = vim.tbl_map(function(comparator)
return comparators[comparator]
end, doom.features.lsp.settings.sorting)
cmp.setup(vim.tbl_deep_extend("force", doom.features.lsp.settings.completion, {
completeopt = nil,
completion = {
completeopt = doom.features.lsp.settings.completion.completeopt,
},
formatting = {
format = function(entry, item)
item.kind =
string.format("%s %s", doom.features.lsp.settings.completion.kinds[item.kind], item.kind)
item.dup = vim.tbl_contains({ "path", "buffer" }, entry.source.name)
return item
end,
},
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
-- ["<ESC>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
vim.fn.feedkeys(replace_termcodes("<Plug>luasnip-expand-or-jump"), "")
elseif check_backspace() then
vim.fn.feedkeys(replace_termcodes("<Tab>"), "n")
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
vim.fn.feedkeys(replace_termcodes("<Plug>luasnip-jump-prev"), "")
else
fallback()
end
end, {
"i",
"s",
}),
},
}, {
mapping = type(doom.features.lsp.settings.completion.mapping) == "function"
and doom.features.lsp.settings.completion.mapping(cmp)
or doom.features.lsp.settings.completion.mapping,
enabled = function()
return _doom.cmp_enable and vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt"
end,
}))
end
lsp.configs["lsp_signature.nvim"] = function()
-- Signature help
require("lsp_signature").setup(
vim.tbl_deep_extend("force", doom.features.lsp.settings.signature, {
handler_opts = {
border = doom.border_style,
},
})
)
end
lsp.binds = function()
return {
{ "K", vim.lsp.buf.hover, name = "Show hover doc" },
{ "[d", vim.diagnostic.goto_prev, name = "Jump to prev diagnostic" },
{ "]d", vim.diagnostic.goto_next, name = "Jump to next diagnostic" },
{
"g",
{
{ "D", vim.lsp.buf.declaration, "Jump to declaration" },
{ "d", vim.lsp.buf.definition, name = "Jump to definition" },
{ "r", vim.lsp.buf.references, name = "Jump to references" },
{ "i", vim.lsp.buf.implementation, name = "Jump to implementation" },
{ "a", vim.lsp.buf.code_action, name = "Do code action" },
},
},
{
"<C-",
{
{ "p>", vim.diagnostic.goto_prev, name = "Jump to prev diagnostic" },
{ "n>", vim.diagnostic.goto_next, name = "Jump to next diagnostic" },
{ "k>", vim.lsp.buf.signature_help, name = "Show signature help" },
},
},
{
"<leader>",
name = "+prefix",
{
{
"c",
name = "+code",
{
{ "r", vim.lsp.buf.rename, name = "Rename" },
{ "a", vim.lsp.buf.code_action, name = "Do action" },
{ "t", vim.lsp.buf.type_definition, name = "Jump to type" },
{ "D", vim.lsp.buf.declaration, "Jump to declaration" },
{ "d", vim.lsp.buf.definition, name = "Jump to definition" },
{ "R", vim.lsp.buf.references, name = "Jump to references" },
{ "i", vim.lsp.buf.implementation, name = "Jump to implementation" },
{
"l",
name = "+lsp",
{
{ "i", "<cmd>LspInfo<CR>", name = "Inform" },
{ "r", "<cmd>LspRestart<CR>", name = "Restart" },
{ "s", "<cmd>LspStart<CR>", name = "Start" },
{ "d", "<cmd>LspStop<CR>", name = "Disconnect" },
},
},
{
"d",
name = "+diagnostics",
{
{ "[", vim.diagnostic.goto_prev, name = "Jump to prev" },
{ "]", vim.diagnostic.goto_next, name = "Jump to next" },
{ "p", vim.diagnostic.goto_prev, name = "Jump to prev" },
{ "n", vim.diagnostic.goto_next, name = "Jump to next" },
{
"L",
function()
vim.diagnostic.open_float(0, {
focusable = false,
border = doom.border_style,
})
end,
name = "Line",
},
{ "l", vim.diagnostic.setloclist, name = "Loclist" },
},
},
},
},
{
"t",
name = "+tweak",
{
{
"c",
function()
lsp.__completions_enabled = not lsp.__completions_enabled
local bool2str = require("doom.utils").bool2str
print(string.format("completion=%s", bool2str(lsp.__completions_enabled)))
end,
name = "Toggle completion",
},
},
},
},
},
}
end
return lsp