microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.33k stars 1.19k forks source link

extra content inserted into terminal when running python file #23284

Open amunger opened 6 months ago

amunger commented 6 months ago

Testing #23272

unrelated to the TPI Close all terminal sessions, this doesn't seem to repro when another terminal is open. Clicking run file will run the file in the terminal, but also insert extra content on the next terminal input.

Recording 2024-04-23 at 09 24 11

karthiknadig commented 6 months ago

@Tyriar This seems like something to do with how terminal handles send text. All we are doing on the python extension side are constructing the execution command and doing a send text.

Tyriar commented 6 months ago

All we are doing on the python extension side are constructing the execution command and doing a send text.

Do you mean you're doing both executeCommand and sendText? You should only be doing the first.

karthiknadig commented 6 months ago

No, we just do sendText. What I meant was, we use the shell type to figure out which activation script to use and then send that script to the terminal via sendText

Here is where we do this: https://github.com/microsoft/vscode-python/blob/c04fa70a351427f7175bf78ba87c6206d9f5fed1/src/client/common/terminal/activator/base.ts#L14-L42

Tyriar commented 6 months ago

Enabling trace logging mode and checking the Terminal output channel will give some information about where the characters are coming from. For example typing "abc", see the sending data and parsing data lines:

2024-04-25 07:55:38.081 [debug] sending data "a" [[97]]
2024-04-25 07:55:38.115 [debug] parsing data "[?25lapplicationFrameHost.exe[?25h" [[27,91,63,50,53,108,27,91,57,51,109,97,27,91,57,55,109,27,91,50,109,27,91,51,109,112,112,108,105,99,97,116,105,111,110,70,114,97,109,101,72,111,115,116,46,101,120,101,27,91,54,59,52,72,27,91,63,50,53,104]]
2024-04-25 07:55:38.125 [debug] parsing data "" [[27,91,109]]
2024-04-25 07:55:38.167 [debug] TextAreaSyncAddon#sync: text changed to "applicationFrameHost.exe" []
2024-04-25 07:55:38.168 [debug] TextAreaSyncAddon#sync: text changed to "applicationFrameHost.exe" []
2024-04-25 07:55:38.405 [debug] sending data "b" [[98]]
2024-04-25 07:55:38.432 [debug] parsing data "abc" [[27,91,57,51,109,8,97,98,27,91,57,55,109,27,91,50,109,27,91,51,109,99,27,91,109,27,91,50,49,88,8]]
2024-04-25 07:55:38.487 [debug] TextAreaSyncAddon#sync: text changed to "abc" []
2024-04-25 07:55:38.488 [debug] TextAreaSyncAddon#sync: text changed to "abc" []
2024-04-25 07:55:38.802 [debug] sending data "c" [[99]]
2024-04-25 07:55:38.830 [debug] parsing data "[?25labc[?25h" [[27,91,63,50,53,108,27,91,57,51,109,27,91,54,59,51,72,97,98,99,27,91,63,50,53,104]]
2024-04-25 07:55:38.853 [debug] parsing data "" [[27,91,109]]
2024-04-25 07:55:38.882 [debug] TextAreaSyncAddon#sync: text changed to "abc" []
2024-04-25 07:55:38.883 [debug] TextAreaSyncAddon#sync: text changed to "abc" []