mason + lsp config working

This commit is contained in:
Ray Elliott 2025-12-06 23:16:03 +00:00
commit 319c66bc0a
9 changed files with 142 additions and 26 deletions

View file

@ -7,30 +7,48 @@ return {
},
config = function()
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local util = require("lspconfig.util")
local servers = {
lua_ls = {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
local function on_attach(_, bufnr)
local map = function(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, noremap = true, desc = desc })
end
map('n', 'gd', vim.lsp.buf.definition, 'LSP: Go to definition')
map('n', 'gr', vim.lsp.buf.references, 'LSP: References')
map('n', 'gD', vim.lsp.buf.declaration, 'LSP: Go to declaration')
map('n', 'gI', vim.lsp.buf.implementation, 'LSP: Go to implementation')
map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover')
end
local function setup(server, opts)
local ok, mod = pcall(require, "lspconfig." .. server)
if not ok or type(mod.setup) ~= "function" then return end
mod.setup(vim.tbl_deep_extend("force", {
capabilities = capabilities,
on_attach = on_attach,
root_dir = util.root_pattern(
".neoconf.json",
".git",
"composer.json",
"package.json"
),
}, opts or {}))
end
setup("lua_ls", {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
},
ts_ls = {},
html = {},
cssls = {},
jsonls = {},
bashls = {},
marksman = {},
intelephense = {},
}
})
for name, opts in pairs(servers) do
local ok, mod = pcall(require, "lspconfig." .. name)
if ok and mod and type(mod.setup) == "function" then
opts = vim.tbl_deep_extend("force", { capabilities = capabilities }, opts or {})
mod.setup(opts)
end
end
setup("ts_ls")
setup("html")
setup("cssls")
setup("jsonls")
setup("bashls")
setup("marksman")
setup("intelephense")
end,
}

View file

@ -0,0 +1,20 @@
return {
"williamboman/mason-lspconfig.nvim",
dependencies = { "williamboman/mason.nvim" },
config = function()
require("mason-lspconfig").setup({
-- mason-lspconfig currently expects the legacy name "tsserver"
ensure_installed = {
"lua_ls",
"ts_ls",
"html",
"cssls",
"jsonls",
"bashls",
"marksman",
"intelephense",
},
automatic_installation = true,
})
end,
}

8
lua/plugins/mason.lua Normal file
View file

@ -0,0 +1,8 @@
return {
"williamboman/mason.nvim",
build = ":MasonUpdate",
config = function()
require("mason").setup({})
end,
}

View file

@ -2,9 +2,16 @@ return {
"folke/neoconf.nvim",
lazy = false, -- load early so it can influence lspconfig later
priority = 1000,
opts = {},
opts = {
live_reload = true,
filetype_jsonc = true,
plugins = {
lspconfig = { enabled = true },
jsonls = { enabled = true, configured_servers_only = false },
lua_ls = { enabled_for_neovim_config = true },
},
},
config = function(_, opts)
require("neoconf").setup(opts)
end,
}