From 6b10b78cd0cca2966defe8b4722cf56a7c2d75ec Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 7 Dec 2025 17:31:06 +0000 Subject: [PATCH] lsp configged, external sources configged --- lua/plugins/lsp.lua | 84 ++++++++++++++++++++++++++--------------- lua/plugins/neoconf.lua | 17 --------- lua/settings.lua | 4 ++ 3 files changed, 57 insertions(+), 48 deletions(-) delete mode 100644 lua/plugins/neoconf.lua diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index e322999..e075c8a 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -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, } diff --git a/lua/plugins/neoconf.lua b/lua/plugins/neoconf.lua deleted file mode 100644 index 2a5f9b1..0000000 --- a/lua/plugins/neoconf.lua +++ /dev/null @@ -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, -} diff --git a/lua/settings.lua b/lua/settings.lua index be40ed2..07dd898 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -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' }