Skip to content

Commit d580651

Browse files
knightburtonyichoi
authored andcommitted
Change the source sending send function to the promise based (#28)
IoT.js-Debug-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent f849558 commit d580651

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/IotjsDebugger.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,20 @@ class IotjsDebugSession extends LoggingDebugSession {
132132
this.sendEvent(new TerminatedEvent());
133133
};
134134

135-
const onWaitForSource = () => {
135+
const onWaitForSource = async () => {
136136
this.log('onWaitForSource');
137+
137138
if (args.program !== '') {
138139
if (Fs.existsSync(`${args.localRoot}/${args.program}`)) {
139140
const content = Fs.readFileSync(`${args.localRoot}/${args.program}`, {
140141
encoding: 'utf8',
141142
flag: 'r'
142143
});
143-
this._protocolhandler.sendClientSource(args.program, content);
144+
await this._protocolhandler.sendClientSource(args.program, content)
145+
.then(() => this.log('Source has been sended to the engine.'))
146+
.catch(error => {
147+
this.sendErrorResponse(response, 0, error);
148+
});
144149
} else {
145150
this.sendErrorResponse(response, 0, 'You must provide a valid path to source');
146151
}

src/JerryProtocolHandler.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,9 @@ export class JerryDebugProtocolHandler {
711711
return result;
712712
}
713713

714-
sendClientSource(fileName, fileSourceCode) {
714+
public sendClientSource(fileName: string, fileSourceCode: string): Promise<any> {
715715
if (!this.waitForSourceEnabled) {
716-
throw new Error('wait-for-source not enabled');
716+
return Promise.reject('wait-for-source not enabled');
717717
}
718718

719719
this.waitForSourceEnabled = false;
@@ -723,21 +723,20 @@ export class JerryDebugProtocolHandler {
723723
array[0] = SP.CLIENT.JERRY_DEBUGGER_CLIENT_SOURCE;
724724

725725
if (byteLength <= this.maxMessageSize) {
726-
this.debuggerClient.send(array);
727-
return true;
726+
return this.sendSimpleRequest(array);
728727
}
729728

730-
this.debuggerClient.send(array.slice(0, this.maxMessageSize));
729+
let result = this.sendSimpleRequest(array.slice(0, this.maxMessageSize));
731730

732731
let offset = this.maxMessageSize - 1;
733732

734733
while (offset < byteLength) {
735734
array[offset] = SP.CLIENT.JERRY_DEBUGGER_CLIENT_SOURCE_PART;
736-
this.debuggerClient.send(array.slice(offset, offset + this.maxMessageSize));
735+
result = this.sendSimpleRequest(array.slice(offset, offset + this.maxMessageSize));
737736
offset += this.maxMessageSize - 1;
738737
}
739738

740-
return true;
739+
return result;
741740
}
742741

743742
onWaitForSource() {

src/extension.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ const provideInitialConfigurations = (): string => {
4646
};
4747

4848
const getListOfFiles = (): Array<string> => {
49-
let wsFolders = Array<string>();
5049
let wsFiles = Array<string>();
5150

52-
vscode.workspace.workspaceFolders.forEach(folder => {
53-
wsFolders.push(folder.uri.fsPath);
54-
});
55-
56-
wsFolders.forEach(entry => {
51+
vscode.workspace.workspaceFolders.map(folder => folder.uri.fsPath).forEach(entry => {
5752
fs.readdirSync(entry).forEach(file => {
5853
if ((fs.statSync(`${entry}/${file}`)).isFile()) {
5954
if (path.extname(file).toLowerCase().match(/\.(js)$/i)) {
@@ -62,12 +57,14 @@ const getListOfFiles = (): Array<string> => {
6257
}
6358
});
6459
});
65-
return wsFiles;
60+
61+
return ['', ...wsFiles];
6662
};
6763

6864
const getProgramName = (): Thenable<string> => {
6965
return vscode.window.showQuickPick(getListOfFiles(), {
70-
placeHolder: 'Select a file you want to debug or press Enter if you are in normal mode'
66+
placeHolder: 'Select a file you want to debug or press Enter if you are in normal mode',
67+
ignoreFocusOut: true
7168
});
7269
};
7370

0 commit comments

Comments
 (0)