1+ local lspconfig = vim .F .npcall (require , " lspconfig" )
2+ if not lspconfig then
3+ return
4+ end
5+
16local imap = require (" tj.keymap" ).imap
27local nmap = require (" tj.keymap" ).nmap
8+ local autocmd = require (" tj.auto" ).autocmd
9+ local autocmd_clear = vim .api .nvim_clear_autocmds
310
4- local has_lsp , lspconfig = pcall (require , " lspconfig" )
5- if not has_lsp then
6- return
7- end
11+ local semantic = vim .F .npcall (require , " nvim-semantic-tokens" )
812
913local is_mac = vim .fn .has " macunix" == 1
1014
1115local lspconfig_util = require " lspconfig.util"
1216
13- local ok , nvim_status = pcall (require , " lsp-status" )
14- if not ok then
15- nvim_status = nil
16- end
17-
1817local telescope_mapper = require " tj.telescope.mappings"
1918local handlers = require " tj.lsp.handlers"
2019
2120local ts_util = require " nvim-lsp-ts-utils"
2221
23- -- Can set this lower if needed.
24- -- require("vim.lsp.log").set_level "debug"
25- -- require("vim.lsp.log").set_level "trace"
26-
27- local status = require " tj.lsp.status"
28- if status then
29- status .activate ()
30- end
31-
3222local custom_init = function (client )
3323 client .config .flags = client .config .flags or {}
3424 client .config .flags .allow_incremental_sync = true
3525end
3626
37- local augroup_format = vim .api .nvim_create_augroup (" my_lsp_format" , { clear = true })
27+ local augroup_highlight = vim .api .nvim_create_augroup (" custom-lsp-references" , { clear = true })
28+ local augroup_codelens = vim .api .nvim_create_augroup (" custom-lsp-codelens" , { clear = true })
29+ local augroup_format = vim .api .nvim_create_augroup (" custom-lsp-format" , { clear = true })
30+ local augroup_semantic = vim .api .nvim_create_augroup (" custom-lsp-semantic" , { clear = true })
31+
3832local autocmd_format = function (async , filter )
3933 vim .api .nvim_clear_autocmds { buffer = 0 , group = augroup_format }
4034 vim .api .nvim_create_autocmd (" BufWritePre" , {
@@ -100,13 +94,9 @@ local buf_inoremap = function(opts)
10094 imap (opts )
10195end
10296
103- local custom_attach = function (client )
97+ local custom_attach = function (client , bufnr )
10498 local filetype = vim .api .nvim_buf_get_option (0 , " filetype" )
10599
106- if nvim_status then
107- nvim_status .on_attach (client )
108- end
109-
110100 buf_inoremap { " <c-s>" , vim .lsp .buf .signature_help }
111101
112102 buf_nnoremap { " <space>cr" , vim .lsp .buf .rename }
@@ -133,41 +123,48 @@ local custom_attach = function(client)
133123
134124 -- Set autocommands conditional on server_capabilities
135125 if client .server_capabilities .documentHighlightProvider then
136- vim .cmd [[
137- augroup lsp_document_highlight
138- autocmd! * <buffer>
139- autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
140- autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
141- augroup END
142- ]]
126+ autocmd_clear { group = augroup_highlight , buffer = bufnr }
127+ autocmd { " CursorHold" , augroup_highlight , vim .lsp .buf .document_highlight , buffer = bufnr }
128+ autocmd { " CursorMoved" , augroup_highlight , vim .lsp .buf .clear_references , buffer = bufnr }
143129 end
144130
145131 if false and client .server_capabilities .codeLensProvider then
146132 if filetype ~= " elm" then
147- vim .cmd [[
148- augroup lsp_document_codelens
149- au! * <buffer>
150- autocmd BufEnter ++once <buffer> lua require"vim.lsp.codelens".refresh()
151- autocmd BufWritePost,CursorHold <buffer> lua require"vim.lsp.codelens".refresh()
152- augroup END
153- ]]
133+ autocmd_clear { group = augroup_codelens , buffer = bufnr }
134+ autocmd { " BufEnter" , augroup_codelens , vim .lsp .codelens .refresh , bufnr , once = true }
135+ autocmd { { " BufWritePost" , " CursorHold" }, augroup_codelens , vim .lsp .codelens .refresh , bufnr }
154136 end
155137 end
156138
139+ local caps = client .server_capabilities
140+ if semantic and caps .semanticTokensProvider and caps .semanticTokensProvider .full then
141+ autocmd_clear { group = augroup_semantic , buffer = bufnr }
142+ autocmd { " TextChanged" , augroup_semantic , vim .lsp .buf .semantic_tokens_full , bufnr }
143+ end
144+
157145 -- Attach any filetype specific options to the client
158146 filetype_attach [filetype ](client )
159147end
160148
161149local updated_capabilities = vim .lsp .protocol .make_client_capabilities ()
162- if nvim_status then
163- updated_capabilities = vim .tbl_deep_extend (" keep" , updated_capabilities , nvim_status .capabilities )
164- end
165- updated_capabilities .textDocument .codeLens = { dynamicRegistration = false }
166- updated_capabilities = require (" cmp_nvim_lsp" ).update_capabilities (updated_capabilities )
150+
151+ -- Completion configuration
152+ require (" cmp_nvim_lsp" ).update_capabilities (updated_capabilities )
167153updated_capabilities .textDocument .completion .completionItem .insertReplaceSupport = false
168154
169- local rust_analyzer
155+ -- Semantic token configuration
156+ if semantic then
157+ semantic .setup {
158+ preset = " default" ,
159+ highlighters = { require " nvim-semantic-tokens.table-highlighter" },
160+ }
161+
162+ semantic .extend_capabilities (updated_capabilities )
163+ end
164+
165+ updated_capabilities .textDocument .codeLens = { dynamicRegistration = false }
170166
167+ local rust_analyzer , rust_analyzer_cmd = nil , { " rustup" , " run" , " nightly" , " rust-analyzer" }
171168local has_rt , rt = pcall (require , " rust-tools" )
172169if has_rt then
173170 local extension_path = vim .fn .expand " ~/.vscode/extensions/sadge-vscode/extension/"
@@ -176,7 +173,7 @@ if has_rt then
176173
177174 rt .setup {
178175 server = {
179- cmd = { " rustup " , " run " , " nightly " , " rust-analyzer " } ,
176+ cmd = rust_analyzer_cmd ,
180177 capabilities = updated_capabilities ,
181178 on_attach = custom_attach ,
182179 },
@@ -191,13 +188,11 @@ if has_rt then
191188 }
192189else
193190 rust_analyzer = {
194- cmd = { " rustup" , " run" , " nightly" , " rust-analyzer" },
195- -- cmd = { "rust-analyzer" },
191+ cmd = rust_analyzer_cmd ,
196192 }
197193end
198194
199195local servers = {
200-
201196 -- Also uses `shellcheck` and `explainshell`
202197 bashls = true ,
203198
@@ -220,11 +215,9 @@ local servers = {
220215 " --clang-tidy" ,
221216 " --header-insertion=iwyu" ,
222217 },
223- -- Required for lsp-status
224218 init_options = {
225219 clangdFileStatus = true ,
226220 },
227- handlers = nvim_status and nvim_status .extensions .clangd .setup () or nil ,
228221 },
229222
230223 gopls = {
423416-- end
424417-- ]]
425418
426- -- python graveyard
427- -- lspconfig.pyls.setup {
428- -- plugins = {
429- -- pyls_mypy = {
430- -- enabled = true,
431- -- live_mode = false
432- -- }
433- -- },
434- -- on_init = custom_init,
435- -- on_attach = custom_attach,
436- -- capabilities = updated_capabilities,
437- -- }
438-
439- -- lspconfig.jedi_language_server.setup {
440- -- on_init = custom_init,
441- -- on_attach = custom_attach,
442- -- capabilities = updated_capabilities,
443- -- }
444-
445419-- Set up null-ls
446420local use_null = true
447421if use_null then
@@ -456,6 +430,10 @@ if use_null then
456430 }
457431end
458432
433+ -- Can set this lower if needed.
434+ -- require("vim.lsp.log").set_level "debug"
435+ -- require("vim.lsp.log").set_level "trace"
436+
459437return {
460438 on_init = custom_init ,
461439 on_attach = custom_attach ,
0 commit comments