hoangKnLai / vscode-ipython

VSCode Extension integrating Editor with IPython console.
MIT License
18 stars 6 forks source link

Code sent to ipython console not handling new line properly #8

Closed austinjtravis closed 2 years ago

austinjtravis commented 2 years ago

When sending a command to the ipython console the new line escape sequence is not being handled properly. This leads to the editor sending the desired command plus and additional new line to the ipython terminal. To execute the command you need to enter a new line manually in the ipython terminal.

Steps to reproduce

  1. Create temporary file debug.py
  2. Launch ipython terminal in vscode
  3. Put some code in debug.py
    • I put print('this has issues')
  4. Run file
    image
    • Verify there the command was not executed
  5. Switch cursor to ipython terminal and hit the Enter button on keyboard
  6. Verify after hitting enter command executes
    image

Potential fixes

It seems adding a new line to the end of the command is not the proper escape sequence. Might make sense to change https://github.com/hoangKnLai/vscode-ipython/blob/main/src/extension.ts#L21 to let newLine: string = ' \';.

In the ipython terminal in vscode trying: %run c:\<path>\debug.py \ seems to give me the desired behavior
image

hoangKnLai commented 2 years ago

Added \ suggestion fix in v2022.4.1 for runFile function. Unfortunately this does not work with other sendText options (appears to work with %run magic command only.

Also change text termination using hex code \x0A for Enter key instead of CRLF. Hopefully this fixes it.

hoangKnLai commented 2 years ago

Remove the \ to %run command. I've tried to increase the execution lag time to 256msec and also instruct sendText to always include a addNewLine together with the Enter key press hex code.

sendText header says:

Send text to the terminal. The text is written to the stdin of the underlying pty process (shell) of the terminal.

Anyhow, the execution problem might also be something wrong in IPython overloading the terminal pty process and the stdin is not written correctly by VSCode. An update to the IPython build may fix it.

hoangKnLai commented 2 years ago

Found problem potentially in IPython v8.2.0 compare to v7.28.0. Prior testing suggests older version of IPython is working while newer is not. Will have to debug this more closely.

austinjtravis commented 2 years ago

Fixed with most recent commit.