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

vscode format on save on big file cursor alway jump to the end of the file #2920

Open
Kyrosee opened this issue Mar 22, 2023 · 11 comments
Open
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.

Comments

@Kyrosee
Copy link

Kyrosee commented Mar 22, 2023

Format on save on big js file(3700lines), cursor alway jump to the end of the file
prettier version 9.10.4
vscode 1.76.2

@madc0w
Copy link

madc0w commented Mar 23, 2023

I can confirm that this is a real issue, and it's driving me nuts.
Same prettier & vscode versions as the OP.

The precise file size at which this behavior begins occurring is 100002 bytes. That is, formatting a file with 100001 bytes is fine, but adding one more byte breaks prettier. At least, this is true for a Javascript file. I've not tested other types.

Here is my test. (I had to put it in a zip file, since the .js extension is not an allowed type for attaching.)
test.zip

@foaudkajj
Copy link

+1 having the same problem.

@marekcambal
Copy link

yes, I can confirm the same issue
file being edited has ~3600 lines

vscode 1.76.2
prettier version 9.10.4

setting source.organizeImports to false prevents cursor jumping to EOF

"editor.codeActionsOnSave": {
    "source.organizeImports": false,
  },

@foaudkajj
Copy link

foaudkajj commented Mar 24, 2023

@marekcambal, please be aware that changing the setting only fixes the problem that happens while saving the file (with save on format flag is true).
When the file is formatted with alt+shift+f combination, the cursor is jumping to the EOF.

@VanguardaSistemas
Copy link

Same issue here

@ValentinLeTallec
Copy link

Same here, except that with

  • a ~5000 lines file
  • vscode 1.77.3
  • prettier 9.10.4

marekcambal's workaround did not work for me

@ntotten ntotten added enhancement help-wanted Not something we plan on doing, but we will take a pull request. labels Apr 21, 2023
@dnjat
Copy link

dnjat commented Jul 9, 2023

+1 crazy

@hdrodel
Copy link

hdrodel commented Aug 2, 2023

Having the same issue. Is there a workaround for this ?

@dnjat
Copy link

dnjat commented Aug 16, 2023

bug +1. this is bug,no enhancement

@liboz
Copy link

liboz commented Aug 20, 2023

I was able to determine that the bug was introduced in 9.5. Reverting to version 9.4 fixes the issue. Looking at the commit log, be790ca seems very suspect.

I changed the mode locally to just modifications but then prettier doesn't run at all. I'm guessing that the algorithm to get only the modified part is too costly to run for very large files. Though that doesn't quite make sense either as manually using the format is still fast (~180ms). VS code might just be having issues for whatever reason for very large files on modification only changes.

The solution is probably to only use the "new" algorithm when the setting is enabled.

But for now reverting to 9.4 will work and that's what I've done.

@ntotten @rotu

@rotu
Copy link
Contributor

rotu commented Aug 20, 2023

I was able to determine that the bug was introduced in 9.5. Reverting to version 9.4 fixes the issue. Looking at the commit log, be790ca seems very suspect.

I don't remember exactly why my change allows range formatting to work. I think it was because prettier always reports that it changed the entire file and this would overlap with some other edit ranges from somewhere else. VSCode would see the conflicting edits and bail.

Because of @madc0w's analysis, I searched for "100000", in VSCode, and this looks like a contributing factor: https://github.com/microsoft/vscode/blob/f125afbc800ec611f5a9ab1333c769832ce424b3/src/vs/editor/common/services/editorSimpleWorker.ts#L492

Looking at the blame, that line was last changed to fix vscode#72321 and the discussion there seems very relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.
Projects
None yet
Development

No branches or pull requests