Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"label": "Minecraft Debugger",
"runtime": "node",
"languages": [
"javascript"
"javascript",
"typescript"
],
"configurationAttributes": {
"attach": {
Expand Down
81 changes: 44 additions & 37 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
captureData: string,
capturePath: string,
basePath: string,
fileName: string
fileName: string,
): boolean {
const data = Buffer.from(captureData, 'base64');

Expand Down Expand Up @@ -272,7 +272,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
profilerCapture.capture_data,
captureFullPathJS,
profilerCapture.capture_base_path,
newCaptureFileNameJS
newCaptureFileNameJS,
);

const newCaptureFileNameTS = `Capture_${formattedDate}_TS.cpuprofile`;
Expand All @@ -281,7 +281,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this._moduleMapping,
this._moduleMaps,
this._sourceMaps,
profilerCapture.capture_data
profilerCapture.capture_data,
);

let tsFileCreated = false;
Expand All @@ -293,7 +293,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
dataTS,
captureFullPathTS,
profilerCapture.capture_base_path,
newCaptureFileNameTS
newCaptureFileNameTS,
);
}

Expand Down Expand Up @@ -341,7 +341,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
// VSCode wants to attach to a debugee (MC), create socket connection on specified port
protected async attachRequest(
response: DebugProtocol.AttachResponse,
args: IAttachRequestArguments
args: IAttachRequestArguments,
): Promise<void> {
this.closeSession();

Expand Down Expand Up @@ -395,7 +395,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {

protected async setBreakPointsRequest(
response: DebugProtocol.SetBreakpointsResponse,
args: DebugProtocol.SetBreakpointsArguments
args: DebugProtocol.SetBreakpointsArguments,
): Promise<void> {
if (!this._breakpointsHandler) {
throw new Error('Breakpoints handler not initialized.');
Expand All @@ -414,7 +414,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
response.body = await this._breakpointsHandler.handleSetBreakpointsRequest(
args.source.path,
response,
args
args,
);
} catch (e) {
this.log((e as Error).message, LogLevel.Error);
Expand All @@ -427,7 +427,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {

protected setExceptionBreakPointsRequest(
response: DebugProtocol.SetExceptionBreakpointsResponse,
args: DebugProtocol.SetExceptionBreakpointsArguments
args: DebugProtocol.SetExceptionBreakpointsArguments,
): void {
this.sendDebuggeeMessage({
type: 'stopOnException',
Expand All @@ -449,15 +449,15 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
response.body = {
threads: Array.from(this._threads.keys()).map(
thread => new Thread(thread, `thread 0x${thread.toString(16)}`)
thread => new Thread(thread, `thread 0x${thread.toString(16)}`),
),
};
this.sendResponse(response);
}

static createModuleMap(
localRoot: string,
mapping: ModuleMapping | undefined
mapping: ModuleMapping | undefined,
): Record<string, SourceMaps> | undefined {
if (!mapping) {
return undefined;
Expand All @@ -473,7 +473,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
debuggerStackFrames: DebuggerStackFrame[],
moduleMapping: ModuleMapping | undefined,
moduleMaps: Record<string, SourceMaps> | undefined,
baseSourceMaps: SourceMaps
baseSourceMaps: SourceMaps,
): Promise<StackFrame[]> {
const stackFrames: StackFrame[] = [];
for (const { id, name, filename, line, column } of debuggerStackFrames) {
Expand All @@ -498,15 +498,15 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
// VSCode requesting stack trace for threads, follows threadsRequest
protected async stackTraceRequest(
response: DebugProtocol.StackTraceResponse,
args: DebugProtocol.StackTraceArguments
args: DebugProtocol.StackTraceArguments,
): Promise<void> {
const stacksBody = (await this.sendDebugeeRequestAsync(response, args)) as DebuggerStackFrame[];

const stackFrames: StackFrame[] = await Session.mapStackFrames(
stacksBody,
this._moduleMapping,
this._moduleMaps,
this._sourceMaps
this._sourceMaps,
);
const totalFrames = stacksBody.length;

Expand Down Expand Up @@ -534,7 +534,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {

protected variablesRequest(
response: DebugProtocol.VariablesResponse,
args: DebugProtocol.VariablesArguments
args: DebugProtocol.VariablesArguments,
): void {
// get variables at this reference (all vars in scope or vars in object/array)
this.sendDebugeeRequest(response, args, (body: any) => {
Expand All @@ -545,7 +545,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
name,
value,
variablesReference,
indexedVariables
indexedVariables,
);
variable.type = type; // to show type when hovered
variables.push(variable);
Expand Down Expand Up @@ -631,7 +631,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
await this._breakpointsHandler.handleSetBreakpointsRequest(
args.source.path,
setBreakpointsResponse,
args
args,
);
// send original response, not the special one we created
this.sendResponse(response);
Expand Down Expand Up @@ -737,7 +737,10 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
});

// show notifications for source map issues
this.checkSourceFilePaths();
// only if we are actually trying to attach to a target
if (this._targetModuleUuid !== undefined) {
this.checkSourceFilePaths();
}

// success
this.showNotification('Success! Debugger is now connected.', LogLevel.Log);
Expand All @@ -747,7 +750,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this._localRoot,
this._sourceMapRoot,
this._generatedSourceRoot,
this._inlineSourceMap
this._inlineSourceMap,
);

this._moduleMaps = Session.createModuleMap(this._localRoot, this._moduleMapping);
Expand Down Expand Up @@ -923,7 +926,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
if (generatedPosition) {
message = message.replace(
fullMatch,
`(${generatedPositionSourceAsRelative}:${generatedPosition.line}) (${javaScriptFilePath}:${javaScriptLineNumber})`
`(${generatedPositionSourceAsRelative}:${generatedPosition.line}) (${javaScriptFilePath}:${javaScriptLineNumber})`,
);
}
} catch (e) {
Expand Down Expand Up @@ -968,46 +971,50 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
if (this._debuggerProtocolVersion < protocolCapabilities.version) {
this.terminateSession(
`protocol unsupported. Upgrade Debugger Extension. Protocol Version: ${protocolCapabilities.version} is not supported by the current version of the Debugger.`,
LogLevel.Error
LogLevel.Error,
);
} else {
if (protocolCapabilities.version === ProtocolVersion.SupportTargetModuleUuid) {
this.onConnectionComplete(protocolCapabilities.version, undefined);
} else if (protocolCapabilities.version >= ProtocolVersion.SupportTargetSelection) {
// no add-ons found, nothing to do
// if passcode is required, prompt user for it
const passcode = await this.promptForPasscode(protocolCapabilities.require_passcode);

// no scripting packs found, continue without a target for diagnostics-only mode
if (!protocolCapabilities.plugins || protocolCapabilities.plugins.length === 0) {
this.terminateSession('protocol error. No Minecraft Add-Ons found.', LogLevel.Error);
this.showNotification(
'No Minecraft behavior packs with scripts found. Debugging features are unavailable, but diagnostics are still available.',
LogLevel.Warn,
);
this.onConnectionComplete(protocolCapabilities.version, undefined, passcode);
return;
}

// if passcode is required, prompt user for it
const passcode = await this.promptForPasscode(protocolCapabilities.require_passcode);

// if a targetuuid was provided, make sure it's valid
if (this._targetModuleUuid) {
const isValidTarget = protocolCapabilities.plugins.some(
plugin => plugin.module_uuid === this._targetModuleUuid
plugin => plugin.module_uuid === this._targetModuleUuid,
);
if (isValidTarget) {
this.onConnectionComplete(protocolCapabilities.version, this._targetModuleUuid, passcode);
return;
} else {
this.showNotification(
`Minecraft Add-On script module not found with targetModuleUuid ${this._targetModuleUuid} specified in launch.json. Prompting for debug target.`,
LogLevel.Warn
LogLevel.Warn,
);
}
} else if (protocolCapabilities.plugins.length === 1) {
this.onConnectionComplete(
protocolCapabilities.version,
protocolCapabilities.plugins[0].module_uuid,
passcode
passcode,
);
return;
} else {
this.showNotification(
'The targetModuleUuid in launch.json is not set to a valid uuid. Set this to a script module uuid (manifest.json) to avoid the selection prompt.',
LogLevel.Warn
LogLevel.Warn,
);
}

Expand All @@ -1016,15 +1023,15 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
if (!targetUuid) {
this.terminateSession(
'could not determine target Minecraft Add-On. You must specify the targetModuleUuid.',
LogLevel.Error
LogLevel.Error,
);
return;
}
this.onConnectionComplete(protocolCapabilities.version, targetUuid, passcode);
} else {
this.terminateSession(
`protocol unsupported. Downgrade Debugger Extension. Protocol Version: ${protocolCapabilities.version} is not supported by the current version of the Debugger.`,
LogLevel.Error
LogLevel.Error,
);
}
}
Expand Down Expand Up @@ -1083,7 +1090,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this._inlineSourceMap = true;
this.log(
`Source maps (.map files) not found. Enabling inline source maps from sourceMapRoot:[${this._sourceMapRoot}].`,
LogLevel.Log
LogLevel.Log,
);
}

Expand All @@ -1096,7 +1103,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this.showNotification(
`Inline source maps not found, failed to find .js files at sourceMapRoot:[${this._sourceMapRoot}].`,
LogLevel.Warn,
true
true,
);
}
}
Expand All @@ -1110,7 +1117,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this.showNotification(
`Failed to find .js files at generatedSourceRoot:[${this._generatedSourceRoot}].`,
LogLevel.Warn,
true
true,
);
}
}
Expand All @@ -1124,7 +1131,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this.showNotification(
"Failed to find .js files. Check that launch.json 'localRoot' cointains .js files.",
LogLevel.Warn,
true
true,
);
}

Expand All @@ -1134,7 +1141,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
this.showNotification(
"Found .ts files at 'localRoot' but 'sourceMapRoot' is not defined.",
LogLevel.Warn,
true
true,
);
}
}
Expand Down Expand Up @@ -1187,7 +1194,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender {
if (workspaceFolders && workspaceFolders.length > 0) {
globPattern = new RelativePattern(
workspaceFolders[0].uri.fsPath ?? '',
reloadOnSourceChangesGlobPattern
reloadOnSourceChangesGlobPattern,
);
}
}
Expand Down
Loading