Skip to content

Commit

Permalink
Take feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Jan 22, 2025
1 parent cb63ae7 commit f9093d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
3 changes: 2 additions & 1 deletion python_files/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// //////////////////////////
Expand Down
47 changes: 20 additions & 27 deletions src/client/terminals/pythonStartupLinkProvider.ts
Original file line number Diff line number Diff line change
@@ -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<CustomTerminalLink> {
// 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<CustomTerminalLink> {
provideTerminalLinks(
context: vscode.TerminalLinkContext,
_token: vscode.CancellationToken,
): vscode.ProviderResult<CustomTerminalLink[]> {
context: TerminalLinkContext,
_token: CancellationToken,
): ProviderResult<CustomTerminalLink[]> {
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',
});
}
Expand All @@ -48,7 +42,6 @@ export class CustomTerminalLinkProvider implements vscode.TerminalLinkProvider<C
}
}

export function registerCustomTerminalLinkProvider(extensionContext: IExtensionContext): void {
const provider = new CustomTerminalLinkProvider();
extensionContext.subscriptions.push(registerTerminalLinkProvider(provider));
export function registerCustomTerminalLinkProvider(disposables: Disposable[]): void {
disposables.push(registerTerminalLinkProvider(new CustomTerminalLinkProvider()));
}

0 comments on commit f9093d8

Please sign in to comment.