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

Debugger commands sent to terminal get swallowed by previous terminal command #67692

Closed
DonJayamanne opened this issue Jan 31, 2019 · 6 comments
Assignees
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Jan 31, 2019

  • VSCode Version:Version 1.31.0-insider (1.31.0-insider)
  • OS Version:Mac

Steps to Reproduce:

  • Install latest version of Python Extension
  • Install python
  • Brew install pipenv
  • Open a folder in VSC
  • Add a python file with a simple print("Hello") statement
  • Open the terminal in VSC and type the command pipenv shell
    • This will create a virtual environment for the current folder
  • Open another terminal and notice how the Python extension will automatically add pipenv shell, causing the previously created environment to get activated in this new terminal.
  • Reload VSC
    • The above pipenv environment will now be automatically selected
    • If not, please use the command Select Python Interpreter
    • From the list, of interpreters select the interpreter with the name same as the folder name you are in.
  • Debug the python file
    • The terminal will now open automatically
    • Python Extension will send the text pipenv shell to activate the environment in the terminal
    • VSC Debugger sends the necessary commands to the terminal
    • Unfortunately there's a race condition here, pipenv shell has not yet completed, and the commands sent by VSC debugger get swallowed up
  • End result, debugger doesn't start

Causes:

  • There's no way to determine when terminal has completed processing previously sent commands.
  • VSC is sending messages to the terminal, when its busy

Solutions:

  1. Python extension can take complete control of opening terminals, etc and not use runInTerminal request (i.e. python extension re-invent the wheel).
  2. VSC DAP accepts additional commands that need to be invokved in the runInTerminal request.
    Currently we can only send args, how about extending this to send commands as well.
    This way the extension can send some custom commands that need to be executed before the VSC debugger commands. I.e. chain them together.
@Tyriar
Copy link
Member

Tyriar commented Feb 1, 2019

See #67693 (comment)

@Tyriar Tyriar assigned weinand and unassigned Tyriar Feb 1, 2019
@Tyriar Tyriar removed the terminal Integrated terminal issues label Feb 1, 2019
@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues bug Issue identified by VS Code Team member as probable bug labels May 20, 2019
@egamma egamma added this to the June 2019 milestone Jun 7, 2019
@weinand weinand modified the milestones: June 2019, July 2019 Jun 24, 2019
@brettcannon
Copy link
Member

To help kickstart this again, the two ideas we had today for solving our debugger issues (if you all would be so gracious as to implement one of them 😉 ) are:

  1. Provide a way for us to specify the terminal ID to have the debugger run into (so we can make sure the terminal is already activated for the Python virtual environment)
  2. Open up an API to the code that constructs the command that gets sent into the terminal (so we can dynamically construct a shell script of two lines -- one to activate, one to run the debugger - so everything is quoted appropriately in the shell script and then we have the terminal run the shell script to make sure everything completes appropriately serially)

@Tyriar
Copy link
Member

Tyriar commented Jul 10, 2019

I haven't really looked into DAP much, but I had a look at how runInTerminal works. You might be able to pass in this as the first arg in the args array to string together multiple commands?

  • Linux/macOS: sh -c "pipenv shell && debug"
  • Windows: cmd.exe /k ... or equivalent in PS

Also created #77110 and #77111 after looking into the feature.

@brettcannon
Copy link
Member

Will that quote what's in those quotes correctly? E.g. if one of the args that you need has a space will that get quoted appropriately in that string you pass to sh?

@Tyriar
Copy link
Member

Tyriar commented Jul 10, 2019

@brettcannon provided the quotes get escaped correctly in debug I would think so.

@weinand
Copy link
Contributor

weinand commented Jul 26, 2019

I've fixed issues #77110 and #77111, but they don't really help with the issue at hand.

As @Tyriar has pointed out in #67693 (comment), there is not much we can do here. His recommendation in #67692 (comment) is the way to go.

Quoting should work fine; if not, please file separate issues for them.

@weinand weinand closed this as completed Jul 26, 2019
@weinand weinand removed the bug Issue identified by VS Code Team member as probable bug label Jul 26, 2019
@weinand weinand removed this from the July 2019 milestone Jul 26, 2019
@weinand weinand added the *as-designed Described behavior is as designed label Jul 26, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

5 participants