Use buffer language when formatting with Prettier#43368
Use buffer language when formatting with Prettier#43368SomeoneToIgnore merged 5 commits intozed-industries:mainfrom
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: John.
|
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Can you please provide more context on what's broken here, how to test the fix, etc.?
|
Hi, In my case I have json that gets stored in files like "feature.settings". UndefinedParserError: No parser could be inferred for file {path_to_file} So for a file like 'feature.settings': {
"foo": "foo",
"bar": "misformatted"
}Formatting would fail, even with the buffer language in Zed set to json. With this change, the prettier parser would be set explicitly using the buffer's language rather than inferred from the file extension. Cheers |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you for the context: sounds like this is quite a logic-related one, and we'd better have a test so it does not degrade later.
We have async fn test_document_format_with_prettier and other prettier tests, let's write another one for this scenario.
|
Hi, Sorry for the delay getting back to you. Long week :). I've added a new test I'm not entirely sure how to handle this, is there some way I can set my test up to run the code that I changed? Thanks |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you for the test, and no worries, I have other things to do anyway.
What if we adjust
let formatted_text = buffer.text() + FORMAT_SUFFIX; to write the parser name too?
That will require amending a few existing tests and restructuring the code of async fn format so that the common code for parser determination is shared between both test and real branches.
But after that, the code before the change should output a totally different value, which we can assert.
…ension does not match known file extensions for the buffer.
800bd35 to
cc22257
Compare
|
I've modified the test code to include the parser name and put the parser determination code in a closure used by both the real and test prettier code. |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Looking at the CI and the changes, this turned out to be the first test that uses Prettier parsers...
Thank you a lot for adding one.
I've left a few minor style nits and will be happy to merge this after today's release, just in case.
* main: (155 commits) Add support for git remotes (zed-industries#42819) python: Improve sorting order of toolchains to give higher precedence to project-local virtual environments that are within current subproject (zed-industries#44141) Use buffer language when formatting with Prettier (zed-industries#43368) search: Fix sort order not being maintained in presence of open buffers (zed-industries#44135) bedrock: Support global endpoints and new regional endpoints (zed-industries#44103) linux: Spawn at least two background threads (zed-industries#44110) macos: Add missing file access entitlements (zed-industries#43609) Re-colorize the brackets when the theme changes (zed-industries#44130) Reduce priority of Windows thread pool work items (zed-industries#44121) Update fancy-regex (zed-industries#44120) Prefer to disable options over hiding (git panel entry context menu) (zed-industries#44102) tab_switcher: Subscribe to workspace events instead of pane events (zed-industries#44101) editor: Add active match highlight for buffer and project search (zed-industries#44098) Add more preview tab settings and fix janky behavior (zed-industries#43921) ai: Add an eval for the inline assistant (zed-industries#43291) Fix circular reference issue around PopoverMenu again (zed-industries#44084) Run `git2::Repository::find_remote` in the background (zed-industries#44092) Improve support for multiple registrations of `textDocument/diagnostic` (zed-industries#43703) Revert "http_client: Add integrity checks for GitHub binaries using digest checks (zed-industries#43737)" (zed-industries#44086) editor: Fix blame hover not working when inline git blame is disabled (zed-industries#42992) ...
Set `prettier_parser` explicitly if the file extension for the buffer does not match a known one for the current language Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Set `prettier_parser` explicitly if the file extension for the buffer does not match a known one for the current language Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Set `prettier_parser` explicitly if the file extension for the buffer does not match a known one for the current language Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Set
prettier_parserexplicitly if the file extension for the buffer does not match a known one for the current languageRelease Notes: