Skip to content

Commit 2160a7d

Browse files
committed
Save scripts with parse error when their corresponding file is not found
Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent 3e65c57 commit 2160a7d

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/EscargotDebugger.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
import {DebugSession, InitializedEvent, OutputEvent, BreakpointEvent, TerminatedEvent, Event, Thread, StoppedEvent, StackFrame, ErrorDestination, Scope,} from 'vscode-debugadapter';
19+
import {DebugSession, InitializedEvent, OutputEvent, LoadedSourceEvent, BreakpointEvent, TerminatedEvent, Event, Thread, StoppedEvent, StackFrame, ErrorDestination, Scope,} from 'vscode-debugadapter';
2020
import {DebugProtocol} from 'vscode-debugprotocol';
2121
import * as Util from 'util';
2222
import * as Cp from 'child_process';
@@ -588,7 +588,11 @@ class EscargotDebugSession extends DebugSession {
588588
private onScriptParsed(data: EscargotMessageScriptParsed): void {
589589
this.log('onScriptParsed', LOG_LEVEL.SESSION);
590590

591-
this.handleSource(data);
591+
this.sendEvent(new LoadedSourceEvent('new', data.source));
592+
593+
if (data.breakpointsHandled) {
594+
this.setBreakpoints(data);
595+
}
592596
}
593597

594598
private async onWaitForSource(mode?: string): Promise<void> {
@@ -623,7 +627,7 @@ class EscargotDebugSession extends DebugSession {
623627

624628
// General helper functions
625629

626-
private async handleSource(data: EscargotMessageScriptParsed): Promise<void> {
630+
private async setBreakpoints(data: EscargotMessageScriptParsed): Promise<void> {
627631
try {
628632
const userBreakpoints: UserBreakpoints = this._userBreakpoints.get(data.source.path);
629633

src/EscargotProtocolHandler.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface EscargotMessageSource {
6868
export interface EscargotMessageScriptParsed {
6969
id: number;
7070
source: Source;
71-
breakpointsHandled: () => void;
71+
breakpointsHandled: () => void | null;
7272
}
7373

7474
export interface EscargotMessageBreakpointHit {
@@ -462,9 +462,33 @@ export class EscargotDebugProtocolHandler {
462462
}
463463

464464
private onParseErrorEnd(str: string): void {
465+
let source: Source = this.sources[this.nextScriptID].reference;
466+
465467
if (this.delegate.onOutput) {
466-
this.delegate.onOutput(`Exception: ${str}`, 'stderr');
468+
this.delegate.onOutput(`Parse error in ${source.path}:\n${str}`, 'stderr');
469+
}
470+
471+
if (source.sourceReference != 0) {
472+
let path: string = Path.join(this.localRoot, 'tmp_' + Path.basename(source.path));
473+
474+
try {
475+
Fs.writeFileSync(path, this.sources[this.nextScriptID].source);
476+
this.delegate.onOutput(`Saved as ${path}`, 'stderr');
477+
} catch {
478+
}
479+
}
480+
481+
this.newFunctions = {};
482+
483+
if (this.delegate.onScriptParsed) {
484+
this.delegate.onScriptParsed({
485+
id: this.nextScriptID,
486+
source,
487+
breakpointsHandled: null
488+
});
467489
}
490+
491+
this.nextScriptID++;
468492
}
469493

470494
private onParseError(data: Uint8Array): void {

0 commit comments

Comments
 (0)