Skip to content

Commit 89e15ee

Browse files
committed
fix: Wrong source locations for source maps
1 parent 604d040 commit 89e15ee

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/runner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,12 @@ async function deriveSourceLocation(
707707

708708
const maintainer = store.maintain(fileUri);
709709
const mapping = await (maintainer.value || maintainer.refresh());
710+
// in parsed stack traces line and column numbers are 1-based, in the VS Code APIs lines are 0-based
711+
const zeroBasedLine = Number(line) - 1;
712+
const zeroBasedCol = Number(col) - 1;
710713
const value =
711-
mapping?.originalPositionFor(Number(line), Number(col)) ||
712-
new vscode.Location(fileUri, new vscode.Position(Number(line), Number(col)));
714+
mapping?.originalPositionFor(zeroBasedLine, zeroBasedCol) ||
715+
new vscode.Location(fileUri, new vscode.Position(zeroBasedLine, zeroBasedCol));
713716

714717
// timeout the maintainer async so that it stays alive for any other immediate teset usage in the file:
715718
setTimeout(() => maintainer.dispose(), 5000);

src/source-map.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const identityMapping = (file: vscode.Uri): IMappingAccessor => ({
3030
});
3131

3232
const smMappingAccessor = (file: vscode.Uri, sm: TraceMap): IMappingAccessor => ({
33+
// @jridgewell/trace-mapping: Lines start at line 1, columns at column 0.
3334
originalPositionFor(line, column) {
3435
const {
3536
source,

src/test/integration/typescript.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('typescript', () => {
8484
expect(failed.message?.location).to.not.be.undefined;
8585
expect(failed.message?.location?.uri.toString()).to.include('hello.test.ts');
8686
expect(path.isAbsolute(failed.message!.location!.uri.fsPath)).to.be.true;
87-
expect(failed.message?.location?.range.start.line).to.equal(29);
88-
expect(failed.message?.location?.range.start.character).to.equal(5);
87+
expect(failed.message?.location?.range.start.line).to.equal(28);
88+
expect(failed.message?.location?.range.start.character).to.equal(4);
8989
});
9090
});

0 commit comments

Comments
 (0)