-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
Formatting after VS Code find and replace is using wrong file content #3040
Comments
I have not been able to replicate this issue on plugin version v9.19.0, but since it's intermittent, it's hard to know if this is actually fixed. Have there been updates that would fix this kind of issue? Maybe this one?
|
Setting the Prettier path in my VSCode user settings fixed this:
"prettier.prettierPath": "./node_modules/prettier", |
I see this consistently for certain find-and-replace in the latest version (10.1.0). From limited experimentation, it behaves correctly within a package but misbehaves across packages (e.g., find-and-replace affecting multiple package.json). To avoid the problem, I need to disable the plugin, then do find-and-replace, then re-enable. |
A little more investigating, I bisected to find that v9.14.0 behaves fine, while v9.15.0 misbehaves. The latter's release notes say:
And indeed I'm using Prettier 3.0.3. Again, what I'm checking is just find-and-replace, with auto-save and format-on-save enabled, across multiple |
By doing this I got the "Invalid host defined options" error in prettier output which lead me to #3100. So what seems to work is to set prettierPath like described in this comment: - "prettier.prettierPath": "./node_modules/prettier",
+ "prettier.prettierPath": "./node_modules/prettier/index.cjs", |
None of this worked for me. I ended up removing the prettier extension. VS Code still seems to do format on save correctly, I guess it has a built-in prettier? |
The default formatter for js/ts is "vscode.typescript-language-features" and it does in fact some formatting but it's very limited. Also (especially if nothing worked for you) you might need to reload the window to apply the new settings (F1, Reload Window). If you want to see what's working for me with both prettier and eslint : https://github.com/cahnory/pnpm-monorepo/blob/template-base/.vscode/settings.json |
Thanks for that. I’ll try it. I did reload/quit/restart etc |
This issue from VS Code (closed to be them thinking its a prettier issue) has more details, and robust reproduction steps. I just got bit by this issue again today with version 10.1.0 of the extension and version 3.0.3 of the npm package: As noted there, the issue is specifically an interaction between format on save, multi file find and replace, and prettier: remove any of those and the problem goes away. This issue, with the proper repro, is determinstic, and at least portable across some machines (I was able to produce the same issue on my desktop and on a github codespace (though both are ubuntu variants). The issue is somewhat impacted by accumulated state as reloading the window before producing the issue impacts what content gets dumped into the broken files (in my case the config file path to prettier instead of a different files contents) which makes this really seems like a use after free or use before initialization issue. I hit this a lot, and its often quite damaging. As a workaround try and turn on format on save before doing fine and replace, but sometimes I forget and have to revert all my local changes to recover. |
Based on this, I think the find and replace multi file case is formatting multiple files at once, and sharing or not synchronizing a buffer somewhere correctly. |
The relevant PR is likely #3016 authored by @sosukesuzuki and approved by @fisker and @ntotten . Maybe one of them can get to the bottom of this. I do love the performance of parallelization like that (thanks for the feature!), but I fear it might have a bug. |
This issue has been labeled as stale due to inactivity. Reply to keep this issue open. |
FWIW I'm still running into this issue as (microsoft/vscode#192617 (comment)) so I think this should be kept open. |
I agree, this should be reopened. We are also still experiencing this issue. |
Just adding one to the pile, I also seem to still be experiencing this behavior |
Tried to hold myself to a thumbs up... but I keep encountering this so commenting to hopefully get some more attention. |
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. |
Summary
When running VS Code find and replace across multiple files, with format on save enabled, the full file content is sometimes replaced with the content of a different file. This seems to only happen when the workspace includes multiple packages, each with their own installation of Prettier, and there are files being changed via find and replace in more than one package. Observed on both Windows and mac.
Github Repository to Reproduce Issue
https://github.com/bob-difronzo/prettier-plugin-repro
Steps To Reproduce:
Expected result
Each of the files should have the same content as before, with only "1.0.0" replaced with "2.0.0".
Actual result
Sometimes, files in one package are replaced with files from another package. For example,
pkg-b/package.json
may have it's full contents replaced with the contents ofpkg-a/package-lock.json
.Additional information
Screenshots
VS Code Version:
Version: 1.79.2 (user setup)
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:57:04.379Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.22621
and
Version: 1.79.2 (Universal)
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:52.392Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin x64 21.6.0
Prettier Extension Version:
v9.15.0 (with Prettier v2.8.8) for both OSes
and
v9.16.0 (with Prettier v3.0.0-alpha.12) on Windows (not tested on macOS)
OS and version:
Windows 11 Enterprise 22H2 with WSL2 Ubuntu 20.04.5 LTS
and
macOS Monterey 12.6.6
Prettier Log Output
Output from run for v9.15.0 on Windows with WSL:
Output from run for v9.16.0 on Windows with WSL:
The text was updated successfully, but these errors were encountered: