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

Commands sent to terminal gets swallowed by previous command #67693

Closed
DonJayamanne opened this issue Jan 31, 2019 · 11 comments
Closed

Commands sent to terminal gets swallowed by previous command #67693

DonJayamanne opened this issue Jan 31, 2019 · 11 comments
Assignees
Labels
info-needed Issue requires more information from poster terminal Integrated terminal issues

Comments

@DonJayamanne
Copy link
Contributor

  • 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.
  • Run python file in terminal
    • Open python file , right click and use the menu option Run Python file in terminal
    • The terminal will now open automatically
    • Python Extension will send the text pipenv shell to activate the environment in the terminal
    • The python extension will send the text <python interpreter> <file name> to the terminal
    • Unfortunately there's a race condition here, pipenv shell has not yet completed, and the commands sent later get swallowed up
  • End result, file doesn't run in terminal

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:

  • Python extension adds a delay between the two commands being sent to the terminal (this is what we do today). However pipenv shell takes longer than other activation routines, hence we need a much longer delay (i.e. a bigger magic number), a work around.
  • Or, VSC provides some api to let us know the terminal is ready to accept input.

Related to #67692

@vscodebot
Copy link

vscodebot bot commented Jan 31, 2019

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the terminal Integrated terminal issues label Jan 31, 2019
@DonJayamanne DonJayamanne changed the title Text sent to terminal gets swallowed by previous command Commands sent to terminal gets swallowed by previous command Jan 31, 2019
@Tyriar
Copy link
Member

Tyriar commented Feb 1, 2019

I think this sort of thing normally happens because the command you ran consumed the input and didn't do anything with it. It doesn't happen for all commands only a subset, for example when developing VS Code you can run yarn<enter>yarn watch and the yarn watch will execute. This is acting as designed in my eyes and we can't really provide a generic API that knows when something has finished running afaict.

There's is a proposed API which lets you listen to the stream coming into the terminal which would allow you to determine when your command has run by matching some expected output:

https://github.com/Microsoft/vscode/blob/1bcf2c77ca766f23b9227ce5d18da8b10c53c803/src/vs/vscode.proposed.d.ts#L892-L897

Disposing the listener after you're done with the init check is a good idea. Would this work?

@DonJayamanne
Copy link
Contributor Author

Great thanks, however we still have a problem with the debugger when using the terminal:

  • We tell VS Code to launch the debugger in a terminal
  • VS Code launcher a terminal to send the commands for debugging.
  • We detect a terminal being opened and send a command to the terminal
  • VS Code now sends the debugger commands to the terminal

Again, there's a race, VSC is sending text when the previous command sent by the extension has not completed.

There are a couple of solutions:

  • VSC accepts some pre-initialization commands (such as initialize environment, this way the extension doesn't have to intercept the creation of the environment)
  • Extension will have to first create a terminal, send the command and tell VSC to use this terminal instead of creating a new terminal
  • Extension doesn't use debugger protocol to launch terminals, we do that our selves, (feels like we're re-inventing the wheel here, e.g. building commands, etc..)

Any other suggestions?

@Tyriar
Copy link
Member

Tyriar commented Feb 13, 2019

  • VSC accepts some pre-initialization commands

This sounds promising, I'm not too familiar with how the debugger uses the terminal though.

@jamesstidard
Copy link

I believe I'm also seeing the same thing here. I've seen it for running debug configurations that try and use the integrated terminal and for installing linting packages from VCS popup prompts.

Using an external terminal seems to get around the issue for me currently for debugging.

Here's a youtube video where both the mypy linter install gets swallowed and the debugger.

@favna
Copy link

favna commented Apr 5, 2019

I also notice this but with a slightly different setup. First of all here is a video on streamable showing what happens

Now as for my setup:

  • yarn init to create a new NodeJS project
  • touch app.js create a simple app
  • Just add something super basic like console.log('bugs galore?') to app.js
  • Add a start script to your package.json
  • Run yarn start

This however only happens to me when my terminal is set to Git Bash and only happens on Windows. Git Bash itself however works perfectly fine normally. Further things to note:

  • Git For Windows v2.21.0 [install config: imgur album, I've also tried configuring differently)
  • VSCode version 1.33.0 (stable) (System Setup, though happens on User Setup as well)
  • Since I use yarn in the video, my yarn version is 1.15.2, Node version 11.13.0 and npm version 6.9.0.
  • The issue does not happen in regular Git Bash terminal or the Hyper terminal which I also have use Git Bash
  • The issue only seems to occur with yarn. Running npm start or node app.js does work.
    • While not as bad, running ng serve in my angular app does not clear the terminal as seen but the terminal does jump showing some commands from before I did a clear just before. So it's not entirely exclusive to yarn
    • It also seems to only happen when using the version installed with the ".msi" installer from their site, not when using one installed through npm i -g yarn

My VSCode settings concerning terminal are as follows (full config on gist here):

//...
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "terminal.integrated.env.windows": {"TERM": "cygwin"},
    "terminal.integrated.shellArgs.windows": ["--login"],
    "terminal.integrated.enableBell": true,
//...

@DonJayamanne
Copy link
Contributor Author

@Tyriar I can see the label needs more info is still here. Are you still waiting on some information from my end?

@DonJayamanne
Copy link
Contributor Author

@favna not sure how your issue is related to this.

@favna
Copy link

favna commented Apr 5, 2019

@DonJayamanne It seemed to be related in that from my understanding it was also that yarn was swallowing commands, assuming I even understood the concept correctly. I was going to create my own issue concerning the topic but I figured I should first search existing ones and so I landed here

@Tyriar
Copy link
Member

Tyriar commented Apr 12, 2019

@DonJayamanne is there anything beyond waiting on onDidWriteData to be stabilized for the terminal? You had debug issues but they should probably be handled in a separate issue.

@DonJayamanne
Copy link
Contributor Author

All is good, thanks.
Let's focus on debugger issue separately.

@Tyriar Tyriar closed this as completed Apr 16, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster terminal Integrated terminal issues
Projects
None yet
Development

No branches or pull requests

4 participants