[diagnosticls] Add php-cs-fixer

This commit is contained in:
2023-12-23 00:06:39 +01:00
parent aa122b5de8
commit 5c7ccf57e8
2 changed files with 44 additions and 4 deletions
+22 -4
View File
@@ -38,7 +38,7 @@ P.config = {
} }
for server, _ in pairs(P.config) do for server, _ in pairs(P.config) do
utils.try_require("lsp." .. server, package_name, function(mod) utils.try_require("lsp." .. server, package_name, function (mod)
P.config[server] = mod P.config[server] = mod
end) end)
end end
@@ -108,7 +108,25 @@ function P.on_attach(client, bufnr)
{ "n", "x", }, { "n", "x", },
"<leader>lf", "<leader>lf",
function () function ()
vim.lsp.buf.format({ async = false, }) if vim.bo.filetype ~= "php" then
return vim.lsp.buf.format()
end
local dls = require("lsp.diagnosticls")
local formatters = dls.lspconfig.init_options.formatFiletypes.php
for _, fmt in ipairs(formatters) do
if fmt == "php_cs_fixer" then
---@type table
local winview = vim.fn.winsaveview()
vim.cmd.write({ bang = true, })
vim.lsp.buf.format()
vim.cmd.write({ bang = true, })
vim.fn.winrestview(winview)
return
end
end
return vim.lsp.buf.format()
end, end,
opts opts
) )
@@ -199,8 +217,8 @@ function P.language_servers()
if #not_installed > 0 then if #not_installed > 0 then
utils.warn( utils.warn(
("Disabling %s " ("Disabling %s "
+ "because the following required package(s) " .. "because the following required package(s) "
+ "are not installed: %s") .. "are not installed: %s")
:format( :format(
server, server,
table.concat(not_installed, ", ") table.concat(not_installed, ", ")
+22
View File
@@ -126,6 +126,7 @@ return {
sh = { "shfmt", }, sh = { "shfmt", },
bash = { "shfmt", }, bash = { "shfmt", },
zsh = { "shfmt", }, zsh = { "shfmt", },
php = { "php_cs_fixer", },
}, },
formatters = { formatters = {
autopep8 = { autopep8 = {
@@ -185,6 +186,27 @@ return {
isStderr = false, isStderr = false,
ignoreExitCode = true, ignoreExitCode = true,
}, },
php_cs_fixer = {
command = "./vendor/bin/php-cs-fixer",
args = {
"fix",
"--no-ansi",
"--using-cache=no",
"--quiet",
"--no-interaction",
"%file",
},
isStdout = false,
isStderr = false,
doesWriteToFile = true,
ignoreExitCode = true,
rootPatterns = {
"composer.json",
"composer.lock",
"vendor",
".git",
},
},
}, },
}, },
}, },