Skip to content

Commit cc589f9

Browse files
committed
Handle wrapped lines
1 parent 8c3fc45 commit cc589f9

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkDetectorAdapter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export class TerminalLinkDetectorAdapter extends Disposable implements ILinkProv
9797
}));
9898
}
9999

100-
console.log('provided links', links);
101100
return links;
102101
}
103102

src/vs/workbench/contrib/terminalContrib/links/browser/terminalMultiLineLinkDetector.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const enum Constants {
2727

2828
const candidateMatchers = [
2929
// Ripgrep:
30-
// 16:console.log(...)
31-
// 16: console.log(...)
30+
// 16:searchresult
31+
// 16: searchresult
3232
// Eslint:
3333
// 16:5 error ...
3434
/\s*(?<link>(?<line>\d+):(?<col>\d+)?)/
@@ -89,7 +89,10 @@ export class TerminalMultiLineLinkDetector implements ITerminalLinkDetector {
8989
// Scan up looking for the first line that could be a path
9090
let possiblePath: string | undefined;
9191
for (let index = startLine - 1; index >= 0; index--) {
92-
// TODO: This does not currently skip wrapped lines
92+
// Ignore lines that aren't at the beginning of a wrapped line
93+
if (this.xterm.buffer.active.getLine(index)!.isWrapped) {
94+
continue;
95+
}
9396
const text = getXtermLineContent(this.xterm.buffer.active, index, index, this.xterm.cols);
9497
if (!text.match(/^\s*\d/)) {
9598
possiblePath = text;

src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalMultiLineLinkDetector.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const supportedLinkFormats: LinkFormatInfo[] = [
8989
{ urlFormat: '{0}\r\n5:another link\r\n{1}:{2} foo', line: '5', column: '3' },
9090
{ urlFormat: '{0}\r\n {1}:{2} foo', line: '5', column: '3' },
9191
{ urlFormat: '{0}\r\n 5:6 error another one\r\n {1}:{2} error', line: '5', column: '3' },
92+
{ urlFormat: `{0}\r\n 5:6 error ${'a'.repeat(80)}\r\n {1}:{2} error`, line: '5', column: '3' },
9293
];
9394

9495
suite('Workbench - TerminalMultiLineLinkDetector', () => {
@@ -115,7 +116,12 @@ suite('Workbench - TerminalMultiLineLinkDetector', () => {
115116
const uri = resource ?? URI.file(link);
116117
const lines = link.split('\r\n');
117118
const lastLine = lines.at(-1)!;
118-
await assertLinks(TerminalBuiltinLinkType.LocalFile, link, [{ uri, range: [[1, lines.length], [lastLine.length, lines.length]] }]);
119+
// Count lines, accounting for wrapping
120+
let lineCount = 0;
121+
for (const line of lines) {
122+
lineCount += Math.max(Math.ceil(line.length / 80), 1);
123+
}
124+
await assertLinks(TerminalBuiltinLinkType.LocalFile, link, [{ uri, range: [[1, lineCount], [lastLine.length, lineCount]] }]);
119125
}
120126

121127
setup(() => {

0 commit comments

Comments
 (0)