Skip to content

Commit d1f0b8c

Browse files
committed
initial set to link pythonrc text to native repl launch.
1 parent 8c54b8a commit d1f0b8c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

python_files/pythonrc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ def __str__(self):
7777

7878
if sys.platform != "win32" and (not is_wsl) and use_shell_integration:
7979
sys.ps1 = PS1()
80+
# TODO: Word this better - get feedback
81+
print("this is link to launch native repl")

src/client/extensionActivation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { registerReplCommands, registerReplExecuteOnEnter, registerStartNativeRe
5555
import { registerTriggerForTerminalREPL } from './terminals/codeExecution/terminalReplWatcher';
5656
import { registerPythonStartup } from './terminals/pythonStartup';
5757
import { registerPixiFeatures } from './pythonEnvironments/common/environmentManagers/pixi';
58+
import { CustomTerminalLinkProvider } from './terminals/pythonStartupLinkProvider';
5859

5960
export async function activateComponents(
6061
// `ext` is passed to any extra activation funcs.
@@ -115,6 +116,10 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
115116
registerStartNativeReplCommand(ext.disposables, interpreterService);
116117
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager);
117118
registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager);
119+
// TODO: proably organize this into new file.
120+
const linkProvider = new CustomTerminalLinkProvider();
121+
// TODO: Do not directly use windows API. Wrap it like we do with command APIs.
122+
ext.context.subscriptions.push(window.registerTerminalLinkProvider(linkProvider));
118123
}
119124

120125
/// //////////////////////////
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-disable class-methods-use-this */
2+
import * as vscode from 'vscode';
3+
4+
interface CustomTerminalLink extends vscode.TerminalLink {
5+
command: string;
6+
}
7+
8+
export class CustomTerminalLinkProvider implements vscode.TerminalLinkProvider<CustomTerminalLink> {
9+
// TODO: How should I properly add this to disposables?
10+
// Need advice, do not want to cause memory leak.
11+
12+
// private disposable: Disposable;
13+
14+
// constructor() {
15+
// this.disposable = window.registerTerminalLinkProvider(this);
16+
// }
17+
18+
// dispose(): void {
19+
// this.disposable.dispose();
20+
// }
21+
22+
provideTerminalLinks(
23+
context: vscode.TerminalLinkContext,
24+
_token: vscode.CancellationToken,
25+
): vscode.ProviderResult<CustomTerminalLink[]> {
26+
const links: CustomTerminalLink[] = [];
27+
const expectedNativeLink = 'this is link to launch native repl';
28+
29+
// eslint-disable-next-line no-cond-assign
30+
if (context.line === expectedNativeLink) {
31+
links.push({
32+
startIndex: 0,
33+
length: expectedNativeLink.length,
34+
tooltip: 'Launch Native REPL',
35+
command: 'python.startNativeREPL',
36+
});
37+
}
38+
return links;
39+
}
40+
41+
handleTerminalLink(link: CustomTerminalLink): vscode.ProviderResult<void> {
42+
// TODO: probably dont use vscode.commands directly?
43+
vscode.commands.executeCommand(link.command);
44+
}
45+
}

0 commit comments

Comments
 (0)