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

activeTerminal undefined for first terminal even when visible #106123

Closed
andycraig opened this issue Sep 4, 2020 · 3 comments
Closed

activeTerminal undefined for first terminal even when visible #106123

andycraig opened this issue Sep 4, 2020 · 3 comments
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label
Milestone

Comments

@andycraig
Copy link

When there are no terminals, and then a terminal is created and shown with the following code, the terminal is visible but vscode.windows.activeTerminal is still undefined. Once a second terminal has been created, activeTerminal works fine.

const myTerminal = vscode.window.createTerminal(`My Terminal #${NEXT_TERM_ID++}`);
myTerminal.show(true);
  • VSCode Version: 1.48.2
  • OS Version: Windows 10
  • Version: 1.48.2 (system setup)
  • Commit: a047975
  • Date: 2020-08-25T10:13:11.295Z
  • Electron: 7.3.2
  • Chrome: 78.0.3904.130
  • Node.js: 12.8.1
  • V8: 7.8.279.23-electron.0
  • OS: Windows_NT x64 10.0.18362

Steps to Reproduce:

To try to make a minimal reproducible example, I have made a small change to one of the Extension Samples. You can see my modification to the Microsoft version here: https://github.com/microsoft/vscode-extension-samples/compare/master...andycraig:master?expand=1

  1. Download/clone my version from https://github.com/andycraig/vscode-extension-samples/tree/master

  2. File -> Open Folder... -> vscode-extension-samples/terminal-sample

  3. Run -> Start Debugging

  4. Close existing terminal

  5. Command Terminal API: Create & Show Terminal

  6. Observe terminal appears, and message 'onDidOpenTerminal, name: My Terminal Open Source VS Code #1'

  7. Command Terminal API: Check activeTerminal

  8. Observe message 'activeTerminal is undefined'

    Unexpected, as 'My Terminal Open Source VS Code #1' is visible.

  9. Command Terminal API: Create & Show Terminal

  10. Observe terminal appears, and message 'onDidOpenTerminal, name: My Terminal gulp-symdest does not preserve links on electron #2'

  11. Command Terminal API: Check activeTerminal

  12. Observe message 'activeTerminal: My Terminal gulp-symdest does not preserve links on electron #2'
    This is as expected.

If 'My Terminal #2' is closed, activeTerminal correctly becomes 'My Terminal #1'. If this is closed, and the steps repeated, the message 'activeTerminal is undefined' will appear again.

Things DO work as expected if the terminal is created and shown with Terminal API: Create Terminal and Terminal API: Show, then verified with Terminal API: Check activeTerminal: this produces the message 'activeTerminal: Ext Terminal #1'. So it seems somehow specific to the code at the top of this issue.

Does this issue occur when all extensions are disabled?: Yes

I identified this while following up on a discussion at #105944. There are some activeTerminal issues that look related, like #53107, but I couldn't find one describing this problem.

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label labels Sep 4, 2020
@Tyriar Tyriar added this to the Backlog milestone Sep 4, 2020
@Tyriar Tyriar added the api label Nov 4, 2020
@cyrilletuzi
Copy link

I'm the author of the Angular Schematics extension (400 000+ users), and I'm also facing an issue with unreliable vscode.window.activeTerminal.

But the issue seems much larger than what is described here, for me the activeTerminal API is totally buggy.

For short, my extension is using a terminal to launch Angular CLI commands, and I would like to switch back to the previously active terminal (generally there will be a terminal with npm start / ng serve running) once it's done. See cyrilletuzi/vscode-angular-schematics#396

So I'm storing vscode.window.activeTerminal to show it back after, but the value is rarely right.

For example, if I open a terminal, launch any command (like echo 'world'), then open another terminal (with the "+" button), launch any command, then use my extension, the first terminal will be displayed back instead of the second.

Things get more and more messier if I delete terminals, add new ones, switch between them, etc.

Seems to me there is a lot of cases where vscode.window.activeTerminal is not updated at all. When looking in the repo issues, I've seen quite of a lot of related issues closed while not really being fixed.

@Tyriar as you tagged this issue, do you know what's the status about this issue and this API in general?

@cyrilletuzi
Copy link

cyrilletuzi commented Feb 8, 2021

For info, it's back to normal in VS Code 1.53. So I'll unsubscribe from this issue.

@andycraig
Copy link
Author

@cyrilletuzi Thank you for the update!

I have tested in VS Code 1.53 too and the bug I reported no longer happens. The active terminal is now the visible terminal, as expected. I will close this issue. @Tyriar If you fixed this, thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label
Projects
None yet
Development

No branches or pull requests

3 participants