11/* eslint-disable class-methods-use-this */
2- import * as vscode from 'vscode' ;
2+ import {
3+ CancellationToken ,
4+ Disposable ,
5+ ProviderResult ,
6+ TerminalLink ,
7+ TerminalLinkContext ,
8+ TerminalLinkProvider ,
9+ l10n ,
10+ } from 'vscode' ;
311import { executeCommand } from '../common/vscodeApis/commandApis' ;
4- import { IExtensionContext } from '../common/types' ;
512import { registerTerminalLinkProvider } from '../common/vscodeApis/windowApis' ;
613
7- interface CustomTerminalLink extends vscode . TerminalLink {
14+ interface CustomTerminalLink extends TerminalLink {
815 command : string ;
916}
1017
11- export class CustomTerminalLinkProvider implements vscode . TerminalLinkProvider < CustomTerminalLink > {
12- // TODO: How should I properly add this to disposables?
13- // Need advice, do not want to cause memory leak.
14-
15- // private disposable: Disposable;
16-
17- // constructor() {
18- // this.disposable = window.registerTerminalLinkProvider(this);
19- // }
20-
21- // dispose(): void {
22- // this.disposable.dispose();
23- // }
24-
18+ export class CustomTerminalLinkProvider implements TerminalLinkProvider < CustomTerminalLink > {
2519 provideTerminalLinks (
26- context : vscode . TerminalLinkContext ,
27- _token : vscode . CancellationToken ,
28- ) : vscode . ProviderResult < CustomTerminalLink [ ] > {
20+ context : TerminalLinkContext ,
21+ _token : CancellationToken ,
22+ ) : ProviderResult < CustomTerminalLink [ ] > {
2923 const links : CustomTerminalLink [ ] = [ ] ;
3024 // Question: What if context.line is truncated because of user zoom setting?
3125 // Meaning what if this line is separated into two+ line in terminal?
32- const expectedNativeLink = 'this is link to launch native repl ' ;
26+ const expectedNativeLink = 'VS Code Native REPL ' ;
3327
3428 // eslint-disable-next-line no-cond-assign
35- if ( context . line === expectedNativeLink ) {
29+ if ( context . line . includes ( expectedNativeLink ) ) {
3630 links . push ( {
37- startIndex : 0 ,
31+ startIndex : context . line . indexOf ( expectedNativeLink ) ,
3832 length : expectedNativeLink . length ,
39- tooltip : 'Launch Native REPL' ,
33+ tooltip : l10n . t ( 'Launch VS Code Native REPL' ) ,
4034 command : 'python.startNativeREPL' ,
4135 } ) ;
4236 }
@@ -48,7 +42,6 @@ export class CustomTerminalLinkProvider implements vscode.TerminalLinkProvider<C
4842 }
4943}
5044
51- export function registerCustomTerminalLinkProvider ( extensionContext : IExtensionContext ) : void {
52- const provider = new CustomTerminalLinkProvider ( ) ;
53- extensionContext . subscriptions . push ( registerTerminalLinkProvider ( provider ) ) ;
45+ export function registerCustomTerminalLinkProvider ( disposables : Disposable [ ] ) : void {
46+ disposables . push ( registerTerminalLinkProvider ( new CustomTerminalLinkProvider ( ) ) ) ;
5447}
0 commit comments