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

Jump to end of file when formating huge JS file #2883

Open
x0vr opened this issue Feb 27, 2023 · 38 comments
Open

Jump to end of file when formating huge JS file #2883

x0vr opened this issue Feb 27, 2023 · 38 comments
Labels

Comments

@x0vr
Copy link

x0vr commented Feb 27, 2023

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 👍

@rotten-bmiller
Copy link

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

@kongku
Copy link

kongku commented Mar 8, 2023

I have the same situation

@DeoThemes
Copy link

Same issue but with an HTML file, not only JS

@ralfhandl
Copy link

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 😄

@ntotten ntotten added the bug label Mar 25, 2023
@wangstar615
Copy link

I had the same problem 😩

@sbikosfp
Copy link

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?

@github-actions
Copy link

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 Jun 26, 2023
@ralfhandl
Copy link

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.

@github-actions github-actions bot removed the Stale label Jun 27, 2023
@github-actions
Copy link

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 Aug 27, 2023
@ralfhandl
Copy link

Issue still exists

@github-actions github-actions bot removed the Stale label Aug 29, 2023
@mustafa-colakoglu
Copy link

issue still exists

@bookmountain
Copy link

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

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
},
@syvuilliot
Copy link

yes, very annoying issue

@syvuilliot
Copy link

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

@mustafa-colakoglu
Copy link

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"

@syvuilliot
Copy link

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 :-(

@mustafa-colakoglu
Copy link

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

Copy link

github-actions bot commented Jan 8, 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 Jan 8, 2024
@ralfhandl
Copy link

Issue still exists, and is still annoying.

@github-actions github-actions bot removed the Stale label Jan 9, 2024
@Infinite-3D
Copy link

Infinite-3D commented Jan 28, 2024

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.

@cjbeattie
Copy link

Still exists. Super annoying.

@inbflat
Copy link

inbflat commented Feb 11, 2024

Still Happening

@costaluu
Copy link

Still happening (up)

@jacksonthall22
Copy link

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

@x0vr
Copy link
Author

x0vr commented Feb 22, 2024

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

@Infinite-3D
Copy link

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.

@arcnid
Copy link

arcnid commented Feb 29, 2024

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

@inbflat
Copy link

inbflat commented Feb 29, 2024

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

@Droniukas
Copy link

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

@vital487
Copy link

Same problem here...

@brendansiow
Copy link

I have the same issue but with Go's code, I have uninstalled prettier and turn off format on save, not working

@rschlack
Copy link

Same issue here. It's so annoying. I think it only happens on the Windows version of VSCode.

@temp4422
Copy link

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

Fix for me too.
In VSCode settings.json -> "prettier.endOfLine": "auto"

System info: macOS Sonoma 14.4, VSCode v1.87, Prettier v10.4.0

@FacundoBrum16
Copy link

don't work for me

@StevenCrocker
Copy link

So this seems to be the issue, at least in my testing. The end of line character in prettier setting must match the document end of line setting.

The end of line character for Prettier is defaults to "LF" if "prettier.endOfLine" isn't specifically set. You can set this to "auto", or you can update the document itself to use "LF" instead of "CRLF". Do this by searching for "Change End of Line Sequence" in the command prompt (CTRL+SHIFT+P). This can also be changed by clicking the CRLF text in the status bar.

Can anyone confirm?

@eduardoldev
Copy link

eduardoldev commented May 21, 2024

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

worked settings.json

@alonemanuel
Copy link

So this seems to be the issue, at least in my testing. The end of line character in prettier setting must match the document end of line setting.

The end of line character for Prettier is defaults to "LF" if "prettier.endOfLine" isn't specifically set. You can set this to "auto", or you can update the document itself to use "LF" instead of "CRLF". Do this by searching for "Change End of Line Sequence" in the command prompt (CTRL+SHIFT+P). This can also be changed by clicking the CRLF text in the status bar.

Can anyone confirm?

Fixed it for me

@PradipBakutra
Copy link

PradipBakutra commented Jun 25, 2024

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"

Yeah, i added
endOfLine: auto
in my .prettierrc file and it worked, thanks a lot man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment