| 25 |
25 |
|
map("<leader>lf", vim.lsp.buf.format, "Format") |
| 26 |
26 |
|
map("<leader>v", "<cmd>vsplit | lua vim.lsp.buf.definition()<cr>", "Goto Definition in Vertical Split") |
| 27 |
27 |
|
|
| 28 |
|
- |
local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) |
|
28 |
+ |
local function client_supports_method(client, method, bufnr) |
|
29 |
+ |
if vim.fn.has 'nvim-0.11' == 1 then |
|
30 |
+ |
return client:supports_method(method, bufnr) |
|
31 |
+ |
else |
|
32 |
+ |
return client.supports_method(method, { bufnr = bufnr }) |
|
33 |
+ |
end |
|
34 |
+ |
end |
| 29 |
35 |
|
|
| 30 |
|
- |
-- When cursor stops moving: Highlights all instances of the symbol under the cursor |
| 31 |
|
- |
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { |
| 32 |
|
- |
buffer = event.buf, |
| 33 |
|
- |
group = highlight_augroup, |
| 34 |
|
- |
callback = vim.lsp.buf.document_highlight, |
| 35 |
|
- |
}) |
|
36 |
+ |
local client = vim.lsp.get_client_by_id(event.data.client_id) |
|
37 |
+ |
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then |
|
38 |
+ |
local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) |
| 36 |
39 |
|
|
| 37 |
|
- |
-- When cursor moves: Clears the highlighting |
| 38 |
|
- |
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { |
| 39 |
|
- |
buffer = event.buf, |
| 40 |
|
- |
group = highlight_augroup, |
| 41 |
|
- |
callback = vim.lsp.buf.clear_references, |
| 42 |
|
- |
}) |
|
40 |
+ |
-- When cursor stops moving: Highlights all instances of the symbol under the cursor |
|
41 |
+ |
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { |
|
42 |
+ |
buffer = event.buf, |
|
43 |
+ |
group = highlight_augroup, |
|
44 |
+ |
callback = vim.lsp.buf.document_highlight, |
|
45 |
+ |
}) |
|
46 |
+ |
-- When cursor moves: Clears the highlighting |
|
47 |
+ |
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { |
|
48 |
+ |
buffer = event.buf, |
|
49 |
+ |
group = highlight_augroup, |
|
50 |
+ |
callback = vim.lsp.buf.clear_references, |
|
51 |
+ |
}) |
| 43 |
52 |
|
|
| 44 |
|
- |
-- When LSP detaches: Clears the highlighting |
| 45 |
|
- |
vim.api.nvim_create_autocmd('LspDetach', { |
| 46 |
|
- |
group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }), |
| 47 |
|
- |
callback = function(event2) |
| 48 |
|
- |
vim.lsp.buf.clear_references() |
| 49 |
|
- |
vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf } |
| 50 |
|
- |
end, |
| 51 |
|
- |
}) |
|
53 |
+ |
-- When LSP detaches: Clears the highlighting |
|
54 |
+ |
vim.api.nvim_create_autocmd('LspDetach', { |
|
55 |
+ |
group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }), |
|
56 |
+ |
callback = function(event2) |
|
57 |
+ |
vim.lsp.buf.clear_references() |
|
58 |
+ |
vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf } |
|
59 |
+ |
end, |
|
60 |
+ |
}) |
|
61 |
+ |
end |
| 52 |
62 |
|
end, |
| 53 |
63 |
|
}) |
| 54 |
64 |
|
|
| 55 |
65 |
|
vim.diagnostic.config({ |
| 56 |
66 |
|
virtual_lines = false, |
|
67 |
+ |
-- virtual_text = true, |
| 57 |
68 |
|
underline = true, |
| 58 |
69 |
|
update_in_insert = false, |
| 59 |
70 |
|
severity_sort = true, |