diff --git a/nvim/dot-config/nvim/after/plugin/lspconfig.lua b/nvim/dot-config/nvim/after/plugin/lspconfig.lua index 51b02c0..a792ad2 100644 --- a/nvim/dot-config/nvim/after/plugin/lspconfig.lua +++ b/nvim/dot-config/nvim/after/plugin/lspconfig.lua @@ -4,6 +4,14 @@ if not ok then return end +local root_dir +for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do + if vim.fn.isdirectory(dir .. "/.git") == 1 then + root_dir = dir + break + end +end + local border = { { "┌", "FloatBorder" }, { "─", "FloatBorder" }, @@ -64,8 +72,16 @@ local on_attach = function(client, bufnr) end end +local function prettier_command() + if vim.fs.basename(root_dir .. "node_modules/prettier") then + return "npx prettier" + else + return "prettier" + end +end + local prettier = { - formatCommand = [[prettier --stdin-filepath ${INPUT} ${--tab-width:tab_width}]], + formatCommand = prettier_command() .. [[ --stdin-filepath ${INPUT} ${--tab-width:tab_width}]], formatStdin = true, } @@ -92,7 +108,7 @@ local shellcheck = { local servers = { efm = { - filetypes = { "typescript", "typescriptreact", "sh" }, + filetypes = { "typescript", "typescriptreact", "sh", "php" }, init_options = { documentFormatting = true }, settings = { rootMarkers = { ".git/" }, @@ -100,6 +116,7 @@ local servers = { typescript = { prettier, eslint }, typescriptreact = { prettier, eslint }, sh = { shellcheck }, + php = { prettier }, }, }, },