Seamlessly handle re-loading Prettier if it has been changed
See original GitHub issueIs your feature request related to a problem? Please describe.
Currently if the version of Prettier inside of a project changes (typically from an npm
or yarn
install), the version the extension uses becomes stale, still using the version it initially cached, leading to changes on save that may not match what the Prettier CLI would output. As this point reloading the VS Code window is necessary in order to have the extension pick up the correct, new, version of Prettier and use it instead.
Describe the solution you’d like I think a working solution here would be to setup a file watcher for the found modules directory. If a change is made to any of those files / the directory itself, then we can invalidate the existing cache we have, allowing the next save to re-detect the module it should be using to run Prettier on the file.
Describe alternatives you’ve considered An alternative solution would be to add a command which can reset the cache on demand. This would be be slightly better than reloading the entire window, but would still need to be on demand, meaning you have to know you need to do it.
Additional context I’ve primarily hit this problem when rolling out a Prettier upgrade org-wide. People tend to upgrade their dependencies, then hit VS Code formatting things improperly and reach out for support. FWIW I’ve hit the same problem with the VS Code ESLint extension 😞.
Figured I’d toss up an issue for this for discussion @ntotten. I’ve also started a WIP branch so you can get a general sense of what I’m thinking about here: https://github.com/prettier/prettier-vscode/compare/master...JHilker:experiment-with-file-watching. It’s definitely a bit messy with debugging logic, but is for the most part fully functional (aside from the global module resolution logic) if you want to check it out locally. I’m also planning on adding tests before tossing up a PR if you think this is a change you’d like to see in the extension.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top GitHub Comments
Enable debug logs for the extension. I reduced the default logging.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.