7 -local map
= require'std.keymap' 8 -local auto
= require'std.auto' 9 -local ui
= require'bugabinga.ui' 10 -local table = require'std.table' 11 -local ignored
= require'std.ignored' 8 +local map
= require 'std.keymap' 9 +local auto
= require 'std.auto' 10 +local ui
= require 'bugabinga.ui' 11 +local table = require 'std.table' 12 +local ignored
= require 'std.ignored' 13 -local lsp_client_configs
= require'bugabinga.lsp.clients' 14 +local lsp_client_configs
= require 'bugabinga.lsp.clients' 17 -local token_update = function(lsp_client)
18 +local token_update = function ( lsp_client )
18 19 local token
= lsp_client.data.token
19 20 local buffer
= lsp_client.buffer
20 21 local client_id
= lsp_client.data.client_id
21 22 local mutable_variable_highlight
= 'MutableVariable' 23 24 if token.type
== 'variable' and not token.modifiers.readonly
then 24 - vim.lsp.semantic_tokens.highlight_token(token, buffer, client_id, mutable_variable_highlight)
25 + vim.lsp.semantic_tokens.highlight_token( token, buffer, client_id, mutable_variable_highlight )
32 -local lsp_start = function(file_type_event)
33 +local lsp_start = function ( file_type_event )
33 34 local match
= file_type_event.match
35 36 local matches_to_ignore
= ignored.filetypes
36 - if vim.iter(matches_to_ignore):find(match)
then return end 37 + if vim.iter( matches_to_ignore ):find( match )
then return end 40 41 local bufnr
= file_type_event.buf
41 - local buffer_path
= vim.api.nvim_buf_get_name(bufnr)
42 + local buffer_path
= vim.api.nvim_buf_get_name( bufnr )
45 - local potential_client_configs
= vim.iter(lsp_client_configs)
46 - :map(
function(config)
46 + local potential_client_configs
= vim.iter( lsp_client_configs )
47 + :map(
function ( config )
48 49 config = { config,
'table' },
49 - [
'config.name'] = { config.name,
'string'},
50 - [
'config.filetypes']= { config.filetypes, {
'string',
'table'}},
51 - [
'config.command'] = { config.command, {
'string',
'table'}},
50 + [
'config.name'] = { config.name,
'string' },
51 + [
'config.filetypes'] = { config.filetypes, {
'string',
'table' } },
52 + [
'config.command'] = { config.command, {
'string',
'table' } },
52 53 [
'config.environment'] = { config.environment,
'table',
true },
53 - [
'config.root_dir'] = { config.root_dir,
'function',
'string'},
54 - [
'config.single_file_support'] = { config.single_file_support,
'boolean'},
54 + [
'config.root_dir'] = { config.root_dir,
'function',
'string' },
55 + [
'config.single_file_support'] = { config.single_file_support,
'boolean' },
55 56 [
'config.settings'] = { config.settings,
'table',
true },
56 - [
'config.workspaces'] = { config.workspaces,
'boolean'},
57 - [
'config.before_init'] = { config.before_init,
'function',
true},
57 + [
'config.workspaces'] = { config.workspaces,
'boolean' },
58 + [
'config.before_init'] = { config.before_init,
'function',
true },
59 + [
'config.init_options'] = { config.init_options,
'table',
true },
60 + [
'config.capabilities'] = { config.capabilities,
'table',
true },
61 - config.command
= type(config.command)
== 'string' and { config.command }
or config.command
62 - config.filetypes
= type(config.filetypes)
== 'string' and { config.filetypes }
or config.filetypes
64 + config.command
= type( config.command )
== 'string' and { config.command }
or config.command
65 + config.filetypes
= type( config.filetypes )
== 'string' and { config.filetypes }
or config.filetypes
66 + config.capabilities
= config.capabilities
or {}
67 + config.init_options
= config.init_options
or {}
65 - :filter(
function(config)
66 - return vim.iter(config.filetypes):find(match)
71 + :filter(
function ( config )
72 + return vim.iter( config.filetypes ):find( match )
73 - local config
= vim.iter(potential_client_configs):find(
74 - function(_)
return _.root_dir(buffer_path)
~= nil end 79 + local config
= vim.iter( potential_client_configs ):find(
80 + function ( _ )
return _.root_dir( buffer_path )
~= nil end 80 - config
= config
or vim.iter(potential_client_configs):find(
81 - function(_)
return _.single_file_support
end 86 + config
= config
or vim.iter( potential_client_configs ):find(
87 + function ( _ )
return _.single_file_support
end 89 - assert(config,
'a matching LSP client config shoud have been found by now!')
95 + assert( config,
'a matching LSP client config shoud have been found by now!' )
97 + local root_dir
= type(config.root_dir)
== "string" and config.root_dir
or config.root_dir( buffer_path )
98 + local capabilities
= vim.lsp.protocol.make_client_capabilities()
99 + capabilities
= table.extend(
"force", capabilities, config.capabilities)
91 101 local start_config
= {
92 102 cmd = config.command,
93 - cmd_cwd = config.root_dir(buffer_path),
103 + cmd_cwd = root_dir,
107 + capabilities = capabilities,
99 109 settings = config.settings,
111 + init_options = config.init_options,
102 112 name = config.name,
105 - on_error =
function(code,
...) vim.print(
'LSP ERROR', code,
...)
end,
115 + on_error =
function ( code,
... ) vim.print(
'LSP ERROR', code,
... )
end,
106 116 before_init = config.before_init,
111 - flags = {
allow_incremental_sync =
true,
debounce_text_changes =
50,
exit_timeout =
200},
112 - root_dir = config.root_dir(buffer_path),
121 + flags = {
allow_incremental_sync =
true,
debounce_text_changes =
50,
exit_timeout =
200 },
122 + root_dir = root_dir,
115 - local client_id
= vim.lsp.start(start_config, {
125 + local client_id
= vim.lsp.start( start_config, {
126 136 local old_omnifunc
127 137 local old_tagfunc
132 -local lsp_attach = function(args)
139 +local lsp_attach = function ( args )
133 140 local bufnr
= args.buf
134 - local client
= vim.lsp.get_client_by_id(args.data.client_id)
141 + local client
= vim.lsp.get_client_by_id( args.data.client_id )
135 142 if not client
then return end 139 146 if client.server_capabilities.definitionProvider
then 140 147 old_tagfunc
= vim.bo[bufnr].tagfunc
141 - vim.bo[bufnr].tagfunc
= "v:lua.vim.lsp.tagfunc" 148 + vim.bo[bufnr].tagfunc
= 'v:lua.vim.lsp.tagfunc' 144 151 if client.server_capabilities.documentFormattingProvider
then 145 152 old_formatexpr
= vim.bo[bufnr].formatexpr
146 - vim.bo[bufnr].formatexpr
= "v:lua.vim.lsp.formatexpr(#{timeout_ms:50})" 153 + vim.bo[bufnr].formatexpr
= 'v:lua.vim.lsp.formatexpr(#{timeout_ms:50})' 149 156 if client.server_capabilities.completionProvider
then 150 157 old_omnifunc
= vim.bo[bufnr].omnifunc
151 - vim.bo[bufnr].omnifunc
= "v:vim.lsp.omnifunc" 158 + vim.bo[bufnr].omnifunc
= 'v:vim.lsp.omnifunc' 289 295 keys
= '<c-7><c-7>',
290 296 command
= '<cmd>Telescope lsp_signature_help<cr>',
295 -local lsp_detach = function(args)
300 +local lsp_detach = function ( args )
299 303 local bufnr
= args.buf
300 - local client
= vim.lsp.get_client_by_id(args.data.client_id)
304 + local client
= vim.lsp.get_client_by_id( args.data.client_id )
301 305 if not client
then return end 303 307 if client.server_capabilities.definitionProvider
then 312 316 vim.bo[bufnr].omnifunc
= old_omnifunc
341 -local lsp_info = function(command)
345 +local lsp_info = function ( command )
342 346 local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0 }
343 - local active_clients
= vim.lsp.get_clients(all_or_current)
347 + local active_clients
= vim.lsp.get_clients( all_or_current )
345 - local infos
= vim.iter(active_clients)
346 - :map(
function(client)
349 + local infos
= vim.iter( active_clients )
350 + :map(
function ( client )
347 351 local name
= client.name
348 - local config
= vim.iter(lsp_client_configs):find(
function(config)
return config.name
== name
end)
349 - assert(config, (
'How did we not find a config for %s ?!?!' ):format(name))
352 + local config
= vim.iter( lsp_client_configs ):find(
function ( config )
return config.name
== name
end )
353 + assert( config, (
'How did we not find a config for %s ?!?!'):format( name ) )
351 - local full_cmd
= table.deep_copy(client.config.cmd)
352 - full_cmd[
1]
= vim.fn.exepath(full_cmd[
1])
355 + local full_cmd
= table.deep_copy( client.config.cmd )
356 + full_cmd[
1]
= vim.fn.exepath( full_cmd[
1] )
356 - cmd =
table.
concat(full_cmd,
' '),
357 - workspace_folders = vim.iter(client.workspace_folders):map(
function(w)
return vim.fs.normalize(w.name)
end):totable(),
358 - filetypes =
table.
concat(config.filetypes,
', '),
360 + cmd =
table.
concat( full_cmd,
' ' ),
361 + workspace_folders = vim.iter( client.workspace_folders ):map(
function ( w )
return vim.fs.normalize( w.name )
end )
363 + filetypes =
table.
concat( config.filetypes,
', ' ),
359 364 single_file_support = config.single_file_support,
360 365 workspaces = config.workspaces,
366 - ui.show_tree(infos)
371 + ui.show_tree( infos )
369 -local lsp_info_extended = function(command)
374 +local lsp_info_extended = function ( command )
370 375 local all_or_current
= command.args
and command.args
== 'all' and {}
or {
bufnr =
0 }
371 - local active_clients
= vim.lsp.get_clients(all_or_current)
372 - ui.show_tree(active_clients)
376 + local active_clients
= vim.lsp.get_clients( all_or_current )
377 + ui.show_tree( active_clients )
375 -vim.api.nvim_create_user_command (
'LspInfo',
380 +vim.api.nvim_create_user_command(
'LspInfo',
379 - complete =
function()
return {
"all"}
end,
384 + complete =
function ()
return {
'all' }
end,
380 385 desc =
'Shows basic information about running LSP clients.',
383 -vim.api.nvim_create_user_command (
'LspInfoExtended',
388 +vim.api.nvim_create_user_command(
'LspInfoExtended',
384 389 lsp_info_extended,
387 - complete =
function()
return {
"all"}
end,
392 + complete =
function ()
return {
'all' }
end,
388 393 desc =
'Shows detailed information about running LSP clients.',
390 -return setmetatable(_ ,{ })
395 +return setmetatable( _, {} )