11 11 local lsp_client_configs
= require 'bugabinga.lsp.clients' 14 - local token_update = function ( lsp_client )
15 - local token
= lsp_client.data.token
16 - local buffer
= lsp_client.buffer
17 - local client_id
= lsp_client.data.client_id
18 - local mutable_variable_highlight
= 'MutableVariable' 14 +local token_update = function ( lsp_client )
15 + local token
= lsp_client.data.token
16 + local buffer
= lsp_client.buffer
17 + local client_id
= lsp_client.data.client_id
18 + local mutable_variable_highlight
= 'MutableVariable' 20 - if token.type
== 'variable' and not token.modifiers.readonly
then 21 - vim.lsp.semantic_tokens.highlight_token( token, buffer, client_id, mutable_variable_highlight )
20 + if token.type
== 'variable' and not token.modifiers.readonly
then 21 + vim.lsp.semantic_tokens.highlight_token( token, buffer, client_id, mutable_variable_highlight )
30 - local expand_path = function ( path )
31 - if vim.fn.executable( path )
== 1 then 32 - return vim.fn.exepath( path )
30 +local expand_path = function ( path )
31 + if vim.fn.executable( path )
== 1 then 32 + return vim.fn.exepath( path )
38 +local expand_command = function ( command )
39 + vim.validate {
command = { command, {
'string',
'table' } } }
43 + if type( command )
== 'table' then 44 + command[
1]
= expand_path( command[
1] )
38 - local expand_command = function ( command )
39 - vim.validate {
command = { command, {
'string',
'table' } } }
48 + return expand_path( command )
51 +local lsp_start = function ( file_type_event )
43 - if type( command )
== 'table' then 44 - command[
1]
= expand_path( command[
1] )
54 + local match
= file_type_event.match
48 - return expand_path( command )
56 + local matches_to_ignore
= ignored.filetypes
58 + if vim.iter( matches_to_ignore ):find( match )
then return end 51 - local lsp_start = function ( file_type_event )
60 + local bufnr
= file_type_event.buf
61 + local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
54 - local match
= file_type_event.match
56 - local matches_to_ignore
= ignored.filetypes
58 - if vim.iter( matches_to_ignore ):find( match )
then return end 60 - local bufnr
= file_type_event.buf
61 - local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
65 - local potential_client_configs
= vim.iter( lsp_client_configs )
66 - :map(
function ( config )
68 - [
'config'] = { config,
'table' },
69 - [
'config.name'] = { config.name,
'string' },
70 - [
'config.filetypes'] = { config.filetypes, {
'string',
'table' } },
71 - [
'config.command'] = { config.command, {
'string',
'table' } },
72 - [
'config.environment'] = { config.environment,
'table',
true },
73 - [
'config.root_dir'] = { config.root_dir,
'function',
'string' },
74 - [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true },
75 - [
'config.settings'] = { config.settings,
'table',
true },
76 - [
'config.workspaces'] = { config.workspaces,
'boolean',
true },
77 - [
'config.before_init'] = { config.before_init,
'function',
true },
78 - [
'config.init_options'] = { config.init_options,
'table',
true },
79 - [
'config.capabilities'] = { config.capabilities,
'table',
true },
80 - [
'config.custom_start'] = { config.custom_start,
'function',
true },
84 - config.command
= type( config.command )
== 'string' and { expand_command( config.command ) }
or 85 - expand_command( config.command )
86 - config.environment
= config.environment
or {}
87 - config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes }
or config.filetypes
88 - config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
89 - config.workspaces
= config.workspaces
== nil and false or config.workspaces
90 - config.capabilities
= config.capabilities
or {}
91 - config.init_options
= config.init_options
or {}
95 - :filter(
function ( config )
96 - return vim.iter( config.filetypes ):find( match )
102 - if table.is_empty( potential_client_configs )
then 107 - for _, config
in ipairs( potential_client_configs )
do 108 - local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
109 - local capabilities
= vim.lsp.protocol.make_client_capabilities()
110 - local cmp_capabilities
= want
'cmp_nvim_lsp' (
function ( cmp )
111 - return cmp.default_capabilities()
113 - capabilities
= table.extend(
'force', capabilities, cmp_capabilities, config.capabilities )
116 - local start_config
= {
117 - cmd = config.command,
118 - cmd_cwd = root_dir,
122 - capabilities = capabilities,
124 - settings = config.settings,
126 - init_options = config.init_options,
127 - name = config.name,
130 - on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
131 - before_init = config.before_init,
136 - flags = {
allow_incremental_sync =
true,
debounce_text_changes =
250,
exit_timeout =
200 },
137 - root_dir = root_dir,
65 + local potential_client_configs
= vim.iter( lsp_client_configs )
66 + :map(
function ( config )
68 + [
'config'] = { config,
'table' },
69 + [
'config.name'] = { config.name,
'string' },
70 + [
'config.filetypes'] = { config.filetypes, {
'string',
'table' } },
71 + [
'config.command'] = { config.command, {
'string',
'table' } },
72 + [
'config.environment'] = { config.environment,
'table',
true },
73 + [
'config.root_dir'] = { config.root_dir,
'function',
'string' },
74 + [
'config.single_file_support'] = { config.single_file_support,
'boolean',
true },
75 + [
'config.settings'] = { config.settings,
'table',
true },
76 + [
'config.workspaces'] = { config.workspaces,
'boolean',
true },
77 + [
'config.before_init'] = { config.before_init,
'function',
true },
78 + [
'config.init_options'] = { config.init_options,
'table',
true },
79 + [
'config.capabilities'] = { config.capabilities,
'table',
true },
80 + [
'config.custom_start'] = { config.custom_start,
'function',
true },
84 + config.command
= type( config.command )
== 'string' and { expand_command( config.command ) }
or 85 + expand_command( config.command )
86 + config.environment
= config.environment
or {}
87 + config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes }
or config.filetypes
88 + config.single_file_support
= config.single_file_support
== nil and false or config.single_file_support
89 + config.workspaces
= config.workspaces
== nil and false or config.workspaces
90 + config.capabilities
= config.capabilities
or {}
91 + config.init_options
= config.init_options
or {}
140 - local lsp_starter
= config.custom_start
or vim.lsp.start
95 + :filter(
function ( config )
96 + return vim.iter( config.filetypes ):find( match )
144 - lsp_starter( start_config, {
148 - reuse_client =
function ( existing_client, new_config )
150 - local same_name_and_root
= existing_client.name
== new_config.name
and 151 - existing_client.workspace_folders[
1]
== new_config.root_dir;
153 - return same_name_and_root;
102 + if table.is_empty( potential_client_configs )
then 161 - local old_formatexpr
107 + for _, config
in ipairs( potential_client_configs )
do 108 + local root_dir
= type( config.root_dir )
== 'string' and config.root_dir
or config.root_dir( buffer_path )
109 + local capabilities
= vim.lsp.protocol.make_client_capabilities()
110 + local cmp_capabilities
= want
'cmp_nvim_lsp' (
function ( cmp )
111 + return cmp.default_capabilities()
113 + capabilities
= table.extend(
'force', capabilities, cmp_capabilities, config.capabilities )
165 - local lsp_attach = function ( args )
166 - local bufnr
= args.buf
167 - local client
= vim.lsp.get_client_by_id( args.data.client_id )
168 - if not client
then return end 116 + local start_config
= {
117 + cmd = config.command,
118 + cmd_cwd = root_dir,
122 + capabilities = capabilities,
124 + settings = config.settings,
126 + init_options = config.init_options,
127 + name = config.name,
130 + on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
131 + before_init = config.before_init,
136 + flags = {
allow_incremental_sync =
true,
debounce_text_changes =
250,
exit_timeout =
200 },
137 + root_dir = root_dir,
140 + local lsp_starter
= config.custom_start
or vim.lsp.start
172 - if client.server_capabilities.definitionProvider
then 173 - old_tagfunc
= vim.bo[bufnr].tagfunc
174 - vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 177 - if client.server_capabilities.documentFormattingProvider
then 178 - old_formatexpr
= vim.bo[bufnr].formatexpr
179 - vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr(#{timeout_ms:50})' 144 + lsp_starter( start_config, {
182 - if client.server_capabilities.completionProvider
then 183 - old_omnifunc
= vim.bo[bufnr].omnifunc
184 - vim.bo[bufnr].omnifunc
= 'v:vim.lsp.omnifunc' 161 +local old_formatexpr
196 - description =
'Show available code actions on current line.',
199 - command = vim.lsp.buf.code_action,
166 +local add = function ( keybind )
167 + table.
insert( keybinds, keybind )
203 - description =
'Goto to definition of symbol under cursor.',
206 - command = vim.lsp.buf.definition,
209 - description =
'Goto to definition of symbol under cursor.',
210 - category =
'telescope',
211 - keys =
'<c-2><c-2>',
212 - command =
'<cmd>Telescope lsp_definitions<cr>',
170 +local lsp_attach = function ( args )
171 + local bufnr
= args.buf
172 + local client
= vim.lsp.get_client_by_id( args.data.client_id )
173 + if not client
then return end 177 + if client.server_capabilities.definitionProvider
then 178 + old_tagfunc
= vim.bo[bufnr].tagfunc
179 + vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 182 + if client.server_capabilities.documentFormattingProvider
then 183 + old_formatexpr
= vim.bo[bufnr].formatexpr
184 + vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr(#{timeout_ms:50})' 187 + if client.server_capabilities.completionProvider
then 188 + old_omnifunc
= vim.bo[bufnr].omnifunc
189 + vim.bo[bufnr].omnifunc
= 'v:vim.lsp.omnifunc' 215 192 if client.server_capabilities.documentHighlightProvider
then 238 220 description =
'Format current buffer',
239 221 category =
'lsp',
241 225 command = vim.lsp.buf.format,
245 229 description =
'Show hover documentation above cursor.',
246 230 category =
'lsp',
232 + keys = {
'K',
'<leader>lk' },
248 233 command = vim.lsp.buf.hover,
237 + description =
'Show signature help under cursor.',
240 + keys =
'<leader>ls',
241 + command = vim.lsp.buf.signature_help,
245 + description =
'Show available code actions on current line.',
248 + keys =
'<leader>la',
249 + command = vim.lsp.buf.code_action,
253 + description =
'Goto to definition of symbol under cursor.',
256 + keys =
'<leader>ld',
257 + command = vim.lsp.buf.definition,
252 261 description =
'Show implementations of symbol under cursor.',
253 262 category =
'lsp',
264 + keys =
'<leader>li',
255 265 command = vim.lsp.buf.implementation,
258 - description =
'Show implementations of symbol under cursor.',
259 - category =
'telescope',
260 - keys =
'<c-4><c-4>',
261 - command =
'<cmd>Telescope lsp_implementations<cr>',
265 269 description =
'Show incoming calls of symbol under cursor.',
266 270 category =
'lsp',
272 + keys =
'<leader>lci',
268 273 command = vim.lsp.buf.incoming_calls,
271 - description =
'Show incoming calls of symbol under cursor.',
272 - category =
'telescope',
273 - keys =
'<c-5><c-5>',
274 - command =
'<cmd>Telescope lsp_incoming_calls<cr>',
277 277 description =
'Show outgoing calls of symbol under cursor.',
278 278 category =
'lsp',
280 + keys =
'<leader>lco',
280 281 command = vim.lsp.buf.outgoing_calls,
283 - description =
'Show outgoing calls of symbol under cursor.',
284 - category =
'telescope',
285 - keys =
'<c-s-5><c-s-5>',
286 - command =
'<cmd>Telescope lsp_outgoing_calls<cr>',
290 285 description =
'Show references of symbol under cursor.',
291 286 category =
'lsp',
288 + keys =
'<leader>lr',
293 289 command = vim.lsp.buf.references,
296 - description =
'Show references of symbol under cursor.',
297 - category =
'telescope',
298 - keys =
'<c-6><c-6>',
299 - command = vim.lsp.buf.references,
303 293 description =
'Rename symbol under cursor.',
304 294 category =
'lsp',
296 + keys = {
'<f2>',
'<leader>ln' },
306 297 command = vim.lsp.buf.rename,
310 - description =
'Show signature help under cursor.',
313 - command = vim.lsp.buf.signature_help,
317 - description =
'Show signature help under cursor.',
318 - category =
'telescope',
319 - keys =
'<c-s-0><c-s-0>',
320 - command =
'<cmd>Telescope lsp_signature_help<cr>',
324 301 local lsp_detach = function ( args )
339 316 if client.server_capabilities.completionProvider
then 340 317 vim.bo[bufnr].omnifunc
= old_omnifunc
320 + for _, keybind_delete
in ipairs(keybinds)
do 411 393 desc
= 'Shows detailed information about running LSP clients.',
414 -return setmetatable( _, {} )
396 +return setmetatable( _, {} )