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

Auto-format adds and removes a semi-colon #146910

Closed
ripperdoc opened this issue Apr 6, 2022 · 3 comments
Closed

Auto-format adds and removes a semi-colon #146910

ripperdoc opened this issue Apr 6, 2022 · 3 comments
Assignees
Labels
*caused-by-extension Issue identified to be caused by an extension

Comments

@ripperdoc
Copy link

ripperdoc commented Apr 6, 2022

Issue Type: Bug

I haven't succeeded in creating a complete reproduction of this issue. What happened is this: as I was editing a source file, I noticed that every time I saved, an additional semi-colon was added after a function. At some point it would create one new semicolon after each save, stacking them up and generating syntax error. Currently, it just switches between adding an extra semi-colon, and then removing it on next save.

This only appears on a particular function. I have Prettier as formatter, but this error doesn't happen if I run Prettier separately from the command pallette, only when saving. I checked the Format on Save settings and the error only appears if set to modifications or modificationsIfAvailable, not on full. So this tells me the error happens because some interplay between the change in this file vs what's in Git. Maybe the diff that extracts only the modified lines plays poorly with the Prettier formatter?

If I copy the same code to another file, the issue doesn't appear, which makes sense as there is not Git history for it to use. I can send the full before and after source if needed but I would prefer to keep it private. See below for a screencap in diff mode when I save several times, it adds and then removes and then adds semicolon.

Screen.Recording.2022-04-06.at.13.49.36.mov

VS Code version: Code 1.66.0 (e18005f, 2022-03-30T05:50:04.419Z)
OS version: Darwin x64 18.7.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz (8 x 2600)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 3
Memory (System) 16.00GB (0.39GB free)
Process Argv --crash-reporter-id f38762bb-c266-463a-bc0c-77d8ce21e900
Screen Reader no
VM 0%
Extensions (39)
Extension Author (truncated) Version
better-toml bun 0.3.2
vscode-svgviewer css 2.0.0
vscode-eslint dba 2.2.2
unity-debug dei 3.0.11
gitlens eam 12.0.5
vscode-front-matter eli 7.0.0
prettier-vscode esb 9.5.0
php-intellisense fel 2.3.14
foam-vscode foa 0.17.8
vscode-nginx-conf-hint han 0.3.0
vscode-mocha-test-adapter hbe 2.13.3
vscode-test-explorer hbe 2.21.1
vscode-edit-csv jan 0.6.8
vscode-styled-components jpo 1.7.0
vscode-gutter-preview kis 0.30.0
vscode-markdown-notes kor 0.0.24
nodejs-repl los 0.5.15
AWK lug 0.0.2
rainbow-csv mec 2.2.0
vscode-docker ms- 1.21.0
csharp ms- 1.24.3
python ms- 2022.4.0
vscode-pylance ms- 2022.3.4
jupyter ms- 2022.3.1000901801
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.6
hexeditor ms- 1.9.5
test-adapter-converter ms- 0.1.5
autodocstring njp 0.6.1
view-in-browser qin 0.0.5
vscode-coverage-gutters rya 2.9.1
jinjahtml sam 0.17.0
markdown-link-expander skn 0.2.1
rewrap stk 1.16.3
markdown-links tch 0.8.0
shellcheck tim 0.19.0
vscode-counter uct 3.0.3
php-debug xde 1.25.0
markdown-all-in-one yzh 3.4.0

(2 theme extensions excluded)

A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
pythonvsnew555:30457759
vscscmwlcmt:30465135
pynewfile477:30463512

@jrieken
Copy link
Member

jrieken commented Apr 6, 2022

It looks like the issue is caused by one of your installed extensions. All extensions execute together on a single nodejs process, so in order to narrow down the possible problematic extension, please try the following:

  • run F1 > Help: Start Extension Bisect
  • (this will restart VS Code with half of your extensions disabled)
  • try to do the steps which reproduce the problem
  • if the problem reproduces, click "This is bad" (this narrows down the problematic extension to the half which was enabled)
  • if the problem does not reproduce, click "Good now" (this narrows down the problematic extension to the half which was disabled)
  • these steps will repeat until the problematic extension is found
initial step final
image image image

@ripperdoc
Copy link
Author

ripperdoc commented Apr 6, 2022

Thanks! I've completed the Bisect and as suspected it was Prettier, but it only happens when VS Code is set to auto-format on save by "editor.formatOnSaveMode": "modificationsIfAvailable" or "editor.formatOnSaveMode": "modifications", NOT when "editor.formatOnSaveMode": "file".

@jrieken
Copy link
Member

jrieken commented Apr 6, 2022

Thanks a great find. Closing this issue and asking you to raise it issue against prettier. Format on save with modificationsIfAvailable is technically the same as format selection, e.g it uses the same underlying API (DocumentRangeFormattingEditProvider), and when formatting results are wrong it's usually an issue with the extension

@jrieken jrieken closed this as completed Apr 6, 2022
@jrieken jrieken added the *caused-by-extension Issue identified to be caused by an extension label Apr 6, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*caused-by-extension Issue identified to be caused by an extension
Projects
None yet
Development

No branches or pull requests

2 participants