summaryrefslogtreecommitdiff
path: root/lua/user/lsp/mason.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/user/lsp/mason.lua')
-rw-r--r--lua/user/lsp/mason.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/lua/user/lsp/mason.lua b/lua/user/lsp/mason.lua
new file mode 100644
index 0000000..afd39ec
--- /dev/null
+++ b/lua/user/lsp/mason.lua
@@ -0,0 +1,46 @@
+local m = require("mason-lspconfig")
+
+-- Servers that should always be installed
+local servers = m.get_installed_servers();
+
+local settings = {
+ ui = {
+ border = "none",
+ },
+ log_level = vim.log.levels.INFO,
+ max_concurrent_installers = 4,
+}
+
+require("mason").setup(settings)
+require("mason-lspconfig").setup({
+ ensure_installed = servers,
+ automatic_installation = false,
+})
+
+local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
+if not lspconfig_status_ok then
+ return
+end
+
+local opts = {}
+
+-- Register a handler that will be called for all installed servers.
+-- Alternatively, you may also register handlers on specific server instances instead (see example below).
+for _, server in pairs(servers) do
+ opts = {
+ on_attach = require("user.lsp.handlers").on_attach,
+ capabilities = require("user.lsp.handlers").capabilities,
+ }
+
+ server = vim.split(server, "@")[1]
+
+ local require_ok, conf_opts = pcall(require, "user.lsp.settings." .. server)
+ if require_ok then
+ opts = vim.tbl_deep_extend("force", conf_opts, opts)
+ end
+
+ -- This setup() function is exactly the same as lspconfig's setup function.
+ -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
+ lspconfig[server].setup(opts)
+end
+