Skip to content

Commit 074030d

Browse files
authored
Add support for module name mapping and unknown source files in stack trace (#21)
Allows debugger to function when some modules can't be mapped
1 parent 8f6db95 commit 074030d

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
## Version 0.5.0 (September 2022)
2828

2929
- Changes to the source path location in Minecraft require that localRoot points to a directory with sources, not the pack root. Update your launch.json 'localRoot'.
30+
31+
## Version 0.6.0 (September 2022)
32+
33+
- Add support for external modules while debugging. For JS modules built into Minecraft, stack will be visible but listed as "unknown". Add configuration support for module name mapping.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "minecraft-debugger",
33
"displayName": "Minecraft Bedrock Edition Debugger",
44
"description": "Debug your JavaScript code running as part of the GameTest Framework experimental feature in Minecraft Bedrock Edition.",
5-
"version": "0.5.0",
5+
"version": "0.6.0",
66
"publisher": "mojang-studios",
77
"author": {
88
"name": "Mojang Studios"
@@ -84,6 +84,10 @@
8484
"inputPort": {
8585
"type": "string",
8686
"description": "Prompts for a port at launch."
87+
},
88+
"moduleMapping": {
89+
"type": "object",
90+
"description": "Module mapping for imports. Each key is an import name that will be mapped to the provided value. Used if modules are external (i.e. included as part of minecraft). Defaults to an empty object."
8791
}
8892
}
8993
}
@@ -149,4 +153,4 @@
149153
"vsce": "^1.93.0",
150154
"vscode-test": "^1.5.0"
151155
}
152-
}
156+
}

src/Session.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ interface PendingResponse {
1616
reject: Function;
1717
}
1818

19+
// Module mapping for getting line numbers for a given module
20+
interface ModuleMapping {
21+
[moduleName: string]: string;
22+
}
23+
1924
// Interface for specific launch arguments.
2025
// See package.json for schema.
2126
interface IAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
@@ -26,6 +31,7 @@ interface IAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
2631
host: string;
2732
port: number;
2833
inputPort: string;
34+
moduleMapping: ModuleMapping;
2935
}
3036

3137
// The Debug Adapter for 'minecraft-js'
@@ -46,6 +52,7 @@ export class Session extends DebugSession {
4652
private _localRoot: string = "";
4753
private _sourceMapRoot?: string;
4854
private _generatedSourceRoot?: string;
55+
private _moduleMapping?: ModuleMapping;
4956

5057
public constructor() {
5158
super();
@@ -88,6 +95,7 @@ export class Session extends DebugSession {
8895
this._localRoot = args.localRoot ? path.normalize(args.localRoot) : "";
8996
this._sourceMapRoot = args.sourceMapRoot ? path.normalize(args.sourceMapRoot) : undefined;
9097
this._generatedSourceRoot = args.generatedSourceRoot ? path.normalize(args.generatedSourceRoot) : undefined;
98+
this._moduleMapping = args.moduleMapping;
9199

92100
// Listen or connect (default), depending on mode.
93101
// Attach makes more sense to use connect, but some MC platforms require using listen.
@@ -191,19 +199,18 @@ export class Session extends DebugSession {
191199

192200
const stackFrames: StackFrame[] = [];
193201
for (const { id, name, filename, line, column } of stacksBody) {
202+
const mappedFilename = this._moduleMapping?.[filename] ?? filename;
194203
try {
195204
const originalLocation = await this._sourceMaps.getOriginalPositionFor({
196-
source: filename,
205+
source: mappedFilename,
197206
line: line || 0,
198207
column: column || 0
199208
});
200209
const source = new Source(path.basename(originalLocation.source), originalLocation.source);
201210
stackFrames.push(new StackFrame(id, name, source, originalLocation.line, originalLocation.column));
202211
}
203212
catch (e) {
204-
this.log((e as Error).message, LogLevel.Error);
205-
this.sendErrorResponse(response, 1003, `Failed to get stack trace for ${filename} at line ${line}.`);
206-
return;
213+
stackFrames.push(new StackFrame(id, name));
207214
}
208215
}
209216

0 commit comments

Comments
 (0)