forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Auto activation of environment in new terminals #2277
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c9e459c
Auto activation of environment in new terminals
DonJayamanne 97e02cf
refactor
DonJayamanne 4ea270c
Fixed tests
DonJayamanne 9a21fe6
Change tests to unit tests
DonJayamanne 69cf67f
Fix flaky test
DonJayamanne 5ce700c
Rename tests
DonJayamanne 91a227f
Added tests for activation of a terminal
DonJayamanne c4f66ee
Add news entry
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Auto activate Python Environment in terminals. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
| import { Disposable, Terminal } from 'vscode'; | ||
| import { ITerminalManager } from '../common/application/types'; | ||
| import { ITerminalHelper } from '../common/terminal/types'; | ||
| import { IDisposableRegistry } from '../common/types'; | ||
| import { IServiceContainer } from '../ioc/types'; | ||
| import { ITerminalAutoActivation } from './types'; | ||
|
|
||
| @injectable() | ||
| export class TerminalAutoActivation implements ITerminalAutoActivation { | ||
| private readonly helper: ITerminalHelper; | ||
| constructor(@inject(IServiceContainer) private container: IServiceContainer) { | ||
| this.helper = container.get<ITerminalHelper>(ITerminalHelper); | ||
| } | ||
| public register() { | ||
| const manager = this.container.get<ITerminalManager>(ITerminalManager); | ||
| const disposables = this.container.get<Disposable[]>(IDisposableRegistry); | ||
| const disposable = manager.onDidOpenTerminal(this.activateTerminal, this); | ||
| disposables.push(disposable); | ||
| } | ||
| private activateTerminal(terminal: Terminal): Promise<void> { | ||
| return this.helper.activateEnvironmentInTerminal(terminal); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
| import { expect } from 'chai'; | ||
| import * as TypeMoq from 'typemoq'; | ||
| import { Terminal } from 'vscode'; | ||
| import { ITerminalManager } from '../../../client/common/application/types'; | ||
| import { ITerminalHelper } from '../../../client/common/terminal/types'; | ||
| import { IDisposableRegistry } from '../../../client/common/types'; | ||
| import { IServiceContainer } from '../../../client/ioc/types'; | ||
| import { TerminalAutoActivation } from '../../../client/terminals/activation'; | ||
| import { ITerminalAutoActivation } from '../../../client/terminals/types'; | ||
| import { noop } from '../../../utils/misc'; | ||
|
|
||
| suite('Terminal Auto Activation', () => { | ||
| let helper: TypeMoq.IMock<ITerminalHelper>; | ||
| let terminalManager: TypeMoq.IMock<ITerminalManager>; | ||
| let terminalAutoActivation: ITerminalAutoActivation; | ||
|
|
||
| setup(() => { | ||
| terminalManager = TypeMoq.Mock.ofType<ITerminalManager>(); | ||
| helper = TypeMoq.Mock.ofType<ITerminalHelper>(); | ||
| const disposables = []; | ||
|
|
||
| const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); | ||
| serviceContainer | ||
| .setup(c => c.get(TypeMoq.It.isValue(ITerminalManager), TypeMoq.It.isAny())) | ||
| .returns(() => terminalManager.object); | ||
| serviceContainer | ||
| .setup(c => c.get(TypeMoq.It.isValue(ITerminalHelper), TypeMoq.It.isAny())) | ||
| .returns(() => helper.object); | ||
| serviceContainer | ||
| .setup(c => c.get(TypeMoq.It.isValue(IDisposableRegistry), TypeMoq.It.isAny())) | ||
| .returns(() => disposables); | ||
|
|
||
| terminalAutoActivation = new TerminalAutoActivation(serviceContainer.object); | ||
| }); | ||
|
|
||
| test('New Terminals should be activated', async () => { | ||
| let eventHandler: undefined | ((e: Terminal) => void); | ||
| const terminal = TypeMoq.Mock.ofType<Terminal>(); | ||
| terminalManager | ||
| .setup(m => m.onDidOpenTerminal(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) | ||
| .returns(handler => { | ||
| eventHandler = handler; | ||
| return { dispose: noop }; | ||
| }); | ||
| helper | ||
| .setup(h => h.activateEnvironmentInTerminal(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) | ||
| .verifiable(TypeMoq.Times.once()); | ||
|
|
||
| terminalAutoActivation.register(); | ||
|
|
||
| expect(eventHandler).not.to.be.an('undefined', 'event handler not initialized'); | ||
|
|
||
| eventHandler!.bind(terminalAutoActivation)(terminal.object); | ||
|
|
||
| helper.verifyAll(); | ||
| }); | ||
| }); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really love to see if we can get an event from the shell when it is 'ready' instead of this sleep stuff. Is there any issue related to this that VSCode knows about/can do anything about?
Do we know why this is the case at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not available.
Powershell is slow. VS Code doesn't get any feedback when process in terminal has completed. Basically the stream is ready to write anytime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we just use the VS Code api (which in turn doesn't provide any feedback on when stuff is ready or not, explained above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been an ongoing issue in VSC. Unfortunately nothing we can do at this stage.