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
|
return {
setup = function(ops)
ops = vim.tbl_deep_extend("force", require "pi.lsp.default", ops)
local lspconfig = require "lspconfig"
require('lspconfig.ui.windows').default_options.border = 'single'
local mason_servers = {}
for server, options in pairs(ops.servers) do
if options.enable == true then
local ok, definition = pcall(require, "pi.lsp.servers." .. server)
local server_options
if not ok then
server_options = ops.default_options(options)
else
server_options = definition(options)
end
lspconfig[server].setup(server_options)
table.insert(mason_servers, server)
end
end
-- Mason
if ops.mason.enable then
local mason_ops = {}
if ops.mason.auto_install == true then
mason_ops.ensure_installed = mason_servers
end
local mason_lspconfig = require "mason-lspconfig"
mason_lspconfig.setup(mason_ops)
end
-- TODO: implement null ls with options
require "pi.lsp.null-ls"
local servers = {}
for server, options in pairs(ops.servers) do
table.insert(servers, string.format("%s <%s>", server, options.enable))
end
-- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up.
-- can get the client by name of the file
vim.api.nvim_create_user_command("PiLSP", function()
vim.ui.select(servers, { prompt = "LSP Servers" }, function(server)
if server == nil then
return
end
server = string.match(server, "^(.+) <")
local path = string.format("%s/lua/pi/lsp/servers/%s.lua", vim.fn.stdpath "config", server)
if vim.fn.filereadable(path) == 0 then
local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel")
if create ~= 1 then
return
end
end
local uri = vim.uri_from_fname(path)
local buffer = vim.uri_to_bufnr(uri)
vim.api.nvim_win_set_buf(0, buffer)
end)
end, {})
end,
}
|