lsp configged, external sources configged
This commit is contained in:
parent
6befee365b
commit
6b10b78cd0
|
|
@ -2,14 +2,31 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"folke/neoconf.nvim",
|
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
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)
|
local map = function(mode, lhs, rhs, desc)
|
||||||
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, noremap = true, desc = desc })
|
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, noremap = true, desc = desc })
|
||||||
end
|
end
|
||||||
|
|
@ -20,22 +37,33 @@ return {
|
||||||
map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover')
|
map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup(server, opts)
|
-- Configure servers using vim.lsp.config (Neovim 0.11+ API)
|
||||||
local ok, mod = pcall(require, "lspconfig." .. server)
|
local function configure(server_name, opts)
|
||||||
if not ok or type(mod.setup) ~= "function" then return end
|
opts = opts or {}
|
||||||
mod.setup(vim.tbl_deep_extend("force", {
|
|
||||||
|
-- Merge with defaults
|
||||||
|
local config = vim.tbl_deep_extend("force", {
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
root_dir = util.root_pattern(
|
on_new_config = function(new_config, root_dir)
|
||||||
".neoconf.json",
|
-- Load project-specific settings based on actual root_dir
|
||||||
".git",
|
local project_settings = load_project_lsp_settings(server_name, root_dir)
|
||||||
"composer.json",
|
if project_settings.settings then
|
||||||
"package.json"
|
new_config.settings = vim.tbl_deep_extend(
|
||||||
),
|
"force",
|
||||||
}, opts or {}))
|
new_config.settings or {},
|
||||||
|
project_settings.settings
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}, opts)
|
||||||
|
|
||||||
|
-- Configure the server using the new API
|
||||||
|
vim.lsp.config(server_name, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
setup("lua_ls", {
|
-- Configure all servers
|
||||||
|
configure("lua_ls", {
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
diagnostics = { globals = { "vim" } },
|
diagnostics = { globals = { "vim" } },
|
||||||
|
|
@ -43,23 +71,17 @@ return {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
setup("ts_ls")
|
configure("ts_ls")
|
||||||
setup("html")
|
configure("html")
|
||||||
setup("cssls")
|
configure("cssls")
|
||||||
setup("jsonls")
|
configure("jsonls")
|
||||||
setup("bashls")
|
configure("bashls")
|
||||||
setup("marksman")
|
configure("marksman")
|
||||||
-- TODO(r): Root detection can pick a parent repo in nested setups.
|
configure("intelephense", {
|
||||||
-- 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", {
|
|
||||||
single_file_support = false,
|
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,
|
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_perl_provider = 0
|
||||||
vim.g.loaded_node_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)
|
-- Phase 3.2: non-plugin settings (legacy values where specified)
|
||||||
-- Completion UI for nvim-cmp
|
-- Completion UI for nvim-cmp
|
||||||
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
|
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue