prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

Jump to end of file when formating huge JS file

Open x0vr opened this issue 2 years ago • 40 comments

Hi 👋

I think thi behavior occurs since ~Feb 2023. When I configure VSCode to use for instance "editor.defaultFormatter": "vscode.typescript-language-features" , the issue is gone.

I am using "Prettier - Code formatter" v9.10.4

Summary

When formating a huge JavaScript file in VSCode using Prettier as default formatter, everytime (most of the time?) I format the document the editor jumps to the end of the file (last line).

Steps To Reproduce:

  1. Open a huge / larger JavaScript file in VSCode
  2. Add some blank lines in the code
  3. Format document
  4. Editor jumps to end of file (last line)

Expected result

Document should be formatted and the line position in editor should not be changed.

Actual result

Editor jumps to end of file (last line)

Additional information

Feel free to attach a screenshot.

VS Code Version: 1.75.1

Prettier Extension Version: 9.10.4

OS and version: Win10

Prettier Log Output

["DEBUG" - 3:19:27 PM] Using bundled version of prettier.
["INFO" - 3:19:30 PM] Formatting file:///d%3A/__GIT/_testing/debug/test.js
["DEBUG" - 3:19:30 PM] Using bundled version of prettier.
["INFO" - 3:19:30 PM] Using ignore file (if present) at d:\__GIT\_testing\.prettierignore
["INFO" - 3:19:30 PM] File Info:
{
  "ignored": false,
  "inferredParser": "babel"
}
["INFO" - 3:19:30 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 3:19:30 PM] Prettier Options:
{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "singleAttributePerLine": false,
  "bracketSameLine": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 180,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": true,
  "tabWidth": 4,
  "trailingComma": "es5",
  "useTabs": true,
  "vueIndentScriptAndStyle": false,
  "filepath": "d:\\__GIT\\_testing\\debug\\test.js",
  "parser": "babel"
}
["INFO" - 3:19:31 PM] Formatting completed in 495ms.

Thanks for checking 👍

x0vr avatar Feb 27 '23 14:02 x0vr

Experiencing this as well with the same setup. Had to disable the prettier extension until this is fixed.

rotten-bmiller avatar Mar 03 '23 16:03 rotten-bmiller

I have the same situation

kongku avatar Mar 08 '23 04:03 kongku

Same issue but with an HTML file, not only JS

DeoThemes avatar Mar 12 '23 09:03 DeoThemes

Same issue, size limit seems to be ~100 KB for JS files.

Had this issue with a JS file of 101 KB, problem vanished after refactoring it to 97 KB.

Maybe this is a feature and not a bug, enticing us to use smaller files 😄

ralfhandl avatar Mar 16 '23 14:03 ralfhandl

I had the same problem 😩

wangstar615 avatar Apr 20 '23 06:04 wangstar615

Yep this issue still exists. It's kinda annoying. I had to disable format on save because of this. Is there an estimated date of fixing?

sbikosfp avatar Apr 26 '23 17:04 sbikosfp

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

github-actions[bot] avatar Jun 26 '23 02:06 github-actions[bot]

Issue still exists, workaround is keeping source files small, which is somewhat painful if I just want to add another test case that thematically belongs into the file that would get too large.

ralfhandl avatar Jun 26 '23 07:06 ralfhandl

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

github-actions[bot] avatar Aug 27 '23 02:08 github-actions[bot]

Issue still exists

ralfhandl avatar Aug 28 '23 07:08 ralfhandl

issue still exists

mustafa-colakoglu avatar Sep 21 '23 13:09 mustafa-colakoglu

Hi guys, I found this may be a fix, paste this in the settings.json.

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},

bookmountain avatar Nov 02 '23 06:11 bookmountain

yes, very annoying issue

syvuilliot avatar Nov 07 '23 16:11 syvuilliot

Hi guys, I found this may be a fix, paste this in the settings.json.

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},

doesn't work for me

syvuilliot avatar Nov 07 '23 16:11 syvuilliot

Hi guys, I found this may be a fix, paste this in the settings.json.

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},

doesn't work for me

Hi, can you try "endOfLine": "auto"

mustafa-colakoglu avatar Nov 08 '23 08:11 mustafa-colakoglu

Hi guys, I found this may be a fix, paste this in the settings.json.

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},

doesn't work for me

Hi, can you try "endOfLine": "auto"

I tried with following settings "eslint.codeActionsOnSave.mode": "problems", "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "prettier.endOfLine": "auto"

but always the same behaviour on large files with cursor moving to end of file :-(

syvuilliot avatar Nov 08 '23 08:11 syvuilliot

Hi guys, I found this may be a fix, paste this in the settings.json.

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},

doesn't work for me

Hi, can you try "endOfLine": "auto"

I tried with following settings "eslint.codeActionsOnSave.mode": "problems", "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "prettier.endOfLine": "auto"

but always the same behaviour on large files with cursor moving to end of file :-(

Hi, my configurasyon file I just added endOfLine auto and fixed, I did not add other configurations. Maybe you should remove other configurations

mustafa-colakoglu avatar Nov 08 '23 08:11 mustafa-colakoglu

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

github-actions[bot] avatar Jan 08 '24 01:01 github-actions[bot]

Issue still exists, and is still annoying.

ralfhandl avatar Jan 08 '24 08:01 ralfhandl

The limit of 100kb (100,000 bytes) seems to be hardcoded in VSCode here.

It would be nice if there was a setting to increase this.

Infinite-3D avatar Jan 28 '24 17:01 Infinite-3D

Still exists. Super annoying.

cjbeattie avatar Jan 31 '24 02:01 cjbeattie

Still Happening

inbflat avatar Feb 11 '24 18:02 inbflat

Still happening (up)

costaluu avatar Feb 21 '24 17:02 costaluu

Having this issue too, extension is basically unusable right now :'(

jacksonthall22 avatar Feb 21 '24 21:02 jacksonthall22

The behavior can be reproduced with this document, for example: https://github.com/turbulenz/turbulenz_engine/blob/master/tslib/canvas.ts

-> Just add a line at the beginning and format document => Editor jumps to eof

x0vr avatar Feb 22 '24 21:02 x0vr

I think this is a VSCode issue rather than a Prettier one. The same thing happens with other formatters such as CSharpier and the 100k limit is hardcoded in VSCode itself.

Infinite-3D avatar Feb 29 '24 16:02 Infinite-3D

How is this still an ongoing thing? I have tried adjusting my settings.json with no luck. I'm moving to Zed, lol

arcnid avatar Feb 29 '24 17:02 arcnid

I was able to fix this by setting End of line to auto in prettier settings.

inbflat avatar Feb 29 '24 21:02 inbflat

Seems like none of these fixes work, would be useful to be able to extend the size limit for files...

Droniukas avatar Mar 19 '24 06:03 Droniukas

Same problem here...

vital487 avatar Mar 19 '24 09:03 vital487