Repository navigation
Expand file tree
/
Copy pathinterpreterPathCommand.ts
More file actions
43 lines (37 loc) · 1.96 KB
/
Copy pathinterpreterPathCommand.ts
File metadata and controls
43 lines (37 loc) · 1.96 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IExtensionSingleActivationService } from '../../../../activation/types';
import { ICommandManager } from '../../../../common/application/types';
import { Commands } from '../../../../common/constants';
import { IConfigurationService, IDisposable, IDisposableRegistry } from '../../../../common/types';
@injectable()
export class InterpreterPathCommand implements IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
@inject(IDisposableRegistry) private readonly disposables: IDisposable[],
) {}
public async activate() {
this.disposables.push(
this.commandManager.registerCommand(Commands.GetSelectedInterpreterPath, (args) => {
return this._getSelectedInterpreterPath(args);
}),
);
}
public _getSelectedInterpreterPath(args: { workspaceFolder: string } | string[]): string {
// If `launch.json` is launching this command, `args.workspaceFolder` carries the workspaceFolder
// If `tasks.json` is launching this command, `args[1]` carries the workspaceFolder
const workspaceFolder = 'workspaceFolder' in args ? args.workspaceFolder : args[1] ? args[1] : undefined;
let workspaceFolderUri;
try {
workspaceFolderUri = workspaceFolder ? Uri.parse(workspaceFolder) : undefined;
} catch (ex) {
workspaceFolderUri = undefined;
}
return this.configurationService.getSettings(workspaceFolderUri).pythonPath;
}
}