2024-02-09 17:53:16 +00:00
|
|
|
local config = require 'lspconfig'
|
2024-11-19 08:22:14 +00:00
|
|
|
local util = require 'lspconfig.util'
|
2024-02-09 17:53:16 +00:00
|
|
|
|
2024-04-29 12:18:56 +00:00
|
|
|
local ensure_capabilities
|
|
|
|
xpcall(function()
|
|
|
|
ensure_capabilities = require("coq").lsp_ensure_capabilities
|
|
|
|
end, function()
|
|
|
|
function ensure_capabilities(...)
|
|
|
|
return ...
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2024-02-09 17:53:16 +00:00
|
|
|
local default = { on_attach = require 'lsp.attach' }
|
2024-07-09 12:08:05 +00:00
|
|
|
setmetatable(default, {__call = function(self, other)
|
|
|
|
local new = {}
|
|
|
|
for _, tab in ipairs{self, other} do
|
|
|
|
for key, value in pairs(tab) do
|
|
|
|
new[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return new
|
|
|
|
end})
|
|
|
|
|
2024-10-01 09:22:40 +00:00
|
|
|
-- init_options -> during server initialization
|
|
|
|
-- settings -> sent as config change event right after initialization
|
2024-09-16 12:55:50 +00:00
|
|
|
local configs = setmetatable({
|
2024-11-19 08:22:14 +00:00
|
|
|
ruby_lsp = default {
|
|
|
|
init_options = {
|
|
|
|
formatter = "standard";
|
|
|
|
linters = { "standard" };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
standardrb = default {
|
|
|
|
root_dir = util.root_pattern("Gemfile", ".git", ".standard.yml");
|
|
|
|
},
|
2024-09-16 12:55:50 +00:00
|
|
|
yamlls = default {
|
|
|
|
settings = {
|
|
|
|
yaml = {
|
|
|
|
format = { enable = true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}, {__index = function() return default end})
|
|
|
|
|
|
|
|
for _, language in ipairs {
|
2024-02-09 17:53:16 +00:00
|
|
|
"clangd",
|
2024-06-24 14:18:04 +00:00
|
|
|
"cssls",
|
|
|
|
"html",
|
2024-02-09 17:53:16 +00:00
|
|
|
"lua_ls",
|
2024-08-12 08:02:46 +00:00
|
|
|
"ruby_lsp",
|
2024-10-01 09:22:40 +00:00
|
|
|
"solargraph",
|
2024-02-09 17:53:16 +00:00
|
|
|
"standardrb",
|
2024-06-24 14:18:04 +00:00
|
|
|
"svelte",
|
|
|
|
"tsserver",
|
2024-02-09 17:53:16 +00:00
|
|
|
"zls",
|
2024-09-16 12:55:50 +00:00
|
|
|
"yamlls", -- bun install --global yaml-language-server
|
2024-02-09 17:53:16 +00:00
|
|
|
} do
|
2024-09-16 12:55:50 +00:00
|
|
|
config[language].setup(ensure_capabilities(configs[language]))
|
2024-07-09 12:08:05 +00:00
|
|
|
end
|
|
|
|
|
2024-09-16 12:55:50 +00:00
|
|
|
-- function _G.ls(name)
|
|
|
|
-- for _, server in pairs(vim.lsp.get_clients()) do
|
|
|
|
-- if server.config.name == name then
|
|
|
|
-- return server
|
|
|
|
-- end
|
|
|
|
-- error("No running language server with name " .. name)
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
|
|
|
|
vim.api.nvim_create_user_command("LspAdd", function(params)
|
|
|
|
local language = params.args
|
|
|
|
local setup = config[language].setup -- temp variable for better stack trace
|
|
|
|
setup(ensure_capabilities(configs[language]))
|
|
|
|
end, {nargs = 1})
|