optimize null_ls
parent
dba36e227c
commit
a3269dbfc4
|
@ -16,11 +16,17 @@ local keymap = vim.keymap -- for conciseness
|
||||||
local function smart_format()
|
local function smart_format()
|
||||||
vim.lsp.buf.format({
|
vim.lsp.buf.format({
|
||||||
filter = function(client)
|
filter = function(client)
|
||||||
if vim.bo.filetype == "rust" then
|
local ft = vim.bo.filetype
|
||||||
|
if ft == "rust" then
|
||||||
return client.name == "rust_analyzer"
|
return client.name == "rust_analyzer"
|
||||||
end
|
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,
|
end,
|
||||||
|
timeout_ms = 3000,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
---------- border >------------------------------
|
---------- border >------------------------------
|
||||||
|
|
|
@ -4,7 +4,38 @@ null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
null_ls.builtins.formatting.phpcbf.with({
|
null_ls.builtins.formatting.phpcbf.with({
|
||||||
command = "phpcbf", -- or full path if not in PATH
|
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,
|
on_attach = on_attach,
|
||||||
|
|
Loading…
Reference in New Issue