-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathutility.ts
36 lines (34 loc) · 1.52 KB
/
utility.ts
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
"use strict";
import * as vscode from "vscode";
import { Constants } from "./constants";
export class Utility {
public static async getPythonPath(document: vscode.TextDocument): Promise<string> {
try {
const extension = vscode.extensions.getExtension("ms-python.python");
if (!extension) {
return Constants.python;
}
const usingNewInterpreterStorage = extension.packageJSON?.featureFlags?.usingNewInterpreterStorage;
if (usingNewInterpreterStorage) {
if (!extension.isActive) {
await extension.activate();
}
const execCommand = extension.exports.settings.getExecutionDetails ?
extension.exports.settings.getExecutionDetails(document?.uri).execCommand :
extension.exports.settings.getExecutionCommand(document?.uri);
return execCommand ? execCommand.join(" ") : Constants.python;
} else {
return this.getConfiguration("python", document).get<string>("pythonPath");
}
} catch (error) {
return Constants.python;
}
}
public static getConfiguration(section?: string, document?: vscode.TextDocument): vscode.WorkspaceConfiguration {
if (document) {
return vscode.workspace.getConfiguration(section, document.uri);
} else {
return vscode.workspace.getConfiguration(section);
}
}
}