1 +local defer
= require'std.defer' 7 2 local map
= require 'std.keymap' 8 3 local auto
= require 'std.auto' 9 4 local ui
= require 'bugabinga.ui' 10 5 local table = require 'std.table' 11 6 local ignored
= require 'std.ignored' 7 +local user_command
= vim.api.nvim_create_user_command
13 8 local lsp_client_configs
= require 'bugabinga.lsp.clients' 17 11 local token_update = function ( lsp_client )
33 -local expand_path = function(path)
34 - if vim.fn.executable(path)
== 1 then 35 - return vim.fn.exepath(path)
27 +local expand_path = function ( path )
28 + if vim.fn.executable( path )
== 1 then 29 + return vim.fn.exepath( path )
41 -local expand_command = function(command)
42 - vim.validate{
command = { command, {
'string',
'table' } }}
35 +local expand_command = function ( command )
36 + vim.validate {
command = { command, {
'string',
'table' } } }
44 - if type(command)
== 'table' then 45 - command[
1]
= expand_path(command[
1])
40 + if type( command )
== 'table' then 41 + command[
1]
= expand_path( command[
1] )
49 - return expand_path(command)
45 + return expand_path( command )
52 48 local lsp_start = function ( file_type_event )
53 51 local match
= file_type_event.match
55 53 local matches_to_ignore
= ignored.filetypes
56 55 if vim.iter( matches_to_ignore ):find( match )
then return end 60 57 local bufnr
= file_type_event.buf
61 58 local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
65 62 local potential_client_configs
= vim.iter( lsp_client_configs )
66 63 :map(
function ( config )
68 - config = { config,
'table' },
65 + [
'config'] = { config,
'table' },
69 66 [
'config.name'] = { config.name,
'string' },
70 67 [
'config.filetypes'] = { config.filetypes, {
'string',
'table' } },
71 68 [
'config.command'] = { config.command, {
'string',
'table' } },
72 69 [
'config.environment'] = { config.environment,
'table',
true },
73 70 [
'config.root_dir'] = { config.root_dir,
'function',
'string' },
74 - [
'config.single_file_support'] = { config.single_file_support,
'boolean' },
71 + [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true },
75 72 [
'config.settings'] = { config.settings,
'table',
true },
76 - [
'config.workspaces'] = { config.workspaces,
'boolean' },
73 + [
'config.workspaces'] = { config.workspaces,
'boolean',
true },
77 74 [
'config.before_init'] = { config.before_init,
'function',
true },
78 75 [
'config.init_options'] = { config.init_options,
'table',
true },
79 76 [
'config.capabilities'] = { config.capabilities,
'table',
true },
77 + [
'config.custom_start'] = { config.custom_start,
'function',
true },
83 - config.command
= type( config.command )
== 'string' and { expand_command(config.command) }
or expand_command(config.command)
81 + config.command
= type( config.command )
== 'string' and { expand_command( config.command ) }
or 82 + expand_command( config.command )
83 + config.environment
= config.environment
or {}
84 84 config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes }
or config.filetypes
85 + config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
86 + config.workspaces
= config.workspaces
== nil and false or config.workspaces
85 87 config.capabilities
= config.capabilities
or {}
86 88 config.init_options
= config.init_options
or {}
98 100 local config
= vim.iter( potential_client_configs ):find(
109 111 if not config
then 110 - vim.print(
'FOUND NO LSP CLIENT FOR', buffer_path)
114 116 assert( config,
'a matching LSP client config shoud have been found by now!' )
116 - local root_dir
= type(config.root_dir)
== "string" and config.root_dir
or config.root_dir( buffer_path )
118 + local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
117 119 local capabilities
= vim.lsp.protocol.make_client_capabilities()
118 - capabilities
= table.extend(
"force", capabilities, config.capabilities)
120 + capabilities
= table.extend(
'force', capabilities, config.capabilities )
120 122 local start_config
= {
121 123 cmd = config.command,
141 143 root_dir
= root_dir,
144 - local client_id
= vim.lsp.start( start_config, {
146 + local lsp_starter
= config.custom_start
or vim.lsp.start
148 + local client_id
= lsp_starter( start_config, {
151 - vim.print(
"ATTACHING LSP CLIENT", client_id)
154 158 local old_formatexpr
203 207 if client.server_capabilities.documentHighlightProvider
then 210 + local debounced_highlight
= defer.debounce_trailing(vim.lsp.buf.document_highlight, delay)
211 + local debounced_clear
= defer.debounce_trailing(vim.lsp.buf.clear_references, delay)
204 213 auto
'document_highlight' {
206 215 description =
'Highlight symbol under cursor on hold',
207 216 events =
'CursorHold',
208 - pattern =
'<buffer>',
209 - command = vim.lsp.buf.document_highlight,
218 + command = debounced_highlight,
213 221 description =
'Remove highlight from symbol under cursor on move',
214 222 events = {
'CursorMoved',
'InsertEnter' },
215 - pattern =
'<buffer>',
216 - command = vim.lsp.buf.clear_references,
224 + command = debounced_clear,
234 242 name =
'Format current buffer',
235 243 category =
'lsp',
237 245 command = vim.lsp.buf.format,
241 249 name =
'Show hover documentation above cursor.',
242 250 category =
'lsp',
244 252 command = vim.lsp.buf.hover,
299 307 name =
'Rename symbol under cursor.',
300 308 category =
'lsp',
302 310 command = vim.lsp.buf.rename,
306 314 name =
'Show signature help under cursor.',
307 315 category =
'lsp',
309 317 command = vim.lsp.buf.signature_help,
313 321 name =
'Show signature help under cursor.',
314 322 category =
'telescope',
315 - keys =
'<c-7><c-7>',
323 + keys =
'<c-s-0><c-s-0>',
316 324 command =
'<cmd>Telescope lsp_signature_help<cr>',
363 371 local lsp_info = function ( command )
364 372 local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0 }
365 - local active_clients
= vim.lsp.get_clients( all_or_current )
373 + local active_clients
= vim.lsp.get_active_clients( all_or_current )
367 375 local infos
= vim.iter( active_clients )
368 376 :map(
function ( client )
395 403 ui.show_tree( active_clients )
398 -vim.api.nvim_create_user_command(
'LspInfo',
402 - complete =
function ()
return {
'all' }
end,
403 - desc =
'Shows basic information about running LSP clients.',
406 +user_command(
'LspInfo', lsp_info, {
408 + complete =
function ()
return {
'all' }
end,
409 + desc =
'Shows basic information about running LSP clients.',
412 +user_command(
'LspInfoExtended', lsp_info_extended, {
414 + complete =
function ()
return {
'all' }
end,
415 + desc =
'Shows detailed information about running LSP clients.',
406 -vim.api.nvim_create_user_command(
'LspInfoExtended',
410 - complete =
function ()
return {
'all' }
end,
411 - desc =
'Shows detailed information about running LSP clients.',
413 418 return setmetatable( _, {} )