forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpythonStartupLinkProvider.ts
More file actions
50 lines (44 loc) · 1.63 KB
/
pythonStartupLinkProvider.ts
File metadata and controls
50 lines (44 loc) · 1.63 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
46
47
48
49
50
/* eslint-disable class-methods-use-this */
import {
CancellationToken,
Disposable,
ProviderResult,
TerminalLink,
TerminalLinkContext,
TerminalLinkProvider,
} from 'vscode';
import { executeCommand } from '../common/vscodeApis/commandApis';
import { registerTerminalLinkProvider } from '../common/vscodeApis/windowApis';
import { Repl } from '../common/utils/localize';
interface CustomTerminalLink extends TerminalLink {
command: string;
}
export class CustomTerminalLinkProvider implements TerminalLinkProvider<CustomTerminalLink> {
provideTerminalLinks(
context: TerminalLinkContext,
_token: CancellationToken,
): ProviderResult<CustomTerminalLink[]> {
const links: CustomTerminalLink[] = [];
let expectedNativeLink;
if (process.platform === 'darwin') {
expectedNativeLink = 'Cmd click to launch VS Code Native REPL';
} else {
expectedNativeLink = 'Ctrl click to launch VS Code Native REPL';
}
if (context.line.includes(expectedNativeLink)) {
links.push({
startIndex: context.line.indexOf(expectedNativeLink),
length: expectedNativeLink.length,
tooltip: Repl.launchNativeRepl,
command: 'python.startNativeREPL',
});
}
return links;
}
async handleTerminalLink(link: CustomTerminalLink): Promise<void> {
await executeCommand(link.command);
}
}
export function registerCustomTerminalLinkProvider(disposables: Disposable[]): void {
disposables.push(registerTerminalLinkProvider(new CustomTerminalLinkProvider()));
}