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 - dbg.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 - dbg.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 - dbg.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 - dbg.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',
'table'},
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',
'table' },
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 - dbg.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 - dbg.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 {}
121 - local project_local_workspace_folders
= localrc(
'.lsp.workspace_folders.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 {}
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 ) )
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 ) )
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.' )
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.' )
135 - project_local_workspace_folders[lsp][idx]
= {
uri =
'file://' .. abs_path,
name = path, }
135 + project_local_workspace_folders[lsp][idx]
= {
uri =
'file://' .. abs_path,
name = path }
139 - dbg.print(
'patched project local workspace folders', project_local_workspace_folders )
139 + dbg.print(
'patched project local workspace folders', project_local_workspace_folders )
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!' )
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!' )
148 - local capabilities
= vim.lsp.protocol.make_client_capabilities()
149 - capabilities
= table.extend(
'force', capabilities, config.capabilities )
148 + local capabilities
= vim.lsp.protocol.make_client_capabilities()
149 + capabilities
= table.extend(
'force', capabilities, config.capabilities )
151 - local settings
= config.settings
152 - local settings_override
= project_local_lsp_settings[config.name]
153 - if settings_override
then 154 - dbg.print(
'overriding settings with project local settings', settings, settings_override )
155 - settings
= vim.tbl_deep_extend(
'force', settings, settings_override )
151 + local settings
= config.settings
152 + local settings_override
= project_local_lsp_settings[config.name]
153 + if settings_override
then 154 + dbg.print(
'overriding settings with project local settings', settings, settings_override )
155 + settings
= vim.tbl_deep_extend(
'force', settings, settings_override )
158 158 local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
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
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
169 - dbg.print(
'starting command:', config.command )
169 + dbg.print(
'starting command:', config.command )
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, },
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 },
195 - local lsp_starter
= config.custom_start
or vim.lsp.start
195 + local lsp_starter
= config.custom_start
or vim.lsp.start
197 - dbg.print(
'starting lsp', start_config.name, root_dir )
197 + dbg.print(
'starting lsp', start_config.name, root_dir )
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
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
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 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 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
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 )
225 + local reuse
= same_name
and same_root
226 + dbg.print(
'reusing lsp client?', reuse )
231 - dbg.print(
'STARTING LSP CLIENT', config.name )
231 + dbg.print(
'STARTING LSP CLIENT', config.name )
235 235 local old_formatexpr
239 239 local keybinds
= {}
240 240 local add = function ( 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 )
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 )
251 251 local lsp_attach = function ( args )
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 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 257 - dbg.print( client.server_capabilities )
257 + dbg.print( client.server_capabilities )
259 - if client.server_capabilities.definitionProvider
then 260 - old_tagfunc
= vim.bo[bufnr].tagfunc
261 - 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' 264 - if client.server_capabilities.documentFormattingProvider
then 265 - old_formatexpr
= vim.bo[bufnr].formatexpr
266 - 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' 269 - if client.server_capabilities.completionProvider
then 270 - old_omnifunc
= vim.bo[bufnr].omnifunc
271 - 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' 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.' 274 + if client.server_capabilities.documentHighlightProvider
then 277 + local debounced_highlight
= defer.debounce_leading( vim.lsp.buf.document_highlight, delay )
278 + 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 )
280 + auto
'document_highlight' {
282 + description =
'Highlight symbol under cursor on hold',
283 + events =
'CursorHold',
285 + command = debounced_highlight,
288 + description =
'Remove highlight from symbol under cursor on move',
289 + events = {
'CursorMoved',
'InsertEnter' },
291 + 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,
296 + if client.server_capabilities.inlayHintProvider
then 297 + add( client_id, map.normal {
298 + description =
'Toggle inlay hints',
301 + keys =
'<leader>ti',
302 + command =
function ()
303 + 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 )
308 + add( client_id, map.normal {
309 + description =
'Show hover documentation above cursor.',
312 + keys = {
'K',
'<leader>lk' },
313 + 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,
316 + add( client_id, map.insert {
317 + description =
'Show signature help under cursor.',
320 + keys = {
'<C-h>' },
321 + 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,
324 + add( client_id, map.normal {
325 + description =
'Show available code actions on current line.',
328 + keys =
'<leader>la',
329 + 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,
332 + add( client_id, map.normal {
333 + description =
'Goto to definition of symbol under cursor.',
336 + keys =
'<leader>ld',
337 + 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,
340 + add( client_id, map.normal {
341 + description =
'Show implementations of symbol under cursor.',
344 + keys =
'<leader>li',
345 + 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,
348 + add( client_id, map.normal {
349 + description =
'Show incoming calls of symbol under cursor.',
352 + keys =
'<leader>lc',
353 + command = vim.lsp.buf.incoming_calls,
370 - add( client_id, map.normal {
371 - description =
'Show incoming calls of symbol under cursor.',
374 - keys =
'<leader>lc',
375 - command = vim.lsp.buf.incoming_calls,
356 + add( client_id, map.normal {
357 + description =
'Show outgoing calls of symbol under cursor.',
360 + keys =
'<leader>lC',
361 + command = vim.lsp.buf.outgoing_calls,
378 - add( client_id, map.normal {
379 - description =
'Show outgoing calls of symbol under cursor.',
382 - keys =
'<leader>lC',
383 - command = vim.lsp.buf.outgoing_calls,
364 + add( client_id, map.normal {
365 + description =
'Show references of symbol under cursor.',
368 + keys =
'<leader>ln',
369 + 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,
394 - add( client_id, map.normal {
395 - description =
'Rename symbol under cursor.',
398 - keys = {
'<f2>',
'<leader>lr', },
399 - command = vim.lsp.buf.rename,
372 + add( client_id, map.normal {
373 + description =
'Rename symbol under cursor.',
376 + keys = {
'<f2>',
'<leader>lr' },
377 + command = vim.lsp.buf.rename,
403 381 local lsp_detach = function ( args )
404 - dbg.print(
'DETACH LSP', args )
382 + dbg.print(
'DETACH LSP', args )
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 384 + local bufnr
= args.buf
385 + local client_id
= args.data.client_id
386 + local client
= vim.lsp.get_client_by_id( client_id )
387 + if not client
then return end 411 - if client.server_capabilities.definitionProvider
then 412 - vim.bo[bufnr].tagfunc
= old_tagfunc
389 + if client.server_capabilities.definitionProvider
then 390 + vim.bo[bufnr].tagfunc
= old_tagfunc
415 - if client.server_capabilities.documentFormattingProvider
then 416 - vim.bo[bufnr].formatexpr
= old_formatexpr
393 + if client.server_capabilities.documentFormattingProvider
then 394 + vim.bo[bufnr].formatexpr
= old_formatexpr
419 - if client.server_capabilities.completionProvider
then 420 - vim.bo[bufnr].omnifunc
= old_omnifunc
397 + if client.server_capabilities.completionProvider
then 398 + vim.bo[bufnr].omnifunc
= old_omnifunc
423 - if table.contains( keybinds, client_id )
then 424 - for _, keybind_delete
in ipairs( keybinds[client_id] )
do 401 + if table.contains( keybinds, client_id )
then 402 + for _, keybind_delete
in ipairs( keybinds[client_id] )
do 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,
410 + description =
'Start or reuse LSP client',
411 + events =
'FileType',
412 + command = lsp_start,
415 + description =
'Hook: LSP client attached to buffer',
416 + events =
'LspAttach',
417 + command = lsp_attach,
420 + description =
'Hook: LSP client detached from buffer',
421 + events =
'LspDetach',
422 + command = lsp_detach,
425 + description =
'Semantic Tokens from the LSP',
426 + events =
'LspTokenUpdate',
427 + command = token_update,
453 431 local lsp_info = function ( command )
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 )
432 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0 }
433 + local active_clients
= vim.lsp.get_clients( all_or_current )
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 ) )
435 + local infos
= vim.iter( active_clients )
436 + :map(
function ( client )
437 + local name
= client.name
438 + local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
439 + assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
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,
441 + local full_cmd
= table.deep_copy( client.config.cmd )
442 + full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
446 + cmd =
table.
concat( full_cmd,
' ' ),
447 + workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
449 + filetypes =
table.
concat( config.filetypes,
', ' ),
450 + single_file_support = config.single_file_support,
451 + workspaces = config.workspaces,
479 - ui.show_tree( infos )
457 + ui.show_tree( infos )
482 460 local lsp_info_extended = function ( command )
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 )
461 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0 }
462 + local active_clients
= vim.lsp.get_clients( all_or_current )
463 + ui.show_tree( active_clients )
488 466 user_command.LspInfo
489 467 'Shows basic information about running LSP clients.' 490 - {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
468 + {
nargs =
'?',
complete =
function ()
return {
'all' }
end } (
494 472 user_command.LspInfoExtended
495 473 'Shows detailed information about running LSP clients.' 496 - {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
474 + {
nargs =
'?',
complete =
function ()
return {
'all' }
end } (
504 482 local completion_icons
= {
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,
483 + Class = icon.class,
484 + Color = icon.color,
485 + Constant = icon.constant,
486 + Constructor = icon.constructor,
488 + EnumMember = icon.enum_member,
489 + Field = icon.field,
491 + Folder = icon.folder,
492 + Function = icon[
'function'],
493 + Interface = icon.interface,
494 + Keyword = icon.keyword,
495 + Method = icon.method,
496 + Module = icon.module,
497 + Property = icon.property,
498 + Snippet = icon.snippet,
499 + Struct = icon.struct,
502 + Value = icon.value,
503 + Variable = icon.variable,
528 506 local completion_kinds
= vim.lsp.protocol.CompletionItemKind
529 507 for i, kind
in ipairs( completion_kinds )
do 530 - completion_kinds[i]
= completion_icons[kind]
or kind
508 + completion_kinds[i]
= completion_icons[kind]
or kind
533 511 return setmetatable( _, {} )