You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue I'm experiencing occurs when I want to run the Prettier command on markdown files which contains code-snippets.
In my vim setup, in addition to vim-prettier, I'm also using vim-polyglot - for better syntax highlighting.
One of the nice features of vim-polyglot for markdown is syntax highlighting for code snippets in the file (so, I can see the code snippets highlighted correctly). It is done in vim-polyglot by detecting the different code snippets available, and loading the relevant syntax highlighting for them (done here in the codebase).
The way that vim-prettier decides about the current file type is by using ftdetect, and setting the value of prettier_ft_default_args:parser from there (here, for example).
Because my vim is loading other snippets (json, for example), when this snippet is loaded, vim-prettier overwrite the value of prettier_ft_default_args:parser to be json, even though the file type is still markdown. This causes the Prettier command to try and run as if the buffer is json file, which causes it to fail.
It is important to note that vim still knows that the file is a markdown file (set ft? -> filetype=markdown).
Steps to reproduce
Have vim-prettier and vim-polyglot enabled in vimrc:
setrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()
Plugin'prettier/vim-prettier'Plugin'sheerun/vim-polyglot'callvundle#end()" requiredsetnocompatible" Allow vim to behave differently from Vi, to use more features of it
Write a simple markdown file, with a code snippet:
# Some markdown
text text
```json
{
"my object": "my value"
}
```
Run Prettier:
Prettier
Prettier: failed to parse buffer
By adding some debug-prints to vim-prettier, I found out that it uses prettier_ft_default_args = {'parser': 'markdown'}.
As described above.
Possible solution
By changing the plugin to check the file-type (run set ft? for example) instead of load this value through an ftdetect option, this issue will completely disappear.
I don't know why this decision was made to start up, so I'm not sure if there are more utilities to the ftdetect solution.
If you agree with my suggestion, I'd be happy to send a pull request.
What version of vim-prettier are you using - (output of :PrettierVersion) ?
1.0.0
What version of prettier are you using - (output of :PrettierCliVersion) ?
3.4.2 (not relevant here)
What is your prettier executable path - (output of :PrettierCliPath) ?
prettier (not relevant here)
Did this work in previous versions of vim-prettier and/or prettier ?
Unknown
Related issues
This issue might be related to #331, but I'm unsure, as I'm not using the same languages, and not enough debug information is provided there.
The text was updated successfully, but these errors were encountered:
omrisarig13
changed the title
Not working when loading multiple file-types
Plugin not working when loading multiple file-types during buffer parsing
Feb 17, 2025
omrisarig13
changed the title
Plugin not working when loading multiple file-types during buffer parsing
Plugin not working when multiple filetypes are loaded during buffer parsing
Feb 17, 2025
omrisarig13
pushed a commit
to omrisarig13/vim-prettier
that referenced
this issue
Feb 18, 2025
Do you want to request a feature or report a bug?
Bug
What is the current/expected behavior?
The issue I'm experiencing occurs when I want to run the
Prettier
command on markdown files which contains code-snippets.In my vim setup, in addition to vim-prettier, I'm also using vim-polyglot - for better syntax highlighting.
One of the nice features of vim-polyglot for markdown is syntax highlighting for code snippets in the file (so, I can see the code snippets highlighted correctly). It is done in vim-polyglot by detecting the different code snippets available, and loading the relevant syntax highlighting for them (done here in the codebase).
The way that vim-prettier decides about the current file type is by using
ftdetect
, and setting the value ofprettier_ft_default_args:parser
from there (here, for example).Because my vim is loading other snippets (json, for example), when this snippet is loaded, vim-prettier overwrite the value of
prettier_ft_default_args:parser
to be json, even though the file type is still markdown. This causes the Prettier command to try and run as if the buffer is json file, which causes it to fail.It is important to note that vim still knows that the file is a markdown file (
set ft?
->filetype=markdown
).Steps to reproduce
Have vim-prettier and vim-polyglot enabled in vimrc:
Write a simple markdown file, with a code snippet:
Run
Prettier
:By adding some debug-prints to vim-prettier, I found out that it uses
prettier_ft_default_args
={'parser': 'markdown'}
.As described above.
Possible solution
By changing the plugin to check the file-type (run
set ft?
for example) instead of load this value through anftdetect
option, this issue will completely disappear.I don't know why this decision was made to start up, so I'm not sure if there are more utilities to the
ftdetect
solution.If you agree with my suggestion, I'd be happy to send a pull request.
What version of
vim-prettier
are you using - (output of:PrettierVersion
) ?1.0.0
What version of
prettier
are you using - (output of:PrettierCliVersion
) ?3.4.2 (not relevant here)
What is your
prettier
executable path - (output of:PrettierCliPath
) ?prettier (not relevant here)
Did this work in previous versions of vim-prettier and/or prettier ?
Unknown
Related issues
This issue might be related to #331, but I'm unsure, as I'm not using the same languages, and not enough debug information is provided there.
The text was updated successfully, but these errors were encountered: