neoclide / coc-prettier

Prettier extension for coc.nvim.
MIT License
546 stars 48 forks source link

Formatting output is not as expected #34

Open jrock2004 opened 5 years ago

jrock2004 commented 5 years ago

So I am trying to use this addon and I did a test to compare how it looks in VScode vs vim. Now maybe VScode is wrong but thought I would ask. So I typed the following:

if(1===1){

When I hit enter it was formatted to

if(1===1) {

}

If I do the same example in VScode I get

if (1 === 1) {

}

Notice how it added the space around the triple equal and between the if and (?

Here is my .prettierrc

{
  "bracketSpacing": true,
  "singleQuote": true,
  "trailingComma": "es5"
}

My project does have an .editorconfig

chemzqm commented 5 years ago

You need check https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel to make sure it's not formatted by other plugin like coc-tsserver

jrock2004 commented 5 years ago

Hmmm, so it seems like now its not even formatting for me. This is my coc-settings

{
  "suggest.enablePreview": true,
  "codeLens.enable": true,
  "git.addedSign.text": "┃",
  "git.removedSign.text": "┃",
  "git.changedSign.text": "┃",
  "git.changeRemovedSign.text": "┃",
  "suggest.maxPreviewWidth": 100,
  "diagnostic.checkCurrentLine": true,
  "diagnostic.maxWindowHeight": 20,
  "diagnostic.errorSign": "✖",
  "diagnostic.warningSign": "⚠",
  "diagnostic.infoSign": "●",
  "diagnostic.hintSign": "○",
  "coc.preferences.currentFunctionSymbolAutoUpdate": true,
  "git.addGlameToBufferVar": true,
  "prettier.requireConfig": true,
  "emmet.includeLanguages": {
    "html.handlebars": "html",
    "javascript": "javascriptreact"
  },
  "coc.preferences.formatOnType": true,
  "tailwindCSS.htmlLanguages": [
    "blade",
    "edge",
    "eelixir",
    "ejs",
    "elixir",
    "erb",
    "eruby",
    "haml",
    "handlebars",
    "html",
    "HTML (EEx)",
    "HTML (Eex)",
    "html.twig",
    "html.handlebars",
    "jade",
    "leaf",
    "markdown",
    "njk",
    "nunjucks",
    "php",
    "razor",
    "slim",
    "svelte",
    "twig",
    "vue"
  ]
}

If I highlight the text and run formatter it formats it correctly. So maybe on type is not supported?

jrock2004 commented 4 years ago

@chemzqm if I do echo coc#status() it says Prettier TSC. Is that correct?

jrock2004 commented 4 years ago

I wonder if format on type is using something different then when I grab a selection and format it

command! -nargs=0 Prettier :CocCommand prettier.formatFile
nmap <leader>f :CocCommand prettier.formatFile<cr>
vmap <leader>f <Plug>(coc-format-selected)
rgreenblatt commented 3 years ago

I wonder if format on type is using something different then when I grab a selection and format it

command! -nargs=0 Prettier :CocCommand prettier.formatFile
nmap <leader>f :CocCommand prettier.formatFile<cr>
vmap <leader>f <Plug>(coc-format-selected)

Possibly related to https://github.com/neoclide/coc-prettier/issues/37? I am running into an issue where a different formater is used for a section vs format all (for json). According to that issue, the problem is fixed on master.