forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlspconfig.lua
219 lines (189 loc) · 7.23 KB
/
lspconfig.lua
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
-- plugin: nvim-lspconfig
-- see: https://github.com/neovim/nvim-lspconfig
-- https://github.com/williamboman/nvim-lsp-installer
-- https://github.com/ray-x/lsp_signature.nvim
-- https://github.com/kosayoda/nvim-lightbulb
-- rafi settings
-- Buffer attached
local on_attach = function(client, bufnr)
local function map_buf(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
-- Keyboard mappings
local opts = { noremap = true, silent = true }
map_buf("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
-- Short-circuit for Helm template files
if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then
require("user").diagnostic.disable(bufnr)
return
end
map_buf("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
map_buf("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
map_buf("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
map_buf("n", "gy", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
map_buf("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
map_buf("n", ",s", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
map_buf("n", ",wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
map_buf("n", ",wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
map_buf("n", ",wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
map_buf("n", ",rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
map_buf("n", "<Leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
map_buf("n", "<Leader>ce", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
-- Set some keybinds conditional on server capabilities
if client.supports_method("textDocument/formatting") then
if vim.fn.has("nvim-0.8") == 1 then
map_buf("n", ",f", "<cmd>lua vim.lsp.buf.format({ timeout_ms = 2000 })<CR>", opts)
else
map_buf("n", ",f", "<cmd>lua vim.lsp.buf.formatting(nil, 2000)<CR>", opts)
end
end
if client.supports_method("textDocument/rangeFormatting") then
map_buf("x", ",f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
end
-- lspsaga.nvim
-- See https://github.com/glepnir/lspsaga.nvim
-- buf_set_keymap('n', '<Leader>f', '<cmd>lua require("lspsaga.provider").lsp_finder()<CR>', opts)
-- buf_set_keymap('n', 'K', '<cmd>lua require("lspsaga.hover").render_hover_doc()<CR>', opts)
-- buf_set_keymap('n', ',s', '<cmd>lua require("lspsaga.signaturehelp").signature_help()<CR>', opts)
-- buf_set_keymap('n', ',rn', '<cmd>lua require("lspsaga.rename").rename()<CR>', opts)
-- buf_set_keymap('n', '<Leader>ca', '<cmd>lua require("lspsaga.codeaction").code_action()<CR>', opts)
-- buf_set_keymap('v', '<Leader>ca', ':<C-u>lua require("lspsaga.codeaction").range_code_action()<CR>', opts)
-- lsp_signature.nvim
-- See https://github.com/ray-x/lsp_signature.nvim
-- require('lsp_signature').on_attach({
-- bind = true,
-- check_pumvisible = true,
-- hint_enable = false,
-- hint_prefix = ' ', --
-- handler_opts = { border = 'rounded' },
-- zindex = 50,
-- }, bufnr)
if client.config.flags then
client.config.flags.allow_incremental_sync = true
-- client.config.flags.debounce_text_changes = vim.opt.updatetime:get()
end
-- Set autocommands conditional on server capabilities
if client.supports_method("textDocument/documentHighlight") then
vim.api.nvim_exec(
[[
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
end
if client.server_capabilities.documentSymbolProvider then
-- require("nvim-navic").attach(client, bufnr)
require("nvim-navbuddy").attach(client, bufnr)
end
end
-- Combine base config for each server and merge user-defined settings.
local function make_config(server_name)
-- Setup base config for each server.
local c = {}
c.on_attach = on_attach
local cap = vim.lsp.protocol.make_client_capabilities()
c.capabilities = require("cmp_nvim_lsp").default_capabilities(cap)
-- Merge user-defined lsp settings.
-- These can be overridden locally by lua/lsp-local/<server_name>.lua
local exists, module = pcall(require, "lsp-local." .. server_name)
if not exists then
exists, module = pcall(require, "lsp." .. server_name)
end
if exists then
local user_config = module.config(c)
for k, v in pairs(user_config) do
c[k] = v
end
end
return c
end
-- main
local function setup()
-- Config
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = true,
update_in_insert = false,
severity_sort = true,
})
-- Diagnostics signs and highlights
-- Error: ✘
-- Warn: ⚠
-- Hint:
-- Info: ⁱ
local signs = { Error = "✘", Warn = "", Hint = "", Info = "ⁱ" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
-- Setup CompletionItemKind symbols, see lua/lsp_kind.lua
-- require('lsp_kind').init()
-- Configure LSP Handlers
-- ---
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
-- https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization#show-source-in-diagnostics-neovim-06-only
source = "if_many",
prefix = "●",
},
})
-- Configure diagnostics publish settings
-- vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
-- vim.lsp.diagnostic.on_publish_diagnostics, {
-- signs = true,
-- underline = true,
-- update_in_insert = false,
-- severity_sort = true,
-- virtual_text = {
-- spacing = 4,
-- -- prefix = '',
-- }
-- }
-- )
-- Configure help hover (normal K) handler
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
-- Configure signature help (,s) handler
vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
-- Setup language servers using nvim-lsp-installer
-- See https://github.com/williamboman/nvim-lsp-installer
local lsp_installer = require("nvim-lsp-installer")
lsp_installer.setup()
-- Setup language servers using nvim-lspconfig
local lspconfig = require("lspconfig")
for _, ls in pairs(lsp_installer.get_installed_servers()) do
local opts = make_config(ls.name)
lspconfig[ls.name].setup(opts)
end
lspconfig.r_language_server.setup({})
-- global custom location-list diagnostics window toggle.
local args = { noremap = true, silent = true }
local function nmap(lhs, rhs)
vim.api.nvim_set_keymap("n", lhs, rhs, args)
end
nmap("<Leader>a", '<cmd>lua require("user").diagnostic.publish_loclist(true)<CR>')
nmap("[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>")
nmap("]d", "<cmd>lua vim.diagnostic.goto_next()<CR>")
require("nvim-lightbulb").setup({ ignore = { "null-ls" } })
vim.api.nvim_exec(
[[
augroup user_lspconfig
autocmd!
" See https://github.com/kosayoda/nvim-lightbulb
autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()
" Automatic diagnostic hover
" autocmd CursorHold * lua require("user").diagnostic.open_float({ focusable=false })
augroup END
]],
false
)
end
return {
setup = setup,
on_attach = on_attach,
}