Skip to content

Commit 361692e

Browse files
authored
debug: allow linking to ranges in debug console uris (microsoft#151335)
1 parent 714456b commit 361692e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/vs/workbench/contrib/debug/browser/linkDetector.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const WIN_PATH = new RegExp(`(${WIN_ABSOLUTE_PATH.source}|${WIN_RELATIVE_PATH.so
2727
const POSIX_PATH = /((?:\~|\.)?(?:\/[\w\.-]*)+)/;
2828
const LINE_COLUMN = /(?:\:([\d]+))?(?:\:([\d]+))?/;
2929
const PATH_LINK_REGEX = new RegExp(`${platform.isWindows ? WIN_PATH.source : POSIX_PATH.source}${LINE_COLUMN.source}`, 'g');
30+
const LINE_COLUMN_REGEX = /:([\d]+)(?::([\d]+))?$/;
3031

3132
const MAX_LENGTH = 2000;
3233

@@ -104,7 +105,17 @@ export class LinkDetector {
104105
private createWebLink(url: string): Node {
105106
const link = this.createLink(url);
106107

107-
const uri = URI.parse(url);
108+
let uri = URI.parse(url);
109+
// if the URI ends with something like `foo.js:12:3`, parse
110+
// that into a fragment to reveal that location (#150702)
111+
const lineCol = LINE_COLUMN_REGEX.exec(uri.path);
112+
if (lineCol) {
113+
uri = uri.with({
114+
path: uri.path.slice(0, lineCol.index),
115+
fragment: `L${lineCol[0].slice(1)}`
116+
});
117+
}
118+
108119
this.decorateLink(link, uri, async () => {
109120

110121
if (uri.scheme === Schemas.file) {
@@ -119,7 +130,13 @@ export class LinkDetector {
119130
return;
120131
}
121132

122-
await this.editorService.openEditor({ resource: fileUri, options: { pinned: true } });
133+
await this.editorService.openEditor({
134+
resource: fileUri,
135+
options: {
136+
pinned: true,
137+
selection: lineCol ? { startLineNumber: +lineCol[1], startColumn: +lineCol[2] } : undefined,
138+
},
139+
});
123140
return;
124141
}
125142

0 commit comments

Comments
 (0)