1 1 local debug = require 'std.debug' 2 +local icon
= require 'std.icon' 2 3 local defer
= require 'std.defer' 3 4 local map
= require 'std.map' 4 5 local auto
= require 'std.auto' 5 6 local ui
= require 'bugabinga.ui' 6 7 local table = require 'std.table' 7 8 local ignored
= require 'std.ignored' 8 -local user_command
= vim.api.nvim_create_user_command
9 +local user_command
= require 'std.user_command' 9 10 local lsp_client_configs
= require 'bugabinga.lsp.clients' 10 11 local localrc
= require 'std.localrc' 14 15 require 'bugabinga.lsp.lightbulb' 16 17 local token_update = function ( lsp_client )
17 - local token
= lsp_client.data.token
18 - local buffer
= lsp_client.buffer
19 - local client_id
= lsp_client.data.client_id
20 - 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' 22 - if token.type
== 'variable' and not token.modifiers.readonly
then 23 - 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 )
32 33 local expand_path = function ( path )
33 - if vim.fn.executable( path )
== 1 then 34 - return vim.fn.exepath( path )
34 + if vim.fn.executable( path )
== 1 then 35 + return vim.fn.exepath( path )
40 41 local expand_command = function ( command )
41 - vim.validate {
command = { command, {
'string',
'table', }, }, }
42 + vim.validate {
command = { command, {
'string',
'table', }, }, }
43 - if type( command )
== 'table' then 44 - command[
1]
= expand_path( command[
1] )
44 + if type( command )
== 'table' then 45 + command[
1]
= expand_path( command[
1] )
48 - return expand_path( command )
49 + return expand_path( command )
51 52 local lsp_start = function ( file_type_event )
52 - debug.print
'trying to start lsp' 53 - local match
= file_type_event.match
53 + debug.print
'trying to start lsp' 54 + local match
= file_type_event.match
55 - debug.print(
'filetypes to ignore', ignored.filetypes,
'current filetype', match )
56 - if vim.iter( ignored.filetypes ):find( match )
then return end 56 + debug.print(
'filetypes to ignore', ignored.filetypes,
'current filetype', match )
57 + if vim.iter( ignored.filetypes ):find( match )
then return end 58 - local bufnr
= file_type_event.buf
59 - local buftype
= vim.api.nvim_get_option_value(
'buftype', {
buf = bufnr, } )
60 - debug.print(
'buftypes to ignore', ignored.buftypes,
'current buftype', buftype )
61 - 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 + debug.print(
'buftypes to ignore', ignored.buftypes,
'current buftype', buftype )
62 + if vim.iter( ignored.buftypes ):find( buftype )
then return end 63 - local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
64 + local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
65 - debug.print(
string.
format(
'searching lsp client for: match: %s, buffer: %s, path: %s', match, bufnr, buffer_path ) )
66 + debug.print(
string.
format(
'searching lsp client for: match: %s, buffer: %s, path: %s', match, bufnr, buffer_path ) )
67 - local potential_client_configs
= vim.iter( lsp_client_configs )
68 - :map(
function ( config )
70 - [
'config'] = { config,
'table', },
71 - [
'config.name'] = { config.name,
'string', },
72 - [
'config.filetypes'] = { config.filetypes, {
'string',
'table', }, },
73 - [
'config.command'] = { config.command, {
'string',
'table', }, },
74 - [
'config.environment'] = { config.environment,
'table',
true, },
75 - [
'config.root_dir'] = { config.root_dir,
'function',
'string', },
76 - [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true, },
77 - [
'config.settings'] = { config.settings,
'table',
true, },
78 - [
'config.workspaces'] = { config.workspaces,
'boolean',
true, },
79 - [
'config.before_init'] = { config.before_init,
'function',
true, },
80 - [
'config.init_options'] = { config.init_options,
'table',
true, },
81 - [
'config.capabilities'] = { config.capabilities,
'table',
true, },
82 - [
'config.custom_start'] = { config.custom_start,
'function',
true, },
86 - config.command
= type( config.command )
== 'string' and { expand_command( config.command ), }
or 87 - expand_command( config.command )
88 - config.environment
= config.environment
or {}
89 - config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes, }
or config.filetypes
90 - config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
91 - config.workspaces
= config.workspaces
== nil and false or config.workspaces
92 - config.capabilities
= config.capabilities
or {}
93 - 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 {}
97 - :filter(
function ( config )
98 - return vim.iter( config.filetypes ):find( match )
98 + :filter(
function ( config )
99 + return vim.iter( config.filetypes ):find( match )
102 - debug.print(
'POTENTIAL CLIENTS',
103 - vim.iter( potential_client_configs ):map(
function ( config )
105 - name = config.name,
103 + debug.print(
'POTENTIAL CLIENTS',
104 + vim.iter( potential_client_configs ):map(
function ( config )
106 + name = config.name,
112 - if table.is_empty( potential_client_configs )
then 113 - debug.print(
'found no lsp client for', buffer_path )
113 + if table.is_empty( potential_client_configs )
then 114 + debug.print(
'found no lsp client for', buffer_path )
120 + local project_local_lsp_settings
= localrc(
'.lsp.settings.lua',
'table' )
or {}
122 - local project_local_lsp_settings
= localrc(
'.lsp.settings.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 _, config
in ipairs( potential_client_configs )
do 125 - local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
126 - local capabilities
= vim.lsp.protocol.make_client_capabilities()
127 - capabilities
= table.extend(
'force', capabilities, config.capabilities )
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 settings
= config.settings
130 - local settings_override
= project_local_lsp_settings[config.name]
131 - if settings_override
then 132 - debug.print(
'overriding settings with project local settings', settings, settings_override )
133 - settings
= vim.tbl_deep_extend(
'force', settings, settings_override )
134 + debug.print(
'starting command:', config.command )
136 - debug.print(
'starting command:', config.command )
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, },
138 - local start_config
= {
139 - cmd = config.command,
140 - cmd_cwd = root_dir,
143 - root_dir = root_dir,
145 - capabilities = capabilities,
147 - settings = settings,
149 - init_options = config.init_options,
150 - name = config.name,
153 - on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
154 - before_init = config.before_init,
156 - on_exit =
function ( code, signal, client_id )
debug.print(
'LSP CLIENT EXIT', code, signal, client_id )
end,
157 - on_attach =
function ( client, attach_bufnr )
debug.print(
'LSP CLIENT ATTACH', client, attach_bufnr )
end,
158 - trace =
debug.get()
and 'on' or 'off',
159 - flags = {
allow_incremental_sync =
true,
debounce_text_changes =
250,
exit_timeout =
200, },
160 + local lsp_starter
= config.custom_start
or vim.lsp.start
162 - local lsp_starter
= config.custom_start
or vim.lsp.start
162 + debug.print(
'starting lsp', start_config.name, root_dir )
164 - debug.print(
'starting lsp', start_config.name, root_dir )
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
166 - lsp_starter( start_config, {
170 - reuse_client =
function ( existing_client, new_config )
172 - 'lsp resuse client',
173 - existing_client.name,
174 - existing_client.workspace_folders,
176 - new_config.root_dir
178 + local same_name
= existing_client.name
== new_config.name
180 - local same_name
= existing_client.name
== new_config.name
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 182 - local new_root_raw
= new_config.root_dir
or nil 183 - local existing_root_raw
= existing_client.workspace_folders
and #existing_client.workspace_folders
>= 1 and 184 - existing_client.workspace_folders[
1].name
or nil 184 + if not (new_root_raw
and existing_root_raw)
then return false end 186 - if not (new_root_raw
and existing_root_raw)
then return false end 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
188 - local new_root
= vim.fs.normalize( new_root_raw )
189 - local existing_root
= vim.fs.normalize( existing_root_raw )
190 - local same_root
= new_root
== existing_root
190 + local reuse
= same_name
and same_root
191 + debug.print(
'reusing lsp client?', reuse )
192 - local reuse
= same_name
and same_root
193 - debug.print(
'reusing lsp client?', reuse )
198 - debug.print(
'ATTACHING LSP CLIENT', config.name )
196 + debug.print(
'ATTACHING LSP CLIENT', config.name )
202 200 local old_formatexpr
206 204 local keybinds
= {}
207 205 local add = function ( client_id, keybind_remover )
209 - client_id = { client_id,
'number', },
210 - keybind_remover = { keybind_remover,
'function', },
212 - if not table.contains( keybinds, client_id )
then 213 - keybinds[client_id]
= {}
215 - table.
insert( keybinds[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 )
218 216 local lsp_attach = function ( args )
219 - local bufnr
= args.buf
220 - local client_id
= args.data.client_id
221 - local client
= vim.lsp.get_client_by_id( client_id )
222 - if not client
then return end 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 224 - debug.print( client.server_capabilities )
222 + debug.print( client.server_capabilities )
226 - if client.server_capabilities.definitionProvider
then 227 - old_tagfunc
= vim.bo[bufnr].tagfunc
228 - vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 224 + if client.server_capabilities.definitionProvider
then 225 + old_tagfunc
= vim.bo[bufnr].tagfunc
226 + vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 231 - if client.server_capabilities.documentFormattingProvider
then 232 - old_formatexpr
= vim.bo[bufnr].formatexpr
233 - vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr' 229 + if client.server_capabilities.documentFormattingProvider
then 230 + old_formatexpr
= vim.bo[bufnr].formatexpr
231 + vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr' 236 - if client.server_capabilities.completionProvider
then 237 - old_omnifunc
= vim.bo[bufnr].omnifunc
238 - vim.bo[bufnr].omnifunc
= 'v:lua.vim.lsp.omnifunc' 234 + if client.server_capabilities.completionProvider
then 235 + old_omnifunc
= vim.bo[bufnr].omnifunc
236 + vim.bo[bufnr].omnifunc
= 'v:lua.vim.lsp.omnifunc' 241 - if client.server_capabilities.documentSymbolProvider
then 242 - local navic_ok, navic
= pcall(
require,
'nvim-navic' )
244 - navic.attach( client, bufnr )
246 - vim.notify
'nvim-navic not found. could not attach to lsp client.' 248 - local navbuddy_ok, navbuddy
= pcall(
require,
'nvim-navbuddy' )
249 - if navbuddy_ok
then 250 - navbuddy.attach( client, bufnr )
252 - description =
'Open overview of symbols in current buffer',
254 - keys =
'<leader>lo',
255 - command =
function () navbuddy.open( bufnr )
end,
259 - vim.notify
'nvim-navbuddy not found. could not attach to lsp client.' 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.' 263 - local lsp_signature_ok, lsp_signature
= pcall(
require,
'lsp_signature' )
264 - if lsp_signature_ok
then 265 - lsp_signature.on_attach( {}, bufnr )
261 + local lsp_signature_ok, lsp_signature
= pcall(
require,
'lsp_signature' )
262 + if lsp_signature_ok
then 263 + lsp_signature.on_attach( {}, bufnr )
268 - if client.server_capabilities.documentHighlightProvider
then 271 - local debounced_highlight
= defer.debounce_leading( vim.lsp.buf.document_highlight, delay )
272 - local debounced_clear
= defer.debounce_leading( vim.lsp.buf.clear_references, delay )
266 + if client.server_capabilities.documentHighlightProvider
then 269 + local debounced_highlight
= defer.debounce_leading( vim.lsp.buf.document_highlight, delay )
270 + local debounced_clear
= defer.debounce_leading( vim.lsp.buf.clear_references, delay )
274 - auto
'document_highlight' {
276 - description =
'Highlight symbol under cursor on hold',
277 - events =
'CursorHold',
279 - command = debounced_highlight,
282 - description =
'Remove highlight from symbol under cursor on move',
283 - events = {
'CursorMoved',
'InsertEnter', },
285 - command = debounced_clear,
272 + auto
'document_highlight' {
274 + description =
'Highlight symbol under cursor on hold',
275 + events =
'CursorHold',
277 + command = debounced_highlight,
280 + description =
'Remove highlight from symbol under cursor on move',
281 + events = {
'CursorMoved',
'InsertEnter', },
283 + command = debounced_clear,
290 - if client.server_capabilities.inlayHintProvider
then 291 - add( client_id, map.normal {
292 - description =
'Toggle inlay hints',
295 - keys =
'<leader>ti',
296 - command =
function ()
297 - vim.lsp.inlay_hint.enable( bufnr,
nil )
288 + if client.server_capabilities.inlayHintProvider
then 289 + add( client_id, map.normal {
290 + description =
'Toggle inlay hints',
293 + keys =
'<leader>ti',
294 + command =
function ()
295 + vim.lsp.inlay_hint.enable( bufnr,
nil )
302 - add( client_id, map.normal {
303 - description =
'Show hover documentation above cursor.',
306 - keys = {
'K',
'<leader>lk', },
307 - command = vim.lsp.buf.hover,
300 + add( client_id, map.normal {
301 + description =
'Show hover documentation above cursor.',
304 + keys = {
'K',
'<leader>lk', },
305 + command = vim.lsp.buf.hover,
310 - add( client_id, map.normal {
311 - description =
'Show signature help under cursor.',
314 - keys = {
'H',
'<leader>ls', },
315 - command = vim.lsp.buf.signature_help,
308 + add( client_id, map.normal {
309 + description =
'Show signature help under cursor.',
312 + keys = {
'H',
'<leader>ls', },
313 + command = vim.lsp.buf.signature_help,
318 - add( client_id, map.normal {
319 - description =
'Show available code actions on current line.',
322 - keys =
'<leader>la',
323 - command = vim.lsp.buf.code_action,
316 + add( client_id, map.normal {
317 + description =
'Show available code actions on current line.',
320 + keys =
'<leader>la',
321 + command = vim.lsp.buf.code_action,
326 - add( client_id, map.normal {
327 - description =
'Goto to definition of symbol under cursor.',
330 - keys =
'<leader>ld',
331 - command = vim.lsp.buf.definition,
324 + add( client_id, map.normal {
325 + description =
'Goto to definition of symbol under cursor.',
328 + keys =
'<leader>ld',
329 + command = vim.lsp.buf.definition,
334 - add( client_id, map.normal {
335 - description =
'Show implementations of symbol under cursor.',
338 - keys =
'<leader>li',
339 - command = vim.lsp.buf.implementation,
332 + add( client_id, map.normal {
333 + description =
'Show implementations of symbol under cursor.',
336 + keys =
'<leader>li',
337 + command = vim.lsp.buf.implementation,
342 - add( client_id, map.normal {
343 - description =
'Show incoming calls of symbol under cursor.',
346 - keys =
'<leader>lci',
347 - command = vim.lsp.buf.incoming_calls,
340 + add( client_id, map.normal {
341 + description =
'Show incoming calls of symbol under cursor.',
344 + keys =
'<leader>lci',
345 + command = vim.lsp.buf.incoming_calls,
350 - add( client_id, map.normal {
351 - description =
'Show outgoing calls of symbol under cursor.',
354 - keys =
'<leader>lco',
355 - command = vim.lsp.buf.outgoing_calls,
348 + add( client_id, map.normal {
349 + description =
'Show outgoing calls of symbol under cursor.',
352 + keys =
'<leader>lco',
353 + command = vim.lsp.buf.outgoing_calls,
358 - add( client_id, map.normal {
359 - description =
'Show references of symbol under cursor.',
362 - keys =
'<leader>ln',
363 - command = vim.lsp.buf.references,
356 + add( client_id, map.normal {
357 + description =
'Show references of symbol under cursor.',
360 + keys =
'<leader>ln',
361 + command = vim.lsp.buf.references,
366 - add( client_id, map.normal {
367 - description =
'Rename symbol under cursor.',
370 - keys = {
'<f2>',
'<leader>lr', },
371 - command = vim.lsp.buf.rename,
364 + add( client_id, map.normal {
365 + description =
'Rename symbol under cursor.',
368 + keys = {
'<f2>',
'<leader>lr', },
369 + command = vim.lsp.buf.rename,
375 373 local lsp_detach = function ( args )
376 - debug.print(
'DETACH LSP', args )
374 + debug.print(
'DETACH LSP', args )
378 - local bufnr
= args.buf
379 - local client_id
= args.data.client_id
380 - local client
= vim.lsp.get_client_by_id( client_id )
381 - if not client
then return end 376 + local bufnr
= args.buf
377 + local client_id
= args.data.client_id
378 + local client
= vim.lsp.get_client_by_id( client_id )
379 + if not client
then return end 383 - if client.server_capabilities.definitionProvider
then 384 - vim.bo[bufnr].tagfunc
= old_tagfunc
381 + if client.server_capabilities.definitionProvider
then 382 + vim.bo[bufnr].tagfunc
= old_tagfunc
387 - if client.server_capabilities.documentFormattingProvider
then 388 - vim.bo[bufnr].formatexpr
= old_formatexpr
385 + if client.server_capabilities.documentFormattingProvider
then 386 + vim.bo[bufnr].formatexpr
= old_formatexpr
391 - if client.server_capabilities.completionProvider
then 392 - vim.bo[bufnr].omnifunc
= old_omnifunc
389 + if client.server_capabilities.completionProvider
then 390 + vim.bo[bufnr].omnifunc
= old_omnifunc
395 - if table.contains( keybinds, client_id )
then 396 - for _, keybind_delete
in ipairs( keybinds[client_id] )
do 393 + if table.contains( keybinds, client_id )
then 394 + for _, keybind_delete
in ipairs( keybinds[client_id] )
do 404 - description =
'Start or reuse LSP client',
405 - events =
'FileType',
406 - command = lsp_start,
409 - description =
'Hook: LSP client attached to buffer',
410 - events =
'LspAttach',
411 - command = lsp_attach,
414 - description =
'Hook: LSP client detached from buffer',
415 - events =
'LspDetach',
416 - command = lsp_detach,
419 - description =
'Semantic Tokens from the LSP',
420 - events =
'LspTokenUpdate',
421 - command = token_update,
402 + description =
'Start or reuse LSP client',
403 + events =
'FileType',
404 + command = lsp_start,
407 + description =
'Hook: LSP client attached to buffer',
408 + events =
'LspAttach',
409 + command = lsp_attach,
412 + description =
'Hook: LSP client detached from buffer',
413 + events =
'LspDetach',
414 + command = lsp_detach,
417 + description =
'Semantic Tokens from the LSP',
418 + events =
'LspTokenUpdate',
419 + command = token_update,
425 423 local lsp_info = function ( command )
426 - local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
427 - local active_clients
= vim.lsp.get_clients( all_or_current )
424 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
425 + local active_clients
= vim.lsp.get_clients( all_or_current )
429 - local infos
= vim.iter( active_clients )
430 - :map(
function ( client )
431 - local name
= client.name
432 - local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
433 - assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
427 + local infos
= vim.iter( active_clients )
428 + :map(
function ( client )
429 + local name
= client.name
430 + local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
431 + assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
435 - local full_cmd
= table.deep_copy( client.config.cmd )
436 - full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
440 - cmd =
table.
concat( full_cmd,
' ' ),
441 - workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
443 - filetypes =
table.
concat( config.filetypes,
', ' ),
444 - single_file_support = config.single_file_support,
445 - workspaces = config.workspaces,
433 + local full_cmd
= table.deep_copy( client.config.cmd )
434 + full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
438 + cmd =
table.
concat( full_cmd,
' ' ),
439 + workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
441 + filetypes =
table.
concat( config.filetypes,
', ' ),
442 + single_file_support = config.single_file_support,
443 + workspaces = config.workspaces,
451 - ui.show_tree( infos )
449 + ui.show_tree( infos )
454 452 local lsp_info_extended = function ( command )
455 - local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
456 - local active_clients
= vim.lsp.get_clients( all_or_current )
457 - ui.show_tree( active_clients )
453 + local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0, }
454 + local active_clients
= vim.lsp.get_clients( all_or_current )
455 + ui.show_tree( active_clients )
460 -user_command(
'LspInfo', lsp_info, {
462 - complete =
function ()
return {
'all', }
end,
463 - desc =
'Shows basic information about running LSP clients.',
458 +user_command.LspInfo
459 +'Shows basic information about running LSP clients.' 460 + {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
466 -user_command(
'LspInfoExtended', lsp_info_extended, {
468 - complete =
function ()
return {
'all', }
end,
469 - desc =
'Shows detailed information about running LSP clients.',
464 +user_command.LspInfoExtended
465 +'Shows detailed information about running LSP clients.' 466 + {
nargs =
'?',
complete =
function ()
return {
'all', }
end, } (
475 474 local completion_icons
= {
479 - Constructor =
' ',
475 + Class = icon.class,
476 + Color = icon.color,
477 + Constant = icon.constant,
478 + Constructor = icon.constructor,
480 + EnumMember = icon.enum_member,
481 + Field = icon.field,
483 + Folder = icon.folder,
484 + Function = icon[
'function'],
485 + Interface = icon.interface,
486 + Keyword = icon.keyword,
487 + Method = icon.method,
488 + Module = icon.module,
489 + Property = icon.property,
490 + Snippet = icon.snippet,
491 + Struct = icon.struct,
494 + Value = icon.value,
495 + Variable = icon.variable,
499 498 local completion_kinds
= vim.lsp.protocol.CompletionItemKind
500 499 for i, kind
in ipairs( completion_kinds )
do 501 - completion_kinds[i]
= completion_icons[kind]
or kind
500 + completion_kinds[i]
= completion_icons[kind]
or kind
504 503 return setmetatable( _, {} )