diff --git a/src/EscargotDebugger.ts b/src/EscargotDebugger.ts index 1754f13..41b414a 100644 --- a/src/EscargotDebugger.ts +++ b/src/EscargotDebugger.ts @@ -16,7 +16,7 @@ 'use strict'; -import {DebugSession, InitializedEvent, OutputEvent, BreakpointEvent, TerminatedEvent, Event, Thread, StoppedEvent, StackFrame, ErrorDestination, Scope,} from 'vscode-debugadapter'; +import {DebugSession, InitializedEvent, OutputEvent, LoadedSourceEvent, BreakpointEvent, TerminatedEvent, Event, Thread, StoppedEvent, StackFrame, ErrorDestination, Scope,} from 'vscode-debugadapter'; import {DebugProtocol} from 'vscode-debugprotocol'; import * as Util from 'util'; import * as Cp from 'child_process'; @@ -588,7 +588,11 @@ class EscargotDebugSession extends DebugSession { private onScriptParsed(data: EscargotMessageScriptParsed): void { this.log('onScriptParsed', LOG_LEVEL.SESSION); - this.handleSource(data); + this.sendEvent(new LoadedSourceEvent('new', data.source)); + + if (data.breakpointsHandled) { + this.setBreakpoints(data); + } } private async onWaitForSource(mode?: string): Promise { @@ -623,7 +627,7 @@ class EscargotDebugSession extends DebugSession { // General helper functions - private async handleSource(data: EscargotMessageScriptParsed): Promise { + private async setBreakpoints(data: EscargotMessageScriptParsed): Promise { try { const userBreakpoints: UserBreakpoints = this._userBreakpoints.get(data.source.path); diff --git a/src/EscargotProtocolHandler.ts b/src/EscargotProtocolHandler.ts index c8457c5..942c358 100644 --- a/src/EscargotProtocolHandler.ts +++ b/src/EscargotProtocolHandler.ts @@ -68,7 +68,7 @@ export interface EscargotMessageSource { export interface EscargotMessageScriptParsed { id: number; source: Source; - breakpointsHandled: () => void; + breakpointsHandled: () => void | null; } export interface EscargotMessageBreakpointHit { @@ -462,9 +462,33 @@ export class EscargotDebugProtocolHandler { } private onParseErrorEnd(str: string): void { + let source: Source = this.sources[this.nextScriptID].reference; + if (this.delegate.onOutput) { - this.delegate.onOutput(`Exception: ${str}`, 'stderr'); + this.delegate.onOutput(`Parse error in ${source.path}:\n${str}`, 'stderr'); + } + + if (source.sourceReference != 0) { + let path: string = Path.join(this.localRoot, 'tmp_' + Path.basename(source.path)); + + try { + Fs.writeFileSync(path, this.sources[this.nextScriptID].source); + this.delegate.onOutput(`Saved as ${path}`, 'stderr'); + } catch { + } + } + + this.newFunctions = {}; + + if (this.delegate.onScriptParsed) { + this.delegate.onScriptParsed({ + id: this.nextScriptID, + source, + breakpointsHandled: null + }); } + + this.nextScriptID++; } private onParseError(data: Uint8Array): void {