-- 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 ---------- lua vim.lsp.buf.document_symbol()", opts) -- floating popups instead of the quickfix split for multiple results keymap.set("n", "gd", "Lspsaga finder def", opts) keymap.set("n", "gi", "Lspsaga finder imp", opts) keymap.set("n", "gy", "Lspsaga finder tyd", opts) keymap.set("n", "l", format_buffer, { desc = "Format code function" }) keymap.set( "n", "cbf", ":!phpcbf -w --standard=PSR12 %", { noremap = true, silent = false, buffer = bufnr } ) keymap.set("n", "o", "Lspsaga outline", opts) keymap.set("n", "ss", "Telescope lsp_dynamic_workspace_symbols", opts) -- LSP Saga keymap.set("n", "gsd", "Lspsaga peek_definition", opts) keymap.set("n", "gr", "Lspsaga finder", opts) keymap.set("n", "rn", "Lspsaga rename", opts) keymap.set("n", "ca", "Lspsaga code_action", opts) keymap.set("n", "ge", "Lspsaga show_line_diagnostics", opts) keymap.set("n", "", "Lspsaga code_action", opts) -- keymap.set("n", "d", "Telescope diagnostics", opts) keymap.set("n", "da", "Lspsaga show_workspace_diagnostics ++float", opts) keymap.set("n", "db", "Lspsaga show_buf_diagnostics ++float", opts) keymap.set("n", "dn", "Lspsaga diagnostic_jump_next") keymap.set("n", "dp", "Lspsaga diagnostic_jump_prev") keymap.set("n", "gj", "lua require'nvim-treesitter-textobjects.move'.goto_next_start('@function.outer')", opts) keymap.set("n", "gk", "lua require'nvim-treesitter-textobjects.move'.goto_previous_start('@function.outer')", 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" } }) -- nvim-lspconfig's own filetypes (javascript, typescript, vue, the *react -- variants, svelte, ...) - the server uses the project's node_modules eslint -- and its config, like ALE does in ~/repos/vim. nodePath is the fallback -- for projects without one: the global eslint (npm root -g), which the -- server doesn't look in on its own. -- -- applySuppressions honours a project's ESLint baseline (eslint-suppressions.json, -- e.g. rcc's), which the server otherwise ignores. Only set when that file -- exists: eslint before 9.24 doesn't know the option and refuses to start. -- nvim-lspconfig's own before_init (workspaceFolder) still runs first. local eslint_before_init = vim.lsp.config.eslint.before_init setup_server("eslint", { settings = { nodePath = "/usr/lib/node_modules" }, before_init = function(params, config) if eslint_before_init then eslint_before_init(params, config) end if config.root_dir and vim.uv.fs_stat(config.root_dir .. "/eslint-suppressions.json") then config.settings.options = vim.tbl_extend("force", config.settings.options or {}, { applySuppressions = true }) end end, }) 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 }, } } }) -- Which PHP LSP server gets enabled - "intelephense" (licensed, mature) or -- "phpantom_lsp" (Rust, faster startup). Only one: running both doubles up -- completion, hover and diagnostics. Mirrors g:pure_vim_php_lsp_server in -- ~/repos/vim; override with `vim.g.php_lsp_server = "intelephense"` before -- this file is loaded. local php_lsp_server = vim.g.php_lsp_server or "phpantom_lsp" -- phpantom runs PHPStan, PHPMD, PHPCS and Mago itself when a project has -- them, but none-ls already runs phpstan/phpcs. Its only switch is a -- per-project .phpantom.toml, so one turning those off is written to the -- workspace root before the server initializes. An existing one is left alone. local phpantom_config = { "# generated by nvim-kickstart lspconfig.lua: phpstan, phpmd and phpcs", "# run through none-ls, Mago is off. Edit freely - it is never overwritten.", "[mago]", 'command = ""', "[phpstan]", 'command = ""', "[phpmd]", 'command = ""', "[phpcs]", 'command = ""', } setup_server("phpantom_lsp", { before_init = function(_, config) local root = config.root_dir if not root then return end local file = root .. "/.phpantom.toml" if vim.uv.fs_stat(file) or not vim.uv.fs_stat(root .. "/composer.json") then return end vim.fn.writefile(phpantom_config, file) end, }) 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", php_lsp_server, } vim.lsp.enable(enabled_servers)