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

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

Closed
bob-difronzo opened this issue Jun 22, 2023 · 17 comments
Closed
Labels
locked Please open a new issue and fill out the template instead of commenting. Stale

Comments

@bob-difronzo
Copy link

bob-difronzo commented Jun 22, 2023

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
pkg-b/package.json replaced with pkg-a/package-lock.json
pkg-b/package-lock.json replaced with pkg-a/package.json

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
Copy link
Author

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
Copy link

ciaran1344 commented Aug 15, 2023

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

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

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

@LukeNotable
Copy link

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
Copy link

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
Copy link

cahnory commented Nov 5, 2023

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
Copy link

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
Copy link

cahnory commented Nov 15, 2023

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
Copy link

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

@CraigMacomber
Copy link

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:
microsoft/vscode#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
Copy link

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
Copy link

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.

Copy link

github-actions bot commented Feb 5, 2024

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

@github-actions github-actions bot added the Stale label Feb 5, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@larsenwork
Copy link

FWIW I'm still running into this issue as (microsoft/vscode#192617 (comment)) so I think this should be kept open.

@dmbarry86
Copy link

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

@jdkula
Copy link

jdkula commented Mar 26, 2024

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

@ben-polinsky
Copy link

ben-polinsky commented May 8, 2024

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

Copy link

github-actions bot commented Aug 7, 2024

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.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label Aug 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting. Stale
Projects
None yet
Development

No branches or pull requests

10 participants