1 -local debug = require 'std.dbg' 1 +local dbg
= require 'std.dbg' 2 2 local icon
= require 'std.icon' 3 3 local defer
= require 'std.defer' 4 4 local map
= require 'std.map' 15 15 require 'bugabinga.lsp.lightbulb' 17 17 local token_update = function ( lsp_client )
18 - local token
= lsp_client.data.token
19 - local buffer
= lsp_client.buffer
20 - local client_id
= lsp_client.data.client_id
21 - local mutable_variable_highlight
= 'MutableVariable' 18 + local token
= lsp_client.data.token
19 + local buffer
= lsp_client.buffer
20 + local client_id
= lsp_client.data.client_id
21 + local mutable_variable_highlight
= 'MutableVariable' 23 - if token.type
== 'variable' and not token.modifiers.readonly
then 24 - vim.lsp.semantic_tokens.highlight_token( token, buffer, client_id, mutable_variable_highlight )
23 + if token.type
== 'variable' and not token.modifiers.readonly
then 24 + vim.lsp.semantic_tokens.highlight_token( token, buffer, client_id, mutable_variable_highlight )
33 33 local expand_path = function ( path )
34 - if vim.fn.executable( path )
== 1 then 35 - return vim.fn.exepath( path )
34 + if vim.fn.executable( path )
== 1 then 35 + return vim.fn.exepath( path )
41 41 local expand_command = function ( command )
42 - vim.validate {
command = { command, {
'string',
'table', }, }, }
42 + vim.validate {
command = { command, {
'string',
'table', }, }, }
44 - if type( command )
== 'table' then 45 - command[
1]
= expand_path( command[
1] )
44 + if type( command )
== 'table' then 45 + command[
1]
= expand_path( command[
1] )
49 - return expand_path( command )
49 + return expand_path( command )
52 52 local lsp_start = function ( file_type_event )
53 - debug.print
'trying to start lsp' 54 - local match
= file_type_event.match
53 + dbg.print
'trying to start lsp' 54 + local match
= file_type_event.match
56 - debug.print(
'filetypes to ignore', ignored.filetypes,
'current filetype', match )
57 - if vim.iter( ignored.filetypes ):find( match )
then return end 56 + dbg.print(
'filetypes to ignore', ignored.filetypes,
'current filetype', match )
57 + if vim.iter( ignored.filetypes ):find( match )
then return end 59 - local bufnr
= file_type_event.buf
60 - local buftype
= vim.api.nvim_get_option_value(
'buftype', {
buf = bufnr, } )
61 - debug.print(
'buftypes to ignore', ignored.buftypes,
'current buftype', buftype )
62 - if vim.iter( ignored.buftypes ):find( buftype )
then return end 59 + local bufnr
= file_type_event.buf
60 + local buftype
= vim.api.nvim_get_option_value(
'buftype', {
buf = bufnr, } )
61 + dbg.print(
'buftypes to ignore', ignored.buftypes,
'current buftype', buftype )
62 + if vim.iter( ignored.buftypes ):find( buftype )
then return end 64 - local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
64 + local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
66 - debug.print(
string.
format(
'searching lsp client for: match: %s, buffer: %s, path: %s', match, bufnr, buffer_path ) )
66 + dbg.print(
string.
format(
'searching lsp client for: match: %s, buffer: %s, path: %s', match, bufnr, buffer_path ) )
68 - local potential_client_configs
= vim.iter( lsp_client_configs )
69 - :map(
function ( config )
71 - [
'config'] = { config,
'table', },
72 - [
'config.name'] = { config.name,
'string', },
73 - [
'config.filetypes'] = { config.filetypes, {
'string',
'table', }, },
74 - [
'config.command'] = { config.command, {
'string',
'table', }, },
75 - [
'config.environment'] = { config.environment,
'table',
true, },
76 - [
'config.root_dir'] = { config.root_dir,
'function',
'string', },
77 - [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true, },
78 - [
'config.settings'] = { config.settings,
'table',
true, },
79 - [
'config.workspaces'] = { config.workspaces,
'boolean',
true, },
80 - [
'config.before_init'] = { config.before_init,
'function',
true, },
81 - [
'config.init_options'] = { config.init_options,
'table',
true, },
82 - [
'config.capabilities'] = { config.capabilities,
'table',
true, },
83 - [
'config.custom_start'] = { config.custom_start,
'function',
true, },
87 - config.command
= type( config.command )
== 'string' and { expand_command( config.command ), }
or 88 - expand_command( config.command )
89 - config.environment
= config.environment
or {}
90 - config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes, }
or config.filetypes
91 - config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
92 - config.workspaces
= config.workspaces
== nil and false or config.workspaces
93 - config.capabilities
= config.capabilities
or {}
94 - config.init_options
= config.init_options
or {}
68 + local potential_client_configs
= vim.iter( lsp_client_configs )
69 + :map(
function ( config )
71 + [
'config'] = { config,
'table', },
72 + [
'config.name'] = { config.name,
'string', },
73 + [
'config.filetypes'] = { config.filetypes, {
'string',
'table', }, },
74 + [
'config.command'] = { config.command, {
'string',
'table', }, },
75 + [
'config.environment'] = { config.environment,
'table',
true, },
76 + [
'config.root_dir'] = { config.root_dir,
'function',
'string', },
77 + [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true, },
78 + [
'config.settings'] = { config.settings,
'table',
true, },
79 + [
'config.workspaces'] = { config.workspaces,
'boolean',
true, },
80 + [
'config.before_init'] = { config.before_init,
'function',
true, },
81 + [
'config.init_options'] = { config.init_options,
'table',
true, },
82 + [
'config.capabilities'] = { config.capabilities,
'table',
true, },
83 + [
'config.custom_start'] = { config.custom_start,
'function',
true, },
87 + config.command
= type( config.command )
== 'string' and { expand_command( config.command ), }
or 88 + expand_command( config.command )
89 + config.environment
= config.environment
or {}
90 + config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes, }
or config.filetypes
91 + config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
92 + config.workspaces
= config.workspaces
== nil and false or config.workspaces
93 + config.capabilities
= config.capabilities
or {}
94 + config.init_options
= config.init_options
or {}
98 - :filter(
function ( config )
99 - return vim.iter( config.filetypes ):find( match )
98 + :filter(
function ( config )
99 + return vim.iter( config.filetypes ):find( match )
103 - debug.print(
'POTENTIAL CLIENTS',
104 - vim.iter( potential_client_configs ):map(
function ( config )
106 - name = config.name,
103 + dbg.print(
'POTENTIAL CLIENTS',
104 + vim.iter( potential_client_configs ):map(
function ( config )
106 + name = config.name,
113 - if table.is_empty( potential_client_configs )
then 114 - debug.print(
'found no lsp client for', buffer_path )
113 + if table.is_empty( potential_client_configs )
then 114 + dbg.print(
'found no lsp client for', buffer_path )
120 - local project_local_lsp_settings
= localrc(
'.lsp.settings.lua',
'table' )
or {}
120 + local project_local_lsp_settings
= localrc(
'.lsp.settings.lua',
'table' )
or {}
121 + local project_local_workspace_folders
= localrc(
'.lsp.workspace_folders.lua',
'table' )
or {}
122 - for _, config
in ipairs( potential_client_configs )
do 123 - local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
124 - local capabilities
= vim.lsp.protocol.make_client_capabilities()
125 - capabilities
= table.extend(
'force', capabilities, config.capabilities )
124 + for lsp, folders
in pairs( project_local_workspace_folders )
do 125 + for idx, path
in ipairs( folders )
do 126 + local cwd
= vim.uv.cwd()
127 + local abs_path
= vim.fs.normalize( vim.fs.joinpath( cwd, path ) )
127 - local settings
= config.settings
128 - local settings_override
= project_local_lsp_settings[config.name]
129 - if settings_override
then 130 - debug.print(
'overriding settings with project local settings', settings, settings_override )
131 - settings
= vim.tbl_deep_extend(
'force', settings, settings_override )
129 + local exists
= vim.uv.fs_stat( abs_path )
130 + if not exists
or exists.type
~= 'directory' then 131 + vim.error(
'the project local workspace folder ' .. 132 + abs_path
.. ' does not exist or is not a directory.' )
134 - debug.print(
'starting command:', config.command )
135 + project_local_workspace_folders[lsp][idx]
= {
uri =
'file://' .. abs_path,
name = path, }
136 - local start_config
= {
137 - cmd = config.command,
138 - cmd_cwd = root_dir,
141 - root_dir = root_dir,
143 - capabilities = capabilities,
145 - settings = settings,
147 - init_options = config.init_options,
148 - name = config.name,
151 - on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
152 - before_init = config.before_init,
154 - on_exit =
function ( code, signal, client_id )
debug.print(
'LSP CLIENT EXIT', code, signal, client_id )
end,
155 - on_attach =
function ( client, attach_bufnr )
debug.print(
'LSP CLIENT ATTACH', client, attach_bufnr )
end,
156 - trace =
debug.get()
and 'on' or 'off',
157 - flags = {
allow_incremental_sync =
true,
debounce_text_changes =
250,
exit_timeout =
200, },
139 + dbg.print(
'patched project local workspace folders', project_local_workspace_folders )
160 - local lsp_starter
= config.custom_start
or vim.lsp.start
141 + for _, config
in ipairs( potential_client_configs )
do 142 + local path
= type( config.command )
== 'table' and config.command[
1]
or config.command
143 + if vim.fn.executable( path )
~= 1 then 144 + vim.notify(
'The LSP ' .. config.name
.. ' does not seem to be installed!' )
162 - debug.print(
'starting lsp', start_config.name, root_dir )
148 + local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
149 + local capabilities
= vim.lsp.protocol.make_client_capabilities()
150 + capabilities
= table.extend(
'force', capabilities, config.capabilities )
164 - lsp_starter( start_config, {
168 - reuse_client =
function ( existing_client, new_config )
170 - 'lsp resuse client',
171 - existing_client.name,
172 - existing_client.workspace_folders,
174 - new_config.root_dir
152 + local settings
= config.settings
153 + local settings_override
= project_local_lsp_settings[config.name]
154 + if settings_override
then 155 + dbg.print(
'overriding settings with project local settings', settings, settings_override )
156 + settings
= vim.tbl_deep_extend(
'force', settings, settings_override )
178 - local same_name
= existing_client.name
== new_config.name
159 + local root_workspace
= root_dir
and {
uri =
'file://' .. root_dir,
name = root_dir, }
or nil 160 + local workspace_folders
= root_workspace
and { root_workspace, }
or nil 161 + local workspace_folders_local
= project_local_workspace_folders[config.name]
162 + if not workspace_folders_local
then dbg.print(
'no local workspace folders found for ' .. config.name )
end 163 + if workspace_folders_local
and config.workspaces
then 164 + dbg.print(
'setting workspace folders to project local workspace folders', workspace_folders_local )
165 + workspace_folders
= workspace_folders
and 166 + vim.tbl_deep_extend(
'force', workspace_folders, workspace_folders_local )
or workspace_folders_local
180 - local new_root_raw
= new_config.root_dir
or nil 181 - local existing_root_raw
= existing_client.workspace_folders
and #existing_client.workspace_folders
>= 1 and 182 - existing_client.workspace_folders[
1].name
or nil 169 + dbg.print(
'starting command:', config.command )
184 - if not (new_root_raw
and existing_root_raw)
then return false end 171 + local start_config
= {
172 + cmd = config.command,
173 + cmd_cwd = root_dir,
176 + root_dir = root_dir,
177 + workspace_folders = workspace_folders,
178 + capabilities = capabilities,
180 + settings = settings,
182 + init_options = config.init_options,
183 + name = config.name,
186 + on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
187 + before_init = config.before_init,
189 + on_exit =
function ( code, signal, client_id ) dbg.print(
'LSP CLIENT EXIT', code, signal, client_id )
end,
190 + on_attach =
function ( client, attach_bufnr ) dbg.print(
'LSP CLIENT ATTACH', client, attach_bufnr )
end,
191 + trace = dbg.get()
and 'on' or 'off',
192 + flags = {
allow_incremental_sync =
true,
debounce_text_changes =
250,
exit_timeout =
200, },
186 - local new_root
= vim.fs.normalize( new_root_raw )
187 - local existing_root
= vim.fs.normalize( existing_root_raw )
188 - local same_root
= new_root
== existing_root
195 + local lsp_starter
= config.custom_start
or vim.lsp.start
190 - local reuse
= same_name
and same_root
191 - debug.print(
'reusing lsp client?', reuse )
197 + dbg.print(
'starting lsp', start_config.name, root_dir )
196 - debug.print(
'ATTACHING LSP CLIENT', config.name )
199 + lsp_starter( start_config, {
203 + reuse_client =
function ( existing_client, new_config )
205 + 'lsp reuse client',
206 + existing_client.name,
207 + existing_client.workspace_folders,
209 + new_config.root_dir
213 + local same_name
= existing_client.name
== new_config.name
215 + local new_root_raw
= new_config.root_dir
or nil 216 + local existing_root_raw
= existing_client.workspace_folders
and #existing_client.workspace_folders
>= 1 and 217 + existing_client.workspace_folders[
1].name
or nil 219 + if not (new_root_raw
and existing_root_raw)
then return false end 221 + local new_root
= vim.fs.normalize( new_root_raw )
222 + local existing_root
= vim.fs.normalize( existing_root_raw )
223 + local same_root
= new_root
== existing_root
225 + local reuse
= same_name
and same_root
226 + dbg.print(
'reusing lsp client?', reuse )
231 + dbg.print(
'ATTACHING LSP CLIENT', config.name )
200 235 local old_formatexpr
204 239 local keybinds
= {}
205 240 local add = function ( client_id, keybind_remover )
207 - client_id = { client_id,
'number', },
208 - keybind_remover = { keybind_remover,
'function', },
210 - if not table.contains( keybinds, client_id )
then 211 - keybinds[client_id]
= {}
213 - table.
insert( keybinds[client_id], keybind_remover )
242 + client_id = { client_id,
'number', },
243 + keybind_remover = { keybind_remover,
'function', },
245 + if not table.contains( keybinds, client_id )
then 246 + keybinds[client_id]
= {}
248 + table.
insert( keybinds[client_id], keybind_remover )
216 251 local lsp_attach = function ( args )
217 - local bufnr
= args.buf
218 - local client_id
= args.data.client_id
219 - local client
= vim.lsp.get_client_by_id( client_id )
220 - if not client
then return end 252 + local bufnr
= args.buf
253 + local client_id
= args.data.client_id
254 + local client
= vim.lsp.get_client_by_id( client_id )
255 + if not client
then return end 222 - debug.print( client.server_capabilities )
257 + dbg.print( client.server_capabilities )
224 - if client.server_capabilities.definitionProvider
then 225 - old_tagfunc
= vim.bo[bufnr].tagfunc
226 - vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 259 + if client.server_capabilities.definitionProvider
then 260 + old_tagfunc
= vim.bo[bufnr].tagfunc
261 + vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 229 - if client.server_capabilities.documentFormattingProvider
then 230 - old_formatexpr
= vim.bo[bufnr].formatexpr
231 - vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr' 264 + if client.server_capabilities.documentFormattingProvider
then 265 + old_formatexpr
= vim.bo[bufnr].formatexpr
266 + vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr' 234 - if client.server_capabilities.completionProvider
then 235 - old_omnifunc
= vim.bo[bufnr].omnifunc
236 - vim.bo[bufnr].omnifunc
= 'v:lua.vim.lsp.omnifunc' 269 + if client.server_capabilities.completionProvider
then 270 + old_omnifunc
= vim.bo[bufnr].omnifunc
271 + vim.bo[bufnr].omnifunc
= 'v:lua.vim.lsp.omnifunc' 239 - if client.server_capabilities.documentSymbolProvider
then 240 - local navic_ok, navic
= pcall(
require,
'nvim-navic' )
242 - navic.attach( client, bufnr )
244 - vim.notify
'nvim-navic not found. could not attach to lsp client.' 246 - local navbuddy_ok, navbuddy
= pcall(
require,
'nvim-navbuddy' )
247 - if navbuddy_ok
then 248 - navbuddy.attach( client, bufnr )
250 - description =
'Open overview of symbols in current buffer',
252 - keys =
'<leader>lo',
253 - command =
function () navbuddy.open( bufnr )
end,
257 - vim.notify
'nvim-navbuddy not found. could not attach to lsp client.' 274 + if client.server_capabilities.documentSymbolProvider
then 275 + local navic_ok, navic
= pcall(
require,
'nvim-navic' )
277 + navic.attach( client, bufnr )
279 + vim.notify
'nvim-navic not found. could not attach to lsp client.' 281 + local navbuddy_ok, navbuddy
= pcall(
require,
'nvim-navbuddy' )
282 + if navbuddy_ok
then 283 + navbuddy.attach( client, bufnr )
285 + description =
'Open overview of symbols in current buffer',
287 + keys =
'<leader>lo',
288 + command =
function () navbuddy.open( bufnr )
end,
292 + vim.notify
'nvim-navbuddy not found. could not attach to lsp client.' 261 - if client.server_capabilities.documentHighlightProvider
then 264 - local debounced_highlight
= defer.debounce_leading( vim.lsp.buf.document_highlight, delay )
265 - local debounced_clear
= defer.debounce_leading( vim.lsp.buf.clear_references, delay )
296 + if client.server_capabilities.documentHighlightProvider
then 299 + local debounced_highlight
= defer.debounce_leading( vim.lsp.buf.document_highlight, delay )
300 + local debounced_clear
= defer.debounce_leading( vim.lsp.buf.clear_references, delay )
267 - auto
'document_highlight' {
269 - description =
'Highlight symbol under cursor on hold',
270 - events =
'CursorHold',
272 - command = debounced_highlight,
275 - description =
'Remove highlight from symbol under cursor on move',
276 - events = {
'CursorMoved',
'InsertEnter', },
278 - command = debounced_clear,
302 + auto
'document_highlight' {
304 + description =
'Highlight symbol under cursor on hold',
305 + events =
'CursorHold',
307 + command = debounced_highlight,
310 + description =
'Remove highlight from symbol under cursor on move',
311 + events = {
'CursorMoved',
'InsertEnter', },
313 + command = debounced_clear,
283 - if client.server_capabilities.inlayHintProvider
then 284 - add( client_id, map.normal {
285 - description =
'Toggle inlay hints',
288 - keys =
'<leader>ti',
289 - command =
function ()
290 - vim.lsp.inlay_hint.enable( bufnr,
nil )
318 + if client.server_capabilities.inlayHintProvider
then 319 + add( client_id, map.normal {
320 + description =
'Toggle inlay hints',
323 + keys =
'<leader>ti',
324 + command =
function ()
325 + vim.lsp.inlay_hint.enable( bufnr,
nil )
295 - add( client_id, map.normal {
296 - description =
'Show hover documentation above cursor.',
299 - keys = {
'K',
'<leader>lk', },
300 - command = vim.lsp.buf.hover,
330 + add( client_id, map.normal {
331 + description =
'Show hover documentation above cursor.',
334 + keys = {
'K',
'<leader>lk', },
335 + command = vim.lsp.buf.hover,
303 - add( client_id, map.normal {
304 - description =
'Show signature help under cursor.',
307 - keys = {
'H',
'<leader>ls', },
308 - command = vim.lsp.buf.signature_help,
338 + add( client_id, map.insert {
339 + description =
'Show signature help under cursor.',
342 + keys = {
'<C-h>', },
343 + command = vim.lsp.buf.signature_help,
311 - add( client_id, map.normal {
312 - description =
'Show available code actions on current line.',
315 - keys =
'<leader>la',
316 - command = vim.lsp.buf.code_action,
346 + add( client_id, map.normal {
347 + description =
'Show available code actions on current line.',
350 + keys =
'<leader>la',
351 + command = vim.lsp.buf.code_action,
319 - add( client_id, map.normal {
320 - description =
'Goto to definition of symbol under cursor.',
323 - keys =
'<leader>ld',
324 - command = vim.lsp.buf.definition,
354 + add( client_id, map.normal {
355 + description =
'Goto to definition of symbol under cursor.',
358 + keys =
'<leader>ld',
359 + command = vim.lsp.buf.definition,
327 - add( client_id, map.normal {
328 - description =
'Show implementations of symbol under cursor.',
331 - keys =
'<leader>li',
332 - command = vim.lsp.buf.implementation,
362 + add( client_id, map.normal {
363 + description =
'Show implementations of symbol under cursor.',
366 + keys =
'<leader>li',
367 + command = vim.lsp.buf.implementation,
335 - add( client_id, map.normal {
336 - description =
'Show incoming calls of symbol under cursor.',
339 - keys =
'<leader>lci',
340 - command = vim.lsp.buf.incoming_calls,
370 + add( client_id, map.normal {
371 + description =
'Show incoming calls of symbol under cursor.',
374 + keys =
'<leader>lci',
375 + command = vim.lsp.buf.incoming_calls,
343 - add( client_id, map.normal {
344 - description =
'Show outgoing calls of symbol under cursor.',
347 - keys =
'<leader>lco',
348 - command = vim.lsp.buf.outgoing_calls,
378 + add( client_id, map.normal {
379 + description =
'Show outgoing calls of symbol under cursor.',
382 + keys =
'<leader>lco',
383 + command = vim.lsp.buf.outgoing_calls,
351 - add( client_id, map.normal {
352 - description =
'Show references of symbol under cursor.',
355 - keys =
'<leader>ln',
356 - command = vim.lsp.buf.references,
386 + add( client_id, map.normal {
387 + description =
'Show references of symbol under cursor.',
390 + keys =
'<leader>ln',
391 + command = vim.lsp.buf.references,
359 - add( client_id, map.normal {
360 - description =
'Rename symbol under cursor.',
363 - keys = {
'<f2>',
'<leader>lr', },
364 - command = vim.lsp.buf.rename,
394 + add( client_id, map.normal {
395 + description =
'Rename symbol under cursor.',
398 + keys = {
'<f2>',
'<leader>lr', },
399 + command = vim.lsp.buf.rename,
368 403 local lsp_detach = function ( args )
369 - debug.print(
'DETACH LSP', args )
404 + dbg.print(
'DETACH LSP', args )
371 - local bufnr
= args.buf
372 - local client_id
= args.data.client_id
373 - local client
= vim.lsp.get_client_by_id( client_id )
374 - if not client
then return end 406 + local bufnr
= args.buf
407 + local client_id
= args.data.client_id
408 + local client
= vim.lsp.get_client_by_id( client_id )
409 + if not client
then return end 376 - if client.server_capabilities.definitionProvider
then 377 - vim.bo[bufnr].tagfunc
= old_tagfunc
411 + if client.server_capabilities.definitionProvider
then 412 + vim.bo[bufnr].tagfunc
= old_tagfunc
380 - if client.server_capabilities.documentFormattingProvider
then 381 - vim.bo[bufnr].formatexpr
= old_formatexpr
415 + if client.server_capabilities.documentFormattingProvider
then 416 + vim.bo[bufnr].formatexpr
= old_formatexpr
384 - if client.server_capabilities.completionProvider
then 385 - vim.bo[bufnr].omnifunc
= old_omnifunc
419 + if client.server_capabilities.completionProvider
then 420 + vim.bo[bufnr].omnifunc
= old_omnifunc
388 - if table.contains( keybinds, client_id )
then 389 - for _, keybind_delete
in ipairs( keybinds[client_id] )
do 423 + if table.contains( keybinds, client_id )
then 424 + for _, keybind_delete
in ipairs( keybinds[client_id] )
do 397 - description =
'Start or reuse LSP client',
398 - events =
'FileType',
399 - command = lsp_start,
402 - description =
'Hook: LSP client attached to buffer',
403 - events =
'LspAttach',
404 - command = lsp_attach,
407 - description =
'Hook: LSP client detached from buffer',
408 - events =
'LspDetach',
409 - command = lsp_detach,
412 - description =
'Semantic Tokens from the LSP',
413 - events =
'LspTokenUpdate',
414 - command = token_update,
432 + description =
'Start or reuse LSP client',
433 + events =
'FileType',
434 + command = lsp_start,
437 + description =
'Hook: LSP client attached to buffer',
438 + events =
'LspAttach',
439 + command = lsp_attach,
442 + description =
'Hook: LSP client detached from buffer',
443 + events =
'LspDetach',
444 + command = lsp_detach,
447 + description =
'Semantic Tokens from the LSP',
448 + events =
'LspTokenUpdate',
449 + command = token_update,
418 453 local lsp_info = function ( command )
419 - local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
420 - local active_clients
= vim.lsp.get_clients( all_or_current )
454 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
455 + local active_clients
= vim.lsp.get_clients( all_or_current )
422 - local infos
= vim.iter( active_clients )
423 - :map(
function ( client )
424 - local name
= client.name
425 - local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
426 - assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
457 + local infos
= vim.iter( active_clients )
458 + :map(
function ( client )
459 + local name
= client.name
460 + local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
461 + assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
428 - local full_cmd
= table.deep_copy( client.config.cmd )
429 - full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
433 - cmd =
table.
concat( full_cmd,
' ' ),
434 - workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
436 - filetypes =
table.
concat( config.filetypes,
', ' ),
437 - single_file_support = config.single_file_support,
438 - workspaces = config.workspaces,
463 + local full_cmd
= table.deep_copy( client.config.cmd )
464 + full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
468 + cmd =
table.
concat( full_cmd,
' ' ),
469 + workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
471 + filetypes =
table.
concat( config.filetypes,
', ' ),
472 + single_file_support = config.single_file_support,
473 + workspaces = config.workspaces,
444 - ui.show_tree( infos )
479 + ui.show_tree( infos )
447 482 local lsp_info_extended = function ( command )
448 - local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
449 - local active_clients
= vim.lsp.get_clients( all_or_current )
450 - ui.show_tree( active_clients )
483 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
484 + local active_clients
= vim.lsp.get_clients( all_or_current )
485 + ui.show_tree( active_clients )
453 488 user_command.LspInfo
454 489 'Shows basic information about running LSP clients.' 455 - {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
490 + {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
459 494 user_command.LspInfoExtended
460 495 'Shows detailed information about running LSP clients.' 461 - {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
496 + {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
469 504 local completion_icons
= {
470 - Class = icon.class,
471 - Color = icon.color,
472 - Constant = icon.constant,
473 - Constructor = icon.constructor,
475 - EnumMember = icon.enum_member,
476 - Field = icon.field,
478 - Folder = icon.folder,
479 - Function = icon[
'function'],
480 - Interface = icon.interface,
481 - Keyword = icon.keyword,
482 - Method = icon.method,
483 - Module = icon.module,
484 - Property = icon.property,
485 - Snippet = icon.snippet,
486 - Struct = icon.struct,
489 - Value = icon.value,
490 - Variable = icon.variable,
505 + Class = icon.class,
506 + Color = icon.color,
507 + Constant = icon.constant,
508 + Constructor = icon.constructor,
510 + EnumMember = icon.enum_member,
511 + Field = icon.field,
513 + Folder = icon.folder,
514 + Function = icon[
'function'],
515 + Interface = icon.interface,
516 + Keyword = icon.keyword,
517 + Method = icon.method,
518 + Module = icon.module,
519 + Property = icon.property,
520 + Snippet = icon.snippet,
521 + Struct = icon.struct,
524 + Value = icon.value,
525 + Variable = icon.variable,
493 528 local completion_kinds
= vim.lsp.protocol.CompletionItemKind
494 529 for i, kind
in ipairs( completion_kinds )
do 495 - completion_kinds[i]
= completion_icons[kind]
or kind
530 + completion_kinds[i]
= completion_icons[kind]
or kind
498 533 return setmetatable( _, {} )