forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivation.ts
More file actions
45 lines (42 loc) · 1.84 KB
/
Copy pathactivation.ts
File metadata and controls
45 lines (42 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Terminal } from 'vscode';
import { ITerminalManager, IWorkspaceService } from '../common/application/types';
import { ITerminalActivator } from '../common/terminal/types';
import { IDisposable, IDisposableRegistry } from '../common/types';
import { ITerminalAutoActivation } from './types';
@injectable()
export class TerminalAutoActivation implements ITerminalAutoActivation {
private handler?: IDisposable;
constructor(
@inject(ITerminalManager) private readonly terminalManager: ITerminalManager,
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(ITerminalActivator) private readonly activator: ITerminalActivator,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService
) {
disposableRegistry.push(this);
}
public dispose() {
if (this.handler) {
this.handler.dispose();
this.handler = undefined;
}
}
public register() {
if (this.handler) {
return;
}
this.handler = this.terminalManager.onDidOpenTerminal(this.activateTerminal, this);
}
private async activateTerminal(terminal: Terminal): Promise<void> {
// If we have just one workspace, then pass that as the resource.
// Until upstream VSC issue is resolved https://github.com/Microsoft/vscode/issues/63052.
const workspaceFolder =
this.workspaceService.hasWorkspaceFolders && this.workspaceService.workspaceFolders!.length > 0
? this.workspaceService.workspaceFolders![0].uri
: undefined;
await this.activator.activateEnvironmentInTerminal(terminal, workspaceFolder);
}
}