From 803704e0ea775a96933e0377165a9c9ad1e32ed7 Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:20:34 -0800 Subject: [PATCH] Bigger native repl suggestion link on terminal (#24751) Resolves: https://github.com/microsoft/vscode-python/issues/24749 --- .../terminals/pythonStartupLinkProvider.ts | 8 +- .../shellIntegration/pythonStartup.test.ts | 113 +++++++++++++----- 2 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/client/terminals/pythonStartupLinkProvider.ts b/src/client/terminals/pythonStartupLinkProvider.ts index 00dcbfd757aa..aba1270f1412 100644 --- a/src/client/terminals/pythonStartupLinkProvider.ts +++ b/src/client/terminals/pythonStartupLinkProvider.ts @@ -21,7 +21,13 @@ export class CustomTerminalLinkProvider implements TerminalLinkProvider { const links: CustomTerminalLink[] = []; - const expectedNativeLink = 'VS Code Native REPL'; + 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({ diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index af90a1886bb5..06364c9445aa 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -146,35 +146,90 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { registerTerminalLinkProviderStub.restore(); }); - - test('Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => { - const provider = new CustomTerminalLinkProvider(); - const context: TerminalLinkContext = { - line: 'Some random string with VS Code Native REPL in it', - terminal: {} as Terminal, - }; - const token: CancellationToken = { - isCancellationRequested: false, - onCancellationRequested: new EventEmitter().event, - }; - - const links = provider.provideTerminalLinks(context, token); - - assert.isNotNull(links, 'Expected links to be not undefined'); - assert.isArray(links, 'Expected links to be an array'); - assert.isNotEmpty(links, 'Expected links to be not empty'); - - if (Array.isArray(links)) { - assert.equal(links[0].command, 'python.startNativeREPL', 'Expected command to be python.startNativeREPL'); - assert.equal( - links[0].startIndex, - context.line.indexOf('VS Code Native REPL'), - 'Expected startIndex to be 0', - ); - assert.equal(links[0].length, 'VS Code Native REPL'.length, 'Expected length to be 16'); - assert.equal(links[0].tooltip, Repl.launchNativeRepl, 'Expected tooltip to be Launch VS Code Native REPL'); - } - }); + if (process.platform === 'darwin') { + test('Mac - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => { + const provider = new CustomTerminalLinkProvider(); + const context: TerminalLinkContext = { + line: 'Some random string with Cmd click to launch VS Code Native REPL', + terminal: {} as Terminal, + }; + const token: CancellationToken = { + isCancellationRequested: false, + onCancellationRequested: new EventEmitter().event, + }; + + const links = provider.provideTerminalLinks(context, token); + + assert.isNotNull(links, 'Expected links to be not undefined'); + assert.isArray(links, 'Expected links to be an array'); + assert.isNotEmpty(links, 'Expected links to be not empty'); + + if (Array.isArray(links)) { + assert.equal( + links[0].command, + 'python.startNativeREPL', + 'Expected command to be python.startNativeREPL', + ); + assert.equal( + links[0].startIndex, + context.line.indexOf('Cmd click to launch VS Code Native REPL'), + 'start index should match', + ); + assert.equal( + links[0].length, + 'Cmd click to launch VS Code Native REPL'.length, + 'Match expected length', + ); + assert.equal( + links[0].tooltip, + Repl.launchNativeRepl, + 'Expected tooltip to be Launch VS Code Native REPL', + ); + } + }); + } + if (process.platform !== 'darwin') { + test('Windows/Linux - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => { + const provider = new CustomTerminalLinkProvider(); + const context: TerminalLinkContext = { + line: 'Some random string with Ctrl click to launch VS Code Native REPL', + terminal: {} as Terminal, + }; + const token: CancellationToken = { + isCancellationRequested: false, + onCancellationRequested: new EventEmitter().event, + }; + + const links = provider.provideTerminalLinks(context, token); + + assert.isNotNull(links, 'Expected links to be not undefined'); + assert.isArray(links, 'Expected links to be an array'); + assert.isNotEmpty(links, 'Expected links to be not empty'); + + if (Array.isArray(links)) { + assert.equal( + links[0].command, + 'python.startNativeREPL', + 'Expected command to be python.startNativeREPL', + ); + assert.equal( + links[0].startIndex, + context.line.indexOf('Ctrl click to launch VS Code Native REPL'), + 'start index should match', + ); + assert.equal( + links[0].length, + 'Ctrl click to launch VS Code Native REPL'.length, + 'Match expected Length', + ); + assert.equal( + links[0].tooltip, + Repl.launchNativeRepl, + 'Expected tooltip to be Launch VS Code Native REPL', + ); + } + }); + } test('Verify provideTerminalLinks returns no links when context.line does not contain expectedNativeLink', () => { const provider = new CustomTerminalLinkProvider();