how to confirm proper configuration
See original GitHub issueThank you for putting this together. Using “format on save” and the like is a big productivity gain for me. I’ve recently migrated to lsp… (like many). I’m still getting my “bearings”. I’m doing some work with css and html. I was using the online prettier parser and decided to see if I could get it running in nvim.
Prettierd is working (status running). I understand where the port and instance id are located to call it via a TCP request.
This said, in my nvim config I’m using the following documented snippet:
-- Prettier
local prettier = require("prettier")
prettier.setup({
bin = 'prettierd',
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
env = {string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/nvim/utils/linter-config/.prettierrc.json'))},
filetypes = {
"css", "graphql", "html", "javascript", "javascriptreact", "json", "less", "markdown", "scss", "typescript", "typescriptreact", "yaml"
},
})
As a “first go” I chose to use the null-ls
plugin as an interface:
--
-- Linters and formatters that do not have an LSP interface; use null-ls to
-- bridge the gap.
local null_ls = require("null-ls")
require("null-ls").setup({
capabilities = capabilities,
on_attach = on_attach,
sources = {
null_ls.builtins.diagnostics.flake8, -- python
null_ls.builtins.formatting.rustfmt, -- rust
null_ls.builtins.formatting.brittany, -- haskell
null_ls.builtins.diagnostics.yamllint, -- yaml
null_ls.builtins.formatting.prettierd -- fast prettier
-- null_ls.builtins.code_actions.eslint, -- html, css, js
}
})
The nvim :checkhealth
reports all is good with prettierd
:
null-ls: require("null-ls.health").check()
========================================================================
- ....
- OK: yamllint: the command "yamllint" is executable.
- OK: prettierd: the command "prettierd" is executable.
Yet, when I hit the <leader>f
command, I don’t see the css
“straighten-up” (i.e., clean-up the formatting).
The mapping is is used by many lsp:
-- bind conditional on server capabilities
if client.resolved_capabilities.document_formatting then
buf_set_keymap('n', '<Leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
elseif client.resolved_capabilities.document_range_formatting then
buf_set_keymap('n', '<Leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
Have I failed to “connect all the dots”? How can I tell that prettierd has been invoked when I call <leader>f
?
Thanks in advance for any pointers.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Brilliant minds think alike. Here is the link to the
prettier
issueOh interesting, do you have a link to the issue in the prettier repo? I can keep an eye on it and implement any option that they add in prettier.
If there’s a flag in prettier to skip the ignore file, we could eventually support it when #237 is resolved.