-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
37 lines (30 loc) · 983 Bytes
/
Copy pathextension.ts
File metadata and controls
37 lines (30 loc) · 983 Bytes
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
import * as vscode from 'vscode';
import * as url from 'url';
export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('pythonDocs.openDocs', () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const selection = editor.selection;
const word = editor.document.getText(selection);
if (!word) {
return;
}
const docsUrl = getDocsUrl(word);
if (docsUrl) {
vscode.env.openExternal(vscode.Uri.parse(docsUrl));
} else {
vscode.window.showErrorMessage(`Документация для функции "${word}" не найдена.`);
}
});
context.subscriptions.push(disposable);
}
function getDocsUrl(functionName: string): string | undefined {
if (!/^(?:(?!_)\w+)+$/.test(functionName)) {
return undefined;
}
const baseUrl = 'https://docs.python.org/3/library/';
return url.resolve(baseUrl, `functions.html#${functionName}`);
}
export function deactivate() {}