prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.15k stars 456 forks source link

Formatting after VS Code find and replace is using wrong file content #3040

Closed bob-difronzo closed 7 months ago

bob-difronzo commented 1 year ago

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:

  1. Open the search panel in VS Code.
  2. Type "1.0.0" in the "Search" input and "2.0.0" in the "Replace" input.
    • There should be 6 results across 4 files.
  3. Click the "Replace All" button.

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 of pkg-a/package-lock.json.

Additional information

Screenshots ![Find and replace](https://github.com/prettier/prettier-vscode/assets/66695241/d01a3183-75df-4288-8711-0c95ba88c07a) ![pkg-b/package.json replaced with pkg-a/package-lock.json](https://github.com/prettier/prettier-vscode/assets/66695241/ad8f0b61-694a-47c5-b69d-948970112d0b) ![pkg-b/package-lock.json replaced with pkg-a/package.json](https://github.com/prettier/prettier-vscode/assets/66695241/1d99801f-af60-4b56-9676-3029be9302c0)

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: ``` ["INFO" - 5:09:21 PM] Extension Name: esbenp.prettier-vscode. ["INFO" - 5:09:21 PM] Extension Version: 9.15.0. ["DEBUG" - 5:09:21 PM] Enabling Prettier globally { "languageSelector": [ { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["DEBUG" - 5:09:21 PM] Using bundled version of prettier. ["DEBUG" - 5:09:21 PM] Enabling Prettier for Workspace /home/difrr/dev/bug-repro/prettier-find-and-replace { "languageSelector": [ { "pattern": "/home/difrr/dev/bug-repro/prettier-find-and-replace/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,javascript,jsb,jscad,jsfl,jslib,jsm,jspre,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,cts,mts,tsx,importmap,json,4DForm,4DProject,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,code-snippets,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,json5,css,wxss,pcss,postcss,less,scss,handlebars,hbs,graphql,gql,graphqls,md,livemd,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,hta,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql}", "scheme": "file" }, { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["INFO" - 5:09:34 PM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package-lock.json ["INFO" - 5:09:34 PM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package.json ["INFO" - 5:09:34 PM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package-lock.json ["INFO" - 5:09:34 PM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package.json ["INFO" - 5:09:34 PM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/.prettierrc.json' ["DEBUG" - 5:09:34 PM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.js' ["INFO" - 5:09:34 PM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/.prettierrc.json' ["DEBUG" - 5:09:34 PM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.js' ["INFO" - 5:09:34 PM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/.prettierrc.json' ["DEBUG" - 5:09:34 PM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.js' ["INFO" - 5:09:34 PM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.js", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 0, "version": null } ["INFO" - 5:09:34 PM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/.prettierrc.json' ["DEBUG" - 5:09:34 PM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.js' ["INFO" - 5:09:34 PM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.js", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 0, "version": null } ["INFO" - 5:09:34 PM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 5:09:34 PM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["DEBUG" - 5:09:34 PM] Using prettier version 2.8.8 ["DEBUG" - 5:09:34 PM] Using prettier version 2.8.8 ["INFO" - 5:09:34 PM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.js", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 1, "version": "2.8.8" } ["INFO" - 5:09:34 PM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.js", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 1, "version": "2.8.8" } ["INFO" - 5:09:34 PM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 5:09:34 PM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 5:09:35 PM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 5:09:35 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 5:09:35 PM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package.json", "parser": "json-stringify" } ["INFO" - 5:09:35 PM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 5:09:35 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 5:09:35 PM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package-lock.json", "parser": "json-stringify" } ["INFO" - 5:09:35 PM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 5:09:35 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 5:09:35 PM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package-lock.json", "parser": "json-stringify" } ["INFO" - 5:09:35 PM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 5:09:35 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 5:09:35 PM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package.json", "parser": "json-stringify" } ["INFO" - 5:09:35 PM] Formatting completed in 380ms. ["INFO" - 5:09:35 PM] Formatting completed in 381ms. ["INFO" - 5:09:35 PM] Formatting completed in 452ms. ["INFO" - 5:09:35 PM] Formatting completed in 450ms. ["DEBUG" - 5:09:40 PM] Using bundled version of prettier. ["DEBUG" - 5:09:40 PM] Enabling Prettier for Workspace /home/difrr/dev/bug-repro/prettier-find-and-replace { "languageSelector": [ { "pattern": "/home/difrr/dev/bug-repro/prettier-find-and-replace/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,javascript,jsb,jscad,jsfl,jslib,jsm,jspre,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,cts,mts,tsx,importmap,json,4DForm,4DProject,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,code-snippets,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,json5,css,wxss,pcss,postcss,less,scss,handlebars,hbs,graphql,gql,graphqls,md,livemd,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,hta,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql}", "scheme": "file" }, { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["DEBUG" - 5:09:41 PM] Using bundled version of prettier. ["DEBUG" - 5:09:42 PM] Using bundled version of prettier. ["DEBUG" - 5:09:43 PM] Using bundled version of prettier. ```
Output from run for v9.16.0 on Windows with WSL: ``` ["INFO" - 10:44:24 AM] Extension Name: esbenp.prettier-vscode. ["INFO" - 10:44:24 AM] Extension Version: 9.16.0. ["DEBUG" - 10:44:24 AM] Enabling Prettier globally { "languageSelector": [ { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["DEBUG" - 10:44:34 AM] Using bundled version of prettier. ["DEBUG" - 10:44:34 AM] Enabling Prettier for Workspace /home/difrr/dev/bug-repro/prettier-find-and-replace { "languageSelector": [ { "pattern": "/home/difrr/dev/bug-repro/prettier-find-and-replace/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,javascript,jsb,jscad,jsfl,jslib,jsm,jspre,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,cts,mts,tsx,importmap,json,4DForm,4DProject,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,code-snippets,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,json5,css,wxss,pcss,postcss,less,scss,handlebars,hbs,graphql,gql,graphqls,md,livemd,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,hta,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql}", "scheme": "file" }, { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["INFO" - 10:44:44 AM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package-lock.json ["INFO" - 10:44:44 AM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package.json ["INFO" - 10:44:44 AM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package-lock.json ["INFO" - 10:44:44 AM] Formatting file:///home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package.json ["INFO" - 10:44:44 AM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/.prettierrc.json' ["DEBUG" - 10:44:44 AM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.cjs' ["INFO" - 10:44:44 AM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/.prettierrc.json' ["DEBUG" - 10:44:44 AM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.cjs' ["INFO" - 10:44:44 AM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/.prettierrc.json' ["DEBUG" - 10:44:44 AM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.cjs' ["INFO" - 10:44:44 AM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.cjs", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 0, "version": null } ["INFO" - 10:44:44 AM] Using config file at '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/.prettierrc.json' ["DEBUG" - 10:44:44 AM] Local prettier module path: '/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.cjs' ["INFO" - 10:44:44 AM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.cjs", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 0, "version": null } ["INFO" - 10:44:44 AM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 10:44:44 AM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["DEBUG" - 10:44:44 AM] Using prettier version 3.0.0-alpha.12 ["DEBUG" - 10:44:44 AM] Using prettier version 3.0.0-alpha.12 ["INFO" - 10:44:44 AM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/node_modules/prettier/index.cjs", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 1, "version": "3.0.0-alpha.12" } ["INFO" - 10:44:44 AM] PrettierInstance: { "modulePath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/node_modules/prettier/index.cjs", "importResolver": {}, "callMethodResolvers": {}, "currentCallMethodId": 1, "version": "3.0.0-alpha.12" } ["INFO" - 10:44:44 AM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 10:44:44 AM] Using ignore file (if present) at /home/difrr/dev/bug-repro/prettier-find-and-replace/.prettierignore ["INFO" - 10:44:44 AM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 10:44:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 10:44:44 AM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package.json", "parser": "json-stringify" } ["INFO" - 10:44:44 AM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 10:44:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 10:44:44 AM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package-lock.json", "parser": "json-stringify" } ["INFO" - 10:44:44 AM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 10:44:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 10:44:44 AM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-a/package-lock.json", "parser": "json-stringify" } ["INFO" - 10:44:44 AM] File Info: { "ignored": false, "inferredParser": "json-stringify" } ["INFO" - 10:44:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 10:44:44 AM] Prettier Options: { "filepath": "/home/difrr/dev/bug-repro/prettier-find-and-replace/pkg-b/package.json", "parser": "json-stringify" } ["INFO" - 10:44:44 AM] Formatting completed in 262ms. ["INFO" - 10:44:44 AM] Formatting completed in 262ms. ["INFO" - 10:44:44 AM] Formatting completed in 267ms. ["INFO" - 10:44:44 AM] Formatting completed in 264ms. ["DEBUG" - 10:44:44 AM] Using bundled version of prettier. ["DEBUG" - 10:44:47 AM] Using bundled version of prettier. ["DEBUG" - 10:44:47 AM] Enabling Prettier for Workspace /home/difrr/dev/bug-repro/prettier-find-and-replace { "languageSelector": [ { "pattern": "/home/difrr/dev/bug-repro/prettier-find-and-replace/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,javascript,jsb,jscad,jsfl,jslib,jsm,jspre,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,cts,mts,tsx,importmap,json,4DForm,4DProject,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,code-snippets,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,json5,css,wxss,pcss,postcss,less,scss,handlebars,hbs,graphql,gql,graphqls,md,livemd,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,hta,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql}", "scheme": "file" }, { "language": "javascript" }, { "language": "mongo" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "json5" }, { "language": "css" }, { "language": "postcss" }, { "language": "less" }, { "language": "scss" }, { "language": "handlebars" }, { "language": "graphql" }, { "language": "markdown" }, { "language": "mdx" }, { "language": "html" }, { "language": "vue" }, { "language": "yaml" }, { "language": "ansible" }, { "language": "home-assistant" }, { "language": "jsonc", "scheme": "vscode-userdata" } ], "rangeLanguageSelector": [ { "language": "javascript" }, { "language": "javascriptreact" }, { "language": "typescript" }, { "language": "typescriptreact" }, { "language": "json" }, { "language": "jsonc" }, { "language": "graphql" } ] } ["DEBUG" - 10:44:48 AM] Using bundled version of prettier. ```
bob-difronzo commented 1 year ago

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?

Reverts change to prettierPath resolution. (#3045)

ciaran1344 commented 1 year ago

Setting the Prettier path in my VSCode user settings fixed this:

~/Library/Application Support/Code/User/settings.json:

"prettier.prettierPath": "./node_modules/prettier",
LukeNotable commented 1 year ago

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.

LukeNotable commented 1 year ago

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:

Run Prettier in worker_threads for v3

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 package.json files.

cahnory commented 11 months ago

Setting the Prettier path in my VSCode user settings fixed this:

~/Library/Application Support/Code/User/settings.json:

"prettier.prettierPath": "./node_modules/prettier",

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",
ujwal-setlur commented 10 months ago

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?

cahnory commented 10 months ago

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

ujwal-setlur commented 10 months ago

Thanks for that. I’ll try it. I did reload/quit/restart etc

CraigMacomber commented 10 months ago

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: https://github.com/microsoft/vscode/issues/192617

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.

CraigMacomber commented 10 months ago

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:

Run Prettier in worker_threads for v3

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 package.json files.

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.

CraigMacomber commented 10 months ago

The relevant PR is likely https://github.com/prettier/prettier-vscode/pull/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.

github-actions[bot] commented 8 months ago

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

larsenwork commented 7 months ago

FWIW I'm still running into this issue as (https://github.com/microsoft/vscode/issues/192617#issuecomment-1792828446) so I think this should be kept open.

dmbarry86 commented 7 months ago

I agree, this should be reopened. We are also still experiencing this issue.

jdkula commented 6 months ago

Just adding one to the pile, I also seem to still be experiencing this behavior

ben-polinsky commented 5 months ago

Tried to hold myself to a thumbs up... but I keep encountering this so commenting to hopefully get some more attention.

github-actions[bot] commented 2 months ago

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.