lsp configged, external sources configged
This commit is contained in:
parent
6befee365b
commit
6b10b78cd0
|
|
@ -2,14 +2,31 @@ return {
|
|||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"folke/neoconf.nvim",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
local util = require("lspconfig.util")
|
||||
|
||||
local function on_attach(_, bufnr)
|
||||
-- Load project-local LSP settings from .nvim.lua
|
||||
local function load_project_lsp_settings(server_name, root_dir)
|
||||
local config_file = root_dir .. "/.nvim.lua"
|
||||
if vim.fn.filereadable(config_file) == 1 then
|
||||
local ok, project_config = pcall(dofile, config_file)
|
||||
if ok and project_config and project_config.lsp and project_config.lsp[server_name] then
|
||||
return project_config.lsp[server_name]
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
local function on_attach(client, bufnr)
|
||||
-- Send settings to server after attach (many servers need didChangeConfiguration)
|
||||
if client.config.settings and next(client.config.settings) then
|
||||
vim.schedule(function()
|
||||
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
|
||||
end)
|
||||
end
|
||||
|
||||
local map = function(mode, lhs, rhs, desc)
|
||||
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, noremap = true, desc = desc })
|
||||
end
|
||||
|
|
@ -20,22 +37,33 @@ return {
|
|||
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", {
|
||||
-- Configure servers using vim.lsp.config (Neovim 0.11+ API)
|
||||
local function configure(server_name, opts)
|
||||
opts = opts or {}
|
||||
|
||||
-- Merge with defaults
|
||||
local config = 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 {}))
|
||||
on_new_config = function(new_config, root_dir)
|
||||
-- Load project-specific settings based on actual root_dir
|
||||
local project_settings = load_project_lsp_settings(server_name, root_dir)
|
||||
if project_settings.settings then
|
||||
new_config.settings = vim.tbl_deep_extend(
|
||||
"force",
|
||||
new_config.settings or {},
|
||||
project_settings.settings
|
||||
)
|
||||
end
|
||||
end,
|
||||
}, opts)
|
||||
|
||||
-- Configure the server using the new API
|
||||
vim.lsp.config(server_name, config)
|
||||
end
|
||||
|
||||
setup("lua_ls", {
|
||||
-- Configure all servers
|
||||
configure("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } },
|
||||
|
|
@ -43,23 +71,17 @@ return {
|
|||
},
|
||||
})
|
||||
|
||||
setup("ts_ls")
|
||||
setup("html")
|
||||
setup("cssls")
|
||||
setup("jsonls")
|
||||
setup("bashls")
|
||||
setup("marksman")
|
||||
-- TODO(r): Root detection can pick a parent repo in nested setups.
|
||||
-- Workaround noted in MIGRATION_PLAN.md: create an empty `.git` (or `.nvimroot`)
|
||||
-- in the intended workspace root to pin LSP root until we refine root_dir further.
|
||||
setup("intelephense", {
|
||||
configure("ts_ls")
|
||||
configure("html")
|
||||
configure("cssls")
|
||||
configure("jsonls")
|
||||
configure("bashls")
|
||||
configure("marksman")
|
||||
configure("intelephense", {
|
||||
single_file_support = false,
|
||||
root_dir = util.root_pattern(
|
||||
".neoconf.json",
|
||||
"composer.json",
|
||||
".nvimroot",
|
||||
".git"
|
||||
),
|
||||
})
|
||||
|
||||
-- Enable all configured servers
|
||||
vim.lsp.enable({ "lua_ls", "ts_ls", "html", "cssls", "jsonls", "bashls", "marksman", "intelephense" })
|
||||
end,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
return {
|
||||
"folke/neoconf.nvim",
|
||||
lazy = false, -- load early so it can influence lspconfig later
|
||||
priority = 1000,
|
||||
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,
|
||||
}
|
||||
|
|
@ -5,6 +5,10 @@ vim.g.loaded_ruby_provider = 0
|
|||
vim.g.loaded_perl_provider = 0
|
||||
vim.g.loaded_node_provider = 0
|
||||
|
||||
-- Enable project-local configuration files
|
||||
vim.opt.exrc = true -- Load .nvim.lua from project root
|
||||
vim.opt.secure = true -- Prompt before loading untrusted files
|
||||
|
||||
-- Phase 3.2: non-plugin settings (legacy values where specified)
|
||||
-- Completion UI for nvim-cmp
|
||||
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
|
||||
|
|
|
|||
Loading…
Reference in New Issue