From f9093d80b9e53eaaf1b8e4c8e8d5eb6ab856f236 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 22 Jan 2025 13:35:43 -0500 Subject: [PATCH] Take feedback --- python_files/pythonrc.py | 3 +- src/client/extensionActivation.ts | 2 +- .../terminals/pythonStartupLinkProvider.ts | 47 ++++++++----------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index 74dcef0f8d37..7b4c2ceeb87b 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -78,4 +78,5 @@ def __str__(self): if sys.platform != "win32" and (not is_wsl) and use_shell_integration: sys.ps1 = PS1() # TODO: Word this better - get feedback -print("this is link to launch native repl") +# TODO: add ctrl/cmd depending on OS +print("Click to launch VS Code Native REPL") diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index f09e2b03fca5..4a1acca62da5 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -116,7 +116,7 @@ export function activateFeatures(ext: ExtensionState, _components: Components): registerStartNativeReplCommand(ext.disposables, interpreterService); registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager); registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager); - registerCustomTerminalLinkProvider(ext.context); // TODO: Is there way to avoid passing in ext.context? + registerCustomTerminalLinkProvider(ext.disposables); } /// ////////////////////////// diff --git a/src/client/terminals/pythonStartupLinkProvider.ts b/src/client/terminals/pythonStartupLinkProvider.ts index 664e2a17a985..57ec1191dd87 100644 --- a/src/client/terminals/pythonStartupLinkProvider.ts +++ b/src/client/terminals/pythonStartupLinkProvider.ts @@ -1,42 +1,36 @@ /* eslint-disable class-methods-use-this */ -import * as vscode from 'vscode'; +import { + CancellationToken, + Disposable, + ProviderResult, + TerminalLink, + TerminalLinkContext, + TerminalLinkProvider, + l10n, +} from 'vscode'; import { executeCommand } from '../common/vscodeApis/commandApis'; -import { IExtensionContext } from '../common/types'; import { registerTerminalLinkProvider } from '../common/vscodeApis/windowApis'; -interface CustomTerminalLink extends vscode.TerminalLink { +interface CustomTerminalLink extends TerminalLink { command: string; } -export class CustomTerminalLinkProvider implements vscode.TerminalLinkProvider { - // TODO: How should I properly add this to disposables? - // Need advice, do not want to cause memory leak. - - // private disposable: Disposable; - - // constructor() { - // this.disposable = window.registerTerminalLinkProvider(this); - // } - - // dispose(): void { - // this.disposable.dispose(); - // } - +export class CustomTerminalLinkProvider implements TerminalLinkProvider { provideTerminalLinks( - context: vscode.TerminalLinkContext, - _token: vscode.CancellationToken, - ): vscode.ProviderResult { + context: TerminalLinkContext, + _token: CancellationToken, + ): ProviderResult { const links: CustomTerminalLink[] = []; // Question: What if context.line is truncated because of user zoom setting? // Meaning what if this line is separated into two+ line in terminal? - const expectedNativeLink = 'this is link to launch native repl'; + const expectedNativeLink = 'VS Code Native REPL'; // eslint-disable-next-line no-cond-assign - if (context.line === expectedNativeLink) { + if (context.line.includes(expectedNativeLink)) { links.push({ - startIndex: 0, + startIndex: context.line.indexOf(expectedNativeLink), length: expectedNativeLink.length, - tooltip: 'Launch Native REPL', + tooltip: l10n.t('Launch VS Code Native REPL'), command: 'python.startNativeREPL', }); } @@ -48,7 +42,6 @@ export class CustomTerminalLinkProvider implements vscode.TerminalLinkProvider