Adding php to lsp
This commit is contained in:
62
lua/config/lsp/php.lua
Normal file
62
lua/config/lsp/php.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
local ok, mason_lspconfig, mason_tool_installer, lspconfig, conform, lint = pcall(function()
|
||||
return require("mason-lspconfig"),
|
||||
require("mason-tool-installer"),
|
||||
require("lspconfig"),
|
||||
require("conform"),
|
||||
require("lint")
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
mason_lspconfig.setup({
|
||||
ensure_installed = {
|
||||
"phpactor",
|
||||
},
|
||||
})
|
||||
|
||||
lspconfig.phpactor.setup({
|
||||
capabilities = require("config/lsp/lsp-capabilities"),
|
||||
on_attach = require("config/lsp/lsp-attach"),
|
||||
})
|
||||
|
||||
mason_tool_installer.setup({
|
||||
ensure_installed = {
|
||||
"php-cs-fixer",
|
||||
"phpcs",
|
||||
},
|
||||
})
|
||||
|
||||
conform.setup({
|
||||
formatters_by_ft = {
|
||||
php = { "php-cs-fixer" },
|
||||
},
|
||||
format_on_save = {
|
||||
async = false,
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
},
|
||||
})
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<leader>lf", function()
|
||||
conform.format({
|
||||
async = false,
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
})
|
||||
end, { desc = "Format" })
|
||||
|
||||
lint.linters_by_ft = {
|
||||
phpcs = { "phpcs" },
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||
callback = function()
|
||||
lint.try_lint()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "<leader>ll", function()
|
||||
lint.try_lint()
|
||||
end, { desc = "Lint" })
|
||||
Reference in New Issue
Block a user