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

@ -1,8 +1,42 @@
-- Non-plugin keymaps (kept intentionally minimal for bootstrap)
-- Non-plugin and global helper keymaps
local map = vim.keymap.set
local opts = { noremap = true, silent = true }
-- Add non-plugin keymaps during Phase 3 when porting settings
-- LSP-aware helpers with graceful fallback to built-ins
local function lsp_has(bufnr, capability)
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
if client.server_capabilities[capability] then return true end
end
return false
end
local function lsp_or_builtin(bufnr, capability, lsp_fn, builtin_normal)
if lsp_has(bufnr, capability) then
lsp_fn()
else
vim.cmd("normal! " .. builtin_normal)
end
end
-- Global LSP-keymaps with fallback so they work reliably
map('n', 'gd', function()
lsp_or_builtin(0, 'definitionProvider', vim.lsp.buf.definition, 'gd')
end, { desc = 'Go to definition (LSP or built-in)' })
map('n', 'gr', function()
if lsp_has(0, 'referencesProvider') then vim.lsp.buf.references() end
end, { desc = 'References (LSP)', silent = true })
map('n', 'gD', function()
lsp_or_builtin(0, 'declarationProvider', vim.lsp.buf.declaration, 'gD')
end, { desc = 'Go to declaration (LSP or built-in)' })
map('n', 'gI', function()
if lsp_has(0, 'implementationProvider') then vim.lsp.buf.implementation() end
end, { desc = 'Go to implementation (LSP)', silent = true })
map('n', 'K', function()
if lsp_has(0, 'hoverProvider') then vim.lsp.buf.hover() end
end, { desc = 'Hover (LSP)', silent = true })
return {}

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,
}