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
10 changes: 7 additions & 3 deletions src/EscargotDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -623,7 +627,7 @@ class EscargotDebugSession extends DebugSession {

// General helper functions

private async handleSource(data: EscargotMessageScriptParsed): Promise<void> {
private async setBreakpoints(data: EscargotMessageScriptParsed): Promise<void> {
try {
const userBreakpoints: UserBreakpoints = this._userBreakpoints.get(data.source.path);

Expand Down
28 changes: 26 additions & 2 deletions src/EscargotProtocolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface EscargotMessageSource {
export interface EscargotMessageScriptParsed {
id: number;
source: Source;
breakpointsHandled: () => void;
breakpointsHandled: () => void | null;
}

export interface EscargotMessageBreakpointHit {
Expand Down Expand Up @@ -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 {
Expand Down