Closed petertriho closed 3 years ago
Changed to using $HOME instead of ~ fixed this for me
@petertriho Sorry for the noob question... but how did you set the environment variable?
Hi @zeitchef, it depends on what you're using to invoke prettierd. If you're using efm + lua + nvim-lsp, you'd need something like this:
local prettier = {
formatCommand = 'prettierd ${INPUT}',
formatStdin = true,
env = {
'PRETTIERD_DEFAULT_CONFIG=/home/myuser/.config/nvim/utils/linter-config/.prettierrc.json',
},
}
(this was adapted from the readme)
@fsouza Thanks for your speedy response! I'm trying to use formatter.nvim
and it's somehow not clear how to set it this way. I've tried a shell environment variable, but should it be in a global npm env? Somehow my results are exactly as described above, it only works if my config is in the same directory.
@fsouza Thanks for your speedy response! I'm trying to use
formatter.nvim
and it's somehow not clear how to set it this way. I've tried a shell environment variable, but should it be in a global npm env? Somehow my results are exactly as described above, it only works if my config is in the same directory.
Can you try the following (untested):
require('formatter').setup({
logging = false,
filetype = {
javascript = {
-- prettierd
function()
return {
exe = "env",
args = {"PRETTIERD_DEFAULT_CONFIG=<full-path>", "prettierd"; vim.api.nvim_buf_get_name(0)},
stdin = true
}
end
}
-- other formatters ...
}
})
(assuming you're on Linux/MacOS/WSL/some unix flavor, I don't think that would work on Windows)
Thanks @fsouza - this didn't seem to work for me, but it could well be a problem with formatter.nvim
as I was getting some error from the plugin.
I'd rather integrate with efm
anyway, so using your updated example in the README, this is how I'm setup:
// efm/prettierd.lua
return {
formatCommand = 'prettierd ${INPUT}',
formatStdin = true,
env = {
string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/prettierd/.prettierrc.json')),
}
}
// efm.lua
local prettierd = require 'efm/prettierd'
require'lspconfig'.efm.setup {
init_options = { documentFormatting = true },
filetypes = {'css', 'html', 'javascipt', 'json', 'markdown', 'sh', 'typescript', 'vue', 'yaml'},
settings = {
rootMarkers = { '.git', 'package.json' },
languages = {
javascript = { prettierd }
}
}
}
And here are my prettier
configs:
// .config/prettierd/.prettierrc.json
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
Now when I try to format using :lua vim.lsp.buf.formatting()
changes are being applied, the problem is that none of my configs are taken into account (ie. all quotes are double and semicolons are added). Clearly there is another config overriding it somehow.
What am I overlooking?
EDIT: I can also confirm that when the .prettierrc.json
is in the current directory, all works as expected.
@zeitchef thanks for the detailed information. I'll reopen this issue and try to reproduce it later.
@zeitchef You probably need to restart the prettierd process
ps aux | grep prettierd
kill <process number>
Thanks for the tip @petertriho - that seemed to fix it. @fsouza Thanks so much for all your help and hard work on this great project!
.prettierrc.json
Running
cat /tmp/test.yaml | prettierd test.yaml
(PRETTIERD_DEFAULT_CONFIG
environment variable set to where.prettierrc.json
is located) doesn't work but whentest.yaml
is in same directory as.prettierrc.json
it worksAlso doesn't work when I use the same config as https://github.com/fsouza/prettierd#editor-integration for efm-langserver + neovim lsp