Skip to content

Commit f849558

Browse files
tdusnokiyichoi
authored andcommitted
Added source sending feature (#21)
IoT.js-Debug-DCO-1.0-Signed-off-by: Tibor Dusnoki [email protected]
1 parent 722a573 commit f849558

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
},
5757
"activationEvents": [
5858
"onDebug",
59-
"onCommand:iotjs-debug.initialConfigurations"
59+
"onCommand:iotjs-debug.initialConfigurations",
60+
"onCommand:iotjs-debug.getProgramName"
6061
],
6162
"main": "./out/extension.js",
6263
"files": [
@@ -114,6 +115,11 @@
114115
"type": "boolean",
115116
"description": "Allowes to log debug messages to the console.",
116117
"default": false
118+
},
119+
"program": {
120+
"type": "string",
121+
"description": "Absolute path to file. Leave it blank if you started server in normal mode.",
122+
"default": "${command:AskForProgramName}"
117123
}
118124
}
119125
}
@@ -130,10 +136,14 @@
130136
"port": 5001,
131137
"localRoot": "${workspaceRoot}",
132138
"stopOnEntry": false,
133-
"debugLog": false
139+
"debugLog": false,
140+
"program": "^\"\\${command:AskForProgramName}\""
134141
}
135142
}
136-
]
143+
],
144+
"variables": {
145+
"AskForProgramName": "iotjs-debug.getProgramName"
146+
}
137147
}
138148
]
139149
}

src/IotjsDebugger.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,28 @@ class IotjsDebugSession extends LoggingDebugSession {
132132
this.sendEvent(new TerminatedEvent());
133133
};
134134

135+
const onWaitForSource = () => {
136+
this.log('onWaitForSource');
137+
if (args.program !== '') {
138+
if (Fs.existsSync(`${args.localRoot}/${args.program}`)) {
139+
const content = Fs.readFileSync(`${args.localRoot}/${args.program}`, {
140+
encoding: 'utf8',
141+
flag: 'r'
142+
});
143+
this._protocolhandler.sendClientSource(args.program, content);
144+
} else {
145+
this.sendErrorResponse(response, 0, 'You must provide a valid path to source');
146+
}
147+
} else {
148+
this.sendErrorResponse(response, 0, 'You must provide a source');
149+
}
150+
};
151+
135152
const protocolDelegate = <JerryDebugProtocolDelegate>{
136153
onBreakpointHit,
137154
onResume,
138-
onScriptParsed
155+
onScriptParsed,
156+
onWaitForSource
139157
};
140158

141159
this._protocolhandler = new JerryDebugProtocolHandler(protocolDelegate, message => this.log(message));

src/IotjsDebuggerInterfaces.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
import { DebugProtocol } from 'vscode-debugprotocol';
1818

1919
export interface IAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
20-
// The IP address on which the server listening.
20+
// IP address on which the server listening.
2121
address: string;
22-
// The debug port to attach to.
22+
// Debug port to attach to.
2323
port: number;
24-
// The VSCode's root directory.
24+
// VSCode's root directory.
2525
localRoot?: string;
2626
// Automatically stop target after launch.
2727
stopOnEntry?: boolean;
28-
// Allowes to log debug messages to the console.
28+
// Allows to log debug messages to console.
2929
debugLog?: boolean;
30+
// Filename.
31+
program?: string;
32+
// Ask for filename if in wait-for-source mode.
33+
provideSource: boolean;
3034
}

src/JerryProtocolHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface JerryDebugProtocolDelegate {
4949
onError?(code: number, message: string): void;
5050
onResume?(): void;
5151
onScriptParsed?(message: JerryMessageScriptParsed): void;
52-
onWaitForSource?(): JerryMessageSource;
52+
onWaitForSource?(): void;
5353
}
5454

5555
export interface JerryMessageSource {

src/extension.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
'use strict';
1818

1919
import * as vscode from 'vscode';
20+
import * as fs from 'fs';
21+
import * as path from 'path';
2022

2123
const initialConfigurations = [{
2224
name: 'Attach',
@@ -26,7 +28,8 @@ const initialConfigurations = [{
2628
port: 5001,
2729
localRoot: '${workspaceRoot}',
2830
stopOnEntry: false,
29-
debugLog: false
31+
debugLog: false,
32+
program: '${command:AskForProgramName}'
3033
}];
3134

3235
const provideInitialConfigurations = (): string => {
@@ -42,9 +45,36 @@ const provideInitialConfigurations = (): string => {
4245
].join('\n');
4346
};
4447

48+
const getListOfFiles = (): Array<string> => {
49+
let wsFolders = Array<string>();
50+
let wsFiles = Array<string>();
51+
52+
vscode.workspace.workspaceFolders.forEach(folder => {
53+
wsFolders.push(folder.uri.fsPath);
54+
});
55+
56+
wsFolders.forEach(entry => {
57+
fs.readdirSync(entry).forEach(file => {
58+
if ((fs.statSync(`${entry}/${file}`)).isFile()) {
59+
if (path.extname(file).toLowerCase().match(/\.(js)$/i)) {
60+
wsFiles.push(file);
61+
}
62+
}
63+
});
64+
});
65+
return wsFiles;
66+
};
67+
68+
const getProgramName = (): Thenable<string> => {
69+
return vscode.window.showQuickPick(getListOfFiles(), {
70+
placeHolder: 'Select a file you want to debug or press Enter if you are in normal mode'
71+
});
72+
};
73+
4574
export const activate = (context: vscode.ExtensionContext) => {
4675
context.subscriptions.push(
47-
vscode.commands.registerCommand('iotjs-debug.provideInitialConfigurations', provideInitialConfigurations)
76+
vscode.commands.registerCommand('iotjs-debug.provideInitialConfigurations', provideInitialConfigurations),
77+
vscode.commands.registerCommand('iotjs-debug.getProgramName', getProgramName)
4878
);
4979
};
5080

0 commit comments

Comments
 (0)