diff --git a/package.json b/package.json index b3cf8a6..33f2f42 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,8 @@ "label": "Minecraft Debugger", "runtime": "node", "languages": [ - "javascript" + "javascript", + "typescript" ], "configurationAttributes": { "attach": { diff --git a/src/session.ts b/src/session.ts index 3b2059a..8511bbf 100644 --- a/src/session.ts +++ b/src/session.ts @@ -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'); @@ -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`; @@ -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; @@ -293,7 +293,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { dataTS, captureFullPathTS, profilerCapture.capture_base_path, - newCaptureFileNameTS + newCaptureFileNameTS, ); } @@ -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 { this.closeSession(); @@ -395,7 +395,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { protected async setBreakPointsRequest( response: DebugProtocol.SetBreakpointsResponse, - args: DebugProtocol.SetBreakpointsArguments + args: DebugProtocol.SetBreakpointsArguments, ): Promise { if (!this._breakpointsHandler) { throw new Error('Breakpoints handler not initialized.'); @@ -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); @@ -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', @@ -449,7 +449,7 @@ 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); @@ -457,7 +457,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { static createModuleMap( localRoot: string, - mapping: ModuleMapping | undefined + mapping: ModuleMapping | undefined, ): Record | undefined { if (!mapping) { return undefined; @@ -473,7 +473,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { debuggerStackFrames: DebuggerStackFrame[], moduleMapping: ModuleMapping | undefined, moduleMaps: Record | undefined, - baseSourceMaps: SourceMaps + baseSourceMaps: SourceMaps, ): Promise { const stackFrames: StackFrame[] = []; for (const { id, name, filename, line, column } of debuggerStackFrames) { @@ -498,7 +498,7 @@ 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 { const stacksBody = (await this.sendDebugeeRequestAsync(response, args)) as DebuggerStackFrame[]; @@ -506,7 +506,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { stacksBody, this._moduleMapping, this._moduleMaps, - this._sourceMaps + this._sourceMaps, ); const totalFrames = stacksBody.length; @@ -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) => { @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) { @@ -968,25 +971,29 @@ 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); @@ -994,20 +1001,20 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { } 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, ); } @@ -1016,7 +1023,7 @@ 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; } @@ -1024,7 +1031,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { } 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, ); } } @@ -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, ); } @@ -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, ); } } @@ -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, ); } } @@ -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, ); } @@ -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, ); } } @@ -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, ); } }