Skip to content

Commit

Permalink
Bigger native repl suggestion link on terminal (microsoft#24751)
Browse files Browse the repository at this point in the history
Resolves: microsoft#24749
  • Loading branch information
anthonykim1 authored Jan 28, 2025
1 parent 4322684 commit 803704e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 30 deletions.
8 changes: 7 additions & 1 deletion src/client/terminals/pythonStartupLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export class CustomTerminalLinkProvider implements TerminalLinkProvider<CustomTe
_token: CancellationToken,
): ProviderResult<CustomTerminalLink[]> {
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({
Expand Down
113 changes: 84 additions & 29 deletions src/test/terminals/shellIntegration/pythonStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>().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<unknown>().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<unknown>().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();
Expand Down

0 comments on commit 803704e

Please sign in to comment.