Files
nvim-kickstart/lua/custom/lspconfig.lua
T
mathiasandClaude Sonnet 5 2646541406 Clean up config: fix broken plugin specs, dedupe options/keymaps, drop dead code
- lspsaga: custom keys lived outside config(), so setup({}) ran empty and
  they never worked; moved into setup() and updated to the plugin's current
  option schema (finder_action_keys/definition_action_keys/move_in_saga
  are stale names in the installed version)
- catppuccin: fixed a stray `as = "catppuccin"` key left outside the plugin
  table; wrapped as { "catppuccin/nvim", name = "catppuccin" }
- options: consolidated the three competing sources (vimrc, init.lua,
  custom/options.lua) into custom/options.lua alone; hlsearch/wrap were
  silently landing opposite to what init.lua's own comments said, purely
  from require-order. custom/options.lua now loads first in the require
  chain since colorizer.lua and others need termguicolors set before their
  own setup() runs
- removed duplicate keymaps that were dead on arrival due to load order
  (<leader>rn, <leader>sf/sg/sh, jj, <leader>y, mapleader x3, manual
  C-h/j/k/l vs vim-tmux-navigator)
- removed dead code: smart_format, root_dir/fallback_root_dir, toggleterm's
  unused _LAZYGIT_TOGGLE/_NODE_TOGGLE/_PYTHON_TOGGLE globals, unused local
  cmp, stale commented blocks, lua/custom/startup.lua
- removed unused plugins: mini.icons, telescope-dap.nvim,
  startup-nvim/startup.nvim (malformed spec, never actually required),
  plus leftover ALE globals with no ALE plugin installed
- vim.loop.* -> vim.uv.*, vim.diagnostic.goto_prev/next ->
  vim.diagnostic.jump({count=...}) for 0.12.5
- guard vim.treesitter.start() at the top of init.lua: the system's
  bundled Lua highlight query is currently ahead of the available
  tree-sitter-lua grammar (a packaging skew, confirmed nvim-treesitter is
  fully up to date), which was throwing on every Lua buffer and taking
  omnifunc/foldexpr down with it; now falls back to regex highlighting
  with a single notify instead

Verified end-to-end against a real Neovim 0.12.5 headless instance with a
fresh plugin install: no load errors, lspsaga's custom keys now actually
apply, and the treesitter guard was confirmed against the real environment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013jVh2Lhn386JAvjSFCHUhn
2026-08-27 22:27:37 +02:00

177 lines
6.5 KiB
Lua

-- lsp.lua (replace your current file with this)
-- import cmp-nvim-lsp plugin safely
-- local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
-- if not cmp_nvim_lsp_status then
-- return
-- end
local keymap = vim.keymap -- for conciseness
---------- border >------------------------------
do
local orig_floating_preview = vim.lsp.util.open_floating_preview
vim.lsp.util.open_floating_preview = function(contents, syntax, opts, ...)
opts = opts or {}
opts.border = "rounded"
return orig_floating_preview(contents, syntax, opts, ...)
end
end
---------- </border ------------------------------
vim.diagnostic.config({
virtual_text = false, -- Disable inline virtual text
float = {
border = "rounded", -- You can choose "single", "double", etc.
source = "always", -- Show the source of the diagnostic (set to 'if_many' for less clutter)
header = "", -- Optional: add a header to the float window
prefix = "", -- Optional: prefix for each diagnostic (leave empty for no prefix)
},
underline = true, -- Optional: underline the lines with errors
signs = true, -- Optional: show signs in the sign column
})
-- enable keybinds only for when lsp server available
local on_attach = function(_, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
keymap.set("n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", opts)
keymap.set("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
keymap.set("n", "<leader>l", function()
vim.lsp.buf.format()
end, { desc = "Format code function" })
keymap.set(
"n",
"<leader>cbf",
":!phpcbf -w --standard=PSR12 %<CR>",
{ noremap = true, silent = false, buffer = bufnr }
)
keymap.set("n", "<leader>o", "<cmd>Lspsaga outline<CR>", opts)
keymap.set("n", "<leader>ss", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts)
-- LSP Saga
keymap.set("n", "gsd", "<cmd>Lspsaga peek_definition<CR>", opts)
keymap.set("n", "gr", "<cmd>Lspsaga finder<CR>", opts)
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts)
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts)
keymap.set("n", "ge", "<cmd>Lspsaga show_line_diagnostics<CR>", opts)
keymap.set("n", "<a-cr>", "<cmd>Lspsaga code_action<CR>", opts)
-- keymap.set("n", "<leader>d", "<cmd>Telescope diagnostics<CR>", opts)
keymap.set("n", "<leader>da", "<cmd>Lspsaga show_workspace_diagnostics ++float<CR>", opts)
keymap.set("n", "<leader>db", "<cmd>Lspsaga show_buf_diagnostics ++float<CR>", opts)
keymap.set("n", "<leader>dn", "<cmd>Lspsaga diagnostic_jump_next<CR>")
keymap.set("n", "<leader>dp", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
keymap.set("n", "gj", "<cmd>lua require'nvim-treesitter-textobjects.move'.goto_next_start('@function.outer')<CR>",
opts)
keymap.set("n", "gk", "<cmd>lua require'nvim-treesitter-textobjects.move'.goto_previous_start('@function.outer')<CR>",
opts)
end
-- capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- helper for registering server configs (lazy attach)
local function setup_server(name, config)
local cfg = vim.tbl_deep_extend("force", {
capabilities = capabilities,
on_attach = on_attach,
}, config or {})
-- register the config
-- use the function form so it works in latest nvim
vim.lsp.config(name, cfg)
end
-- servers
setup_server("bashls", { filetypes = { "sh", "bin" } })
setup_server("lemminx", { filetypes = { "xml" } })
setup_server("yamlls", { filetypes = { "yaml", "yml" } })
setup_server("jsonls", { filetypes = { "json" } })
setup_server("pyright", { filetypes = { "py" } })
setup_server("html", { filetypes = { "html" } })
setup_server("cssls",
{ filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" } })
setup_server("eslint", {
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
})
setup_server("rust_analyzer", {
settings = {
["rust-analyzer"] = { checkOnSave = true, check = { command = "clippy" } },
},
})
-- PHP LSPs
-- start it manually :LspStart phpactor
-- setup_server("phpactor", {
-- filetypes = { "php" },
-- -- root_dir = fallback_root_dir,
-- init_options = {
-- ["language_server_phpstan.enabled"] = true,
-- ["language_server_psalm.enabled"] = false,
-- },
-- })
setup_server("lua_ls", {
filetypes = { "lua" },
settings = {
Lua = {
diagnostics = {
globals = { "vim" } },
format = { enable = true },
}
}
})
setup_server("intelephense", {
filetypes = { "php" },
-- root_dir = fallback_root_dir,
init_options = {
licenceKey = (function()
local license_path = vim.fn.expand("$HOME/.config/intelephense/license.txt")
if vim.fn.filereadable(license_path) == 1 then
return vim.fn.readfile(license_path)[1]
end
return nil
end)(),
},
settings = {
intelephense = {
telemetry = { enabled = false },
files = {
maxSize = 5000000,
associations = { "**/*.php" },
},
completion = {
fullyQualifyGlobalConstantsAndFunctions = false,
triggerParameterHints = true,
maxItems = 100,
},
phpdoc = { enabled = true },
diagnostics = { enable = true },
format = { enable = false },
},
},
})
-- phpcs / phpstan configs
vim.g.nvim_phpcs_config_phpcs_path = 'phpcs'
vim.g.nvim_phpcs_config_phpcbf_path = 'phpcbf'
local phpcs_config = "~/repos/configs/phpcs.xml"
local phpcs_config_new = "~/repos/dotfiles/phpcs.xml"
if vim.uv.fs_stat(phpcs_config_new) then
vim.g.nvim_phpcs_config_phpcs_standard = phpcs_config_new
elseif vim.uv.fs_stat(phpcs_config) then
vim.g.nvim_phpcs_config_phpcs_standard = phpcs_config
end
-- === ENABLE: tell Neovim to autostart these configs lazily (filetype + root_dir)
-- call this early in your init (so FileType autocommands are installed before opening files)
local enabled_servers = {
"bashls", "lemminx", "yamlls", "jsonls", "pyright", "html", "cssls",
"eslint", "rust_analyzer", "lua_ls",
"intelephense"
}
vim.lsp.enable(enabled_servers)