1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
local lsp = require('lspconfig')
local nnoremap = require('astronauta.keymap').nnoremap
local spinner_lsp= require('spinner.lsp')
require('lspconfig/configs').zk = {
default_config = {
cmd = {'zk', 'lsp'},
filetypes = {'markdown'},
root_dir = function()
return vim.loop.cwd()
end,
settings = {},
}
}
local my_attach = function(client, bufnr)
spinner_lsp.on_attach(client, bufnr)
if client.resolved_capabilities.goto_definition then
nnoremap { '<C-]>' , vim.lsp.buf.definition }
nnoremap { 'gd' , vim.lsp.buf.definition }
nnoremap { 'gR' , vim.lsp.buf.references }
end
if client.resolved_capabilities.hover then
nnoremap { 'K' , vim.lsp.buf.hover }
end
if client.resolved_capabilities.rename then
nnoremap { 'grr' , vim.lsp.buf.rename }
end
if client.resolved_capabilities.signature_help then
nnoremap { '<c-h>' , vim.lsp.buf.signature_help }
-- nnoremap <silent> ;s <cmd> lua vim.lsp.buf.signature_help()<CR>
end
if client.resolved_capabilities.document_formatting then
nnoremap { '<leader>f' , vim.lsp.buf.formatting_sync }
end
if client.resolved_capabilities.type_definition then
nnoremap { 'gT' , vim.lsp.buf.type_definition }
end
if client.resolved_capabilities.declaration then
nnoremap { 'gD' , vim.lsp.buf.declaration }
end
if client.resolved_capabilities.implementation then
nnoremap { 'gI' , vim.lsp.buf.implementation }
end
if client.resolved_capabilities.workspace_symbol then
nnoremap { 'gW' , vim.lsp.buf.workspace_symbol }
end
-- if client.resolved_capabilities.document_symbol then
-- nnoremap { 'g0', vim.lsp.buf.document_symbol }
-- end
nnoremap { ']d' , vim.lsp.diagnostic.goto_next }
nnoremap { '[d' , vim.lsp.diagnostic.goto_prev }
nnoremap { '<leader>d' , vim.lsp.diagnostic.show_line_diagnostics }
augroup {
lsp_user = {
{'BufWritePre' , '*' , 'lua vim.lsp.buf.formatting_seq_sync(nil, 1000)'},
{'BufWritePre' , '*.go' , 'lua vim.lsp.buf.code_action({ only = {"source.organizeImports"} })'},
-- {'CursorHold' , '*' , 'lua vim.lsp.diagnostic.show_line_diagnostics()'},
}
}
end
local setup = function()
local caps = vim.lsp.protocol.make_client_capabilities()
-- enable lsp-based snippets
caps.textDocument.completion.completionItem.snippetSupport = true
caps.textDocument.completion.completionItem.resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
}
}
spinner_lsp.setup()
spinner_lsp.init_capabilities(caps)
-- handler overwrites
-- configure builtin diagnositics
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with( -- {{{
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false,
signs = true,
underline = true,
update_in_insert = false,
}
)
-- }}}
-- overwrite codeAction handler to not ask for confirmation if only a single
-- action is given
vim.lsp.handlers['textDocument/codeAction'] = function(_, _, actions) -- {{{
if actions == nil or vim.tbl_isempty(actions) then
-- skip printing 'no code actions available'
return
end
local action_cosen
if #actions == 1 then
action_chosen = actions[1]
else
local option_strings = {'Code Actions:'}
for i, action in ipairs(actions) do
local title = action.title:gsub('\r\n', '\\r\\n')
title = title:gsub('\n', '\\n')
table.insert(option_strings, string.format('%d. %s', i, title))
end
local choice = vim.fn.inputlist(option_strings)
if choice < 1 or choice > #actions then
return
end
action_chosen = actions[choice]
end
if action_chosen.edit or type(action_chosen.command) == 'table' then
if action_chosen.edit then
vim.lsp.util.apply_workspace_edit(action_chosen.edit)
end
if type(action_chosen.command) == 'table' then
vim.lsp.buf.execute_command(action_chosen.command)
end
else
vim.lsp.buf.execute_command(action_chosen)
end
end
-- }}}
vim.fn.sign_define({
{name='LspDiagnosticsSignError', text='⚡', numhl='Error'},
{name='LspDiagnosticsSignWarning', text='⯈', numhl='Warning'},
{name='LspDiagnosticsSignInformation', text='ℹ'},
{name='LspDiagnosticsSignHint', text='🞶'}
})
-- lsp.ccls.setup {
-- on_attach = my_attach,
-- capabilities = caps,
-- }
lsp.gopls.setup {
on_attach = my_attach,
capabilities = caps,
settings = {
gopls = {
-- analyses = {
-- composites = false
-- },
codelenses = {
test = true,
tidy = true,
},
gofumpt = true,
}
}
}
lsp.sumneko_lua.setup {
on_attach = my_attach,
capabilities = caps,
cmd = { 'lua-language-server' };
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
},
diagnostics = {
globals = {'vim'},
},
workspace = {
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
}
}
}
}
}
lsp.rust_analyzer.setup {
on_attach = my_attach,
capabilities = caps,
cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'rust-analyzer' },
}
lsp.zls.setup {
on_attach = my_attach,
capabilities = caps,
}
lsp.zk.setup {
on_attach = my_attach,
capabilities = caps,
root_dir = lsp.util.root_pattern('.zk/'),
}
end
return {
my_attach = my_attach,
setup = setup
}
|