forked from askfiy/nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnv_nvim-lsp-installer.lua
More file actions
231 lines (212 loc) · 6.69 KB
/
nv_nvim-lsp-installer.lua
File metadata and controls
231 lines (212 loc) · 6.69 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
-- https://github.com/neovim/nvim-lspconfig
-- https://github.com/SmiteshP/nvim-navic
-- https://github.com/stevearc/aerial.nvim
-- https://github.com/williamboman/nvim-lsp-installer
local api = require("utils.api")
local aux_lsp = require("utils.aux.lsp")
local options = require("core.options")
local M = {
safe_requires = {
{ "aerial" },
{ "lspconfig" },
{ "nvim-navic", "navic" },
{ "nvim-lsp-installer", "lsp_installer" },
},
installer_servers = {
"vimls",
"sumneko_lua",
"gopls",
"pyright",
"html",
"vuels",
"cssls",
"jsonls",
"emmet_ls",
"tsserver",
"tailwindcss",
},
}
function M.before() end
function M.load()
aux_lsp.quick_set(options.float_border)
M.lsp_installer.setup({
automatic_installation = true,
ui = {
border = options.float_border and "double" or "none",
icons = {
server_installed = "",
server_pending = "",
server_uninstalled = "ﮊ",
},
keymaps = {
toggle_server_expand = "<cr>",
install_server = "i",
update_server = "u",
check_server_version = "c",
update_all_servers = "U",
check_outdated_servers = "C",
uninstall_server = "X",
},
},
github = {
download_url_template = options.download_source .. "%s/releases/download/%s/%s",
},
max_concurrent_installers = 20,
})
end
function M.after()
-- store servers name waiting to be installed
local download_servers = {}
for _, server_name in pairs(M.installer_servers) do
local server_available, server_object = M.lsp_installer.get_server(server_name)
-- if available
if server_available then
-- if is installed
if server_object:is_installed() then
-- determine if there is a user-defined configuration file
local ok, lsp_config = pcall(require, string.format("configure.lsp.%s", server_name))
-- if there is no user-defined configuration file, use the default configuration
if not ok then
lsp_config = {}
end
lsp_config.capabilities = aux_lsp.get_capabilities()
lsp_config.handlers = aux_lsp.get_headlers(lsp_config)
lsp_config.on_attach = function(client, bufnr)
M.register_key()
M.navic.attach(client, bufnr)
M.aerial.on_attach(client, bufnr)
end
M.lspconfig[server_name].setup(lsp_config)
-- if not installed, add to download list and install server
else
table.insert(download_servers, server_name)
server_object:install()
end
-- invalid server name
else
local error_message = server_object
vim.notify(error_message, "ERROR", { title = "Language Server" })
end
end
-- show download information
if not vim.tbl_isempty(download_servers) then
vim.notify(
string.format("Install Language Servers: \n - %s", table.concat(download_servers, "\n - ")),
"INFO",
{ title = "Language Server" }
)
end
end
function M.register_key()
api.map.bulk_register({
{
mode = { "n" },
lhs = "<leader>ca",
rhs = vim.lsp.buf.code_action,
options = { silent = true },
description = "Show code action",
},
{
mode = { "n" },
lhs = "<leader>cn",
rhs = vim.lsp.buf.rename,
options = { silent = true },
description = "Variable renaming",
},
{
mode = { "n" },
lhs = "<leader>cf",
rhs = vim.lsp.buf.format,
options = { silent = true },
description = "Format buffer",
},
{
mode = { "n" },
lhs = "gh",
rhs = vim.lsp.buf.hover,
options = { silent = true },
description = "Show help information",
},
{
mode = { "n" },
lhs = "gr",
rhs = function()
require("telescope.builtin").lsp_references()
end,
options = { silent = true },
description = "Go to references",
},
{
mode = { "n" },
lhs = "gI",
rhs = function()
require("telescope.builtin").lsp_implementations()
end,
options = { silent = true },
description = "Go to implementations",
},
{
mode = { "n" },
lhs = "gD",
rhs = function()
require("telescope.builtin").lsp_type_definitions()
end,
options = { silent = true },
description = "Go to type definitions",
},
{
mode = { "n" },
lhs = "gd",
rhs = function()
require("telescope.builtin").lsp_definitions()
end,
options = { silent = true },
description = "Go to definitions",
},
{
mode = { "n" },
lhs = "go",
rhs = function()
require("telescope.builtin").diagnostics()
end,
options = { silent = true },
description = "Show Workspace Diagnostics",
},
{
mode = { "n" },
lhs = "[g",
rhs = aux_lsp.goto_prev_diagnostic,
options = { silent = true },
description = "Jump to prev diagnostic",
},
{
mode = { "n" },
lhs = "]g",
rhs = aux_lsp.goto_next_diagnostic,
options = { silent = true },
description = "Jump to next diagnostic",
},
{
mode = { "i" },
lhs = "<c-j>",
rhs = aux_lsp.sigature_help,
options = { silent = true },
description = "Toggle signature help",
},
{
mode = { "i", "n" },
lhs = "<c-b>",
rhs = aux_lsp.scroll_to_up,
options = { silent = true },
description = "Scroll up floating window",
},
{
mode = { "i", "n" },
lhs = "<c-f>",
rhs = aux_lsp.scroll_to_down,
options = { silent = true },
description = "Scroll down floating window",
},
})
end
return M