Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin not working when multiple filetypes are loaded during buffer parsing #358

Open
omrisarig13 opened this issue Feb 17, 2025 · 0 comments

Comments

@omrisarig13
Copy link

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 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:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'prettier/vim-prettier'
Plugin 'sheerun/vim-polyglot'
call vundle#end()            " required

set nocompatible " 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.

@omrisarig13 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant