diff --git a/lua/custom/lspconfig.lua b/lua/custom/lspconfig.lua index 71ca12c..532d972 100644 --- a/lua/custom/lspconfig.lua +++ b/lua/custom/lspconfig.lua @@ -16,11 +16,17 @@ local keymap = vim.keymap -- for conciseness local function smart_format() vim.lsp.buf.format({ filter = function(client) - if vim.bo.filetype == "rust" then + local ft = vim.bo.filetype + if ft == "rust" then return client.name == "rust_analyzer" end - return client.name == "null-ls" + -- Prefer null-ls for all non-Rust, otherwise allow anything + if vim.tbl_contains({ "null-ls", "lua_ls", "jsonls", "tsserver" }, client.name) then + return true + end + return false end, + timeout_ms = 3000, }) end ---------- border >------------------------------ diff --git a/lua/custom/none-ls.lua b/lua/custom/none-ls.lua index e71fdcd..460136e 100644 --- a/lua/custom/none-ls.lua +++ b/lua/custom/none-ls.lua @@ -4,7 +4,38 @@ null_ls.setup({ sources = { null_ls.builtins.formatting.phpcbf.with({ command = "phpcbf", -- or full path if not in PATH - extra_args = { "--standard=PSR12" }, + extra_args = { "--standard=PSR12", "--standard=phpcs.xml" }, + }), + null_ls.builtins.diagnostics.phpstan.with({ + command = "phpstan", + args = { + "analyse", + "--error-format", "raw", + "--no-progress", + "$FILENAME", -- or your project's entrypoint folder + }, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, -- or ON_OPEN or BOTH + condition = function(utils) + return utils.root_has_file({ "phpstan.neon", "phpstan.neon.dist" }) + end, + }), + null_ls.builtins.diagnostics.phpcs.with({ + command = "phpcs", -- or "vendor/bin/phpcs" if local + args = { + "--standard=PSR12", -- or "phpcs.xml", "phpcs.xml.dist", etc. + "-s", -- show sniff codes + "-q", -- suppress warnings + "--report=emacs", + "--stdin-path", "$FILENAME", + "-" + }, + condition = function(utils) + return utils.root_has_file({ "phpcs.xml", "phpcs.xml.dist" }) or true + end, + }), + null_ls.builtins.formatting.phpcsfixer.with({ + command = "php-cs-fixer", + -- no extra_args needed if config file is correctly named and in root }), }, on_attach = on_attach,