microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
150 stars 35 forks source link

Editor jumps to new line after formatting #349

Closed willjhenry closed 11 months ago

willjhenry commented 11 months ago

After black has finished formatting, the editor window jumps to a new line. Sometimes it is just a few lines below, sometimes the very bottom of the file (could be hundreds of lines below). The cursor itself is often in the same position, but the editor window has paged down. Sometimes the cursor itself has jumped to a new location

karthiknadig commented 11 months ago

@willjhenry Try the pre-release version, it should have a fix for this.

willjhenry commented 11 months ago

awesome - thank you!

willjhenry commented 11 months ago

It still pages down ~one page, but it no longer jumps to the bottom of the file. Is this expected?

karthiknadig commented 11 months ago

The pre-release improves the case my doing narrow edits. But that is all that can be done from the extension. Further improvements for this behavior should be addressed in VS Code itself.

From the extension we don't really do anything other than telling the editor that the various edits needed to be done to the file as a result of formatting. VS Code chooses to move the cursor or scroll as it sees fit.

If you want to file a bug on VS Code, I recommend setting "python.trace.server": "verbose" in your user settings. This should capture the file and edits we send back to repro. Reproing the issue, and then share it with the logs.