Closed sentientmachin3 closed 1 year ago
I have the same question. Is it possible to override the config to look for the package.json at the git root?
For example, in my tsserver config I do;
root_dir = require("lspconfig").util.root_pattern(".git"),
@sockthedev inspecting the code I think it starts checking from the folder vim was opened in.
To change the condition for starting prettierd
server, you can do this:
prettier.setup({
bin = "prettierd", -- (v0.23.3+)
["null-ls"] = {
condition = function()
-- will always start
return true
-- will start if you open vim in a folder with `package.json` file
-- i.e. for javascript/typescript projects
return require("lspconfig.util").find_package_json_ancestor(vim.fn.getcwd())
end,
-- ...
},
-- ...
})
The important thing is that the function pass to condition
will only run once at startup. By default it checks if current working directory has prettier config file (.pretterrc*
, prettier.config.*
) or package.json
with "prettier"
key.
Note that, even if prettierd
server is not running, you can still execute :Prettier
command to format the file manually.
I hope that helps.
Hi, not really an issue, more like a how-does-it-work question.
I have a monorepo with the following setup:
I noticed when editing a file in the
root/package-a
path, the lsp does not format the code using prettier. I guess this happens because the plugin stops searching after the first package.json found, which does not contain the prettier entry, is this correct?Great job btw, works flawlessly.