Skip to content

Commit 31251de

Browse files
author
Furkan DUMAN
committed
Upload via debug run support
Debug console support Give up to use nodemcu-tool
1 parent 178f054 commit 31251de

11 files changed

+388
-89
lines changed

client/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# NodeMCU Development Tools For Visual Studio Code
22
## Features
33

4-
* Intellisense supported for some NodeMCU modules.
4+
* Intellisense supported for almost all NodeMCU modules.
55
* Lua error detection supported. (It can only detect the first error because of luaparse's limitations)
6-
* Uploading lua file to NodeMCU-ESP 8266 device supported.
6+
* Uploading lua file on debug run to NodeMCU-ESP 8266 device supported.
7+
* Debug console supported (evaluation of commands on debug console also supported)
78

89
## TODO's
910

10-
* Improve intellisense support for modules.
11-
* Add signature support.
12-
* Add documentation for modules.
1311
* Support configurable baudrate, etc..
1412
* Add more NodeMCU commands other than upload.
1513

client/package.json

+43-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "vscode-nodemcu",
33
"displayName": "NodeMcu",
4-
"description": "Supports NodeMCU upload over serial port, lua error detection and lua optimization, intellisense",
4+
"description": "Supports NodeMCU upload over serial port, debug console, lua error detection and lua optimization, intellisense",
55
"author": {
66
"name": "Furkan Duman",
77
"email": "[email protected]"
88
},
99
"license": "MIT",
10-
"version": "1.0.4",
10+
"version": "1.0.5",
1111
"publisher": "fduman",
1212
"icon": "esp8266.gif",
1313
"repository": {
@@ -20,20 +20,52 @@
2020
"engines": {
2121
"vscode": "^0.10.10"
2222
},
23+
"keywords": [
24+
"nodemcu",
25+
"lua",
26+
"debuggers"
27+
],
2328
"categories": [
29+
"Languages",
30+
"Debuggers",
2431
"Other"
2532
],
2633
"activationEvents": [
2734
"onLanguage:lua"
2835
],
2936
"main": "./out/src/extension",
3037
"contributes": {
31-
"commands": [
32-
{
33-
"command": "nodemcu.upload",
34-
"title": "Upload file to NodeMCU Device"
35-
}
36-
]
38+
"debuggers": [
39+
{
40+
"type": "nodemcu",
41+
"label": "NodeMCU Debug",
42+
43+
"program": "./out/src/debug.js",
44+
"runtime": "node",
45+
46+
"configurationAttributes": {
47+
"launch": {
48+
"required": [ "program" ],
49+
"properties": {
50+
"program": {
51+
"type": "string",
52+
"description": "Absolute path to a text file.",
53+
"default": "${file}"
54+
}
55+
}
56+
}
57+
},
58+
59+
"initialConfigurations": [
60+
{
61+
"name": "NodeMCU-Debug",
62+
"type": "nodemcu",
63+
"request": "launch",
64+
"program": "${file}"
65+
}
66+
]
67+
}
68+
]
3769
},
3870
"scripts": {
3971
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
@@ -46,6 +78,8 @@
4678
},
4779
"dependencies": {
4880
"vscode-languageclient": "^2.2.1",
49-
"nodemcu-tool": "1.6.0"
81+
"serialport": "4.0.1",
82+
"vscode-debugprotocol": "^1.11.0",
83+
"vscode-debugadapter": "^1.11.0"
5084
}
5185
}

client/src/.vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"runtimeExecutable": "${execPath}",
9+
"args": [
10+
"--extensionDevelopmentPath=${workspaceRoot}"
11+
],
12+
"stopOnEntry": false,
13+
"sourceMaps": true,
14+
"outDir": "${workspaceRoot}/out",
15+
"preLaunchTask": "npm"
16+
}
17+
]
18+
}

client/src/debug.ts

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
'use strict';
6+
7+
import {
8+
DebugSession,
9+
InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Event,
10+
Thread
11+
} from 'vscode-debugadapter';
12+
13+
import {DebugProtocol} from 'vscode-debugprotocol';
14+
import {readFileSync} from 'fs';
15+
import {basename} from 'path';
16+
17+
import * as nodemcu from "./nodeMcuCommunication";
18+
19+
export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
20+
/** An absolute path to the program to debug. */
21+
program: string;
22+
}
23+
24+
class NodeMcuDebugSession extends DebugSession {
25+
26+
// we don't support multiple threads, so we can use a hardcoded ID for the default thread
27+
private static THREAD_ID = 1;
28+
29+
// the contents (= lines) of the one and only file
30+
private _sourceLines = new Array<string>();
31+
32+
private _terminal: nodemcu.NodeMcuCommunicator;
33+
34+
private _portclosing: boolean = false;
35+
36+
/**
37+
* Creates a new debug adapter that is used for one debug session.
38+
* We configure the default implementation of a debug adapter here.
39+
*/
40+
public constructor() {
41+
super();
42+
43+
// this debugger uses zero-based lines and columns
44+
this.setDebuggerLinesStartAt1(false);
45+
this.setDebuggerColumnsStartAt1(false);
46+
}
47+
48+
49+
/**
50+
* The 'initialize' request is the first request called by the frontend
51+
* to interrogate the features the debug adapter provides.
52+
*/
53+
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
54+
55+
// since this debug adapter can accept configuration requests like 'setBreakpoint' at any time,
56+
// we request them early by sending an 'initializeRequest' to the frontend.
57+
// The frontend will end the configuration sequence by calling 'configurationDone' request.
58+
this.sendEvent(new InitializedEvent());
59+
60+
// This debug adapter implements the configurationDoneRequest.
61+
response.body.supportsConfigurationDoneRequest = false;
62+
63+
// make VS Code to use 'evaluate' when hovering over source
64+
response.body.supportsEvaluateForHovers = false;
65+
66+
// make VS Code to show a 'step back' button
67+
response.body.supportsStepBack = false;
68+
69+
this.sendResponse(response);
70+
}
71+
72+
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
73+
74+
let sourceCode = readFileSync(args.program).toString();
75+
this._sourceLines = sourceCode.split('\n');
76+
77+
nodemcu.NodeMcuCommunicator.detectPort((error: string, ports: nodemcu.PortInformation[]) => {
78+
79+
if (ports.length > 0) {
80+
this.sendEvent(new OutputEvent(`NodeMCU device found on: ` + ports[0].comName + "\n"));
81+
this._terminal = new nodemcu.NodeMcuCommunicator(ports[0].comName);
82+
83+
this._terminal.registerOnPortDisconnect((error: string) => {
84+
if (!this._portclosing) {
85+
this.sendErrorResponse(response, 0, "NodeMCU device disconnected");
86+
this.shutdown();
87+
}
88+
});
89+
90+
this._terminal.registerOnError((error: string) => {
91+
this.sendErrorResponse(response, 0, "An error occured on NodeMCU device communication: " + error);
92+
});
93+
94+
this._terminal.registerOnDataReceived((data: string) => {
95+
this.sendEvent(new OutputEvent(data + "\n"));
96+
});
97+
98+
this._terminal.registerOnPortOpen(() => {
99+
this.sendEvent(new OutputEvent("Port opened\n"));
100+
this.sendEvent(new OutputEvent("The file is uploading to NodeMCU device\n"));
101+
this._terminal.uploadFile(this._sourceLines, basename(args.program));
102+
});
103+
104+
this._terminal.open();
105+
} else {
106+
107+
this.sendErrorResponse(response, 0, "NodeMCU device not found");
108+
this.shutdown();
109+
}
110+
});
111+
}
112+
113+
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
114+
if (this._terminal != null) {
115+
this._portclosing = true;
116+
this._terminal.close();
117+
}
118+
119+
super.disconnectRequest(response, args);
120+
}
121+
122+
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
123+
response.body = {
124+
result: "",
125+
variablesReference: 0
126+
};
127+
128+
this._terminal.write(args.expression);
129+
130+
this.sendResponse(response);
131+
}
132+
133+
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
134+
135+
// return the default thread
136+
response.body = {
137+
threads: [
138+
new Thread(NodeMcuDebugSession.THREAD_ID, "thread 1")
139+
]
140+
};
141+
this.sendResponse(response);
142+
}
143+
144+
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
145+
}
146+
147+
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
148+
}
149+
150+
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
151+
}
152+
153+
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): void {
154+
}
155+
156+
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void {
157+
}
158+
159+
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
160+
}
161+
162+
protected stepBackRequest(response: DebugProtocol.StepBackResponse, args: DebugProtocol.StepBackArguments): void {
163+
}
164+
}
165+
166+
DebugSession.run(NodeMcuDebugSession);

client/src/extension.ts

-12
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import * as path from 'path';
88

99
import { window, commands, workspace, Disposable, ExtensionContext } from 'vscode';
1010
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
11-
import * as nodemanager from "./nodeMcuManager";
1211

1312
export function activate(context: ExtensionContext) {
14-
1513
// The server is implemented in node
1614
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
1715
// The debug options for the server
@@ -38,16 +36,6 @@ export function activate(context: ExtensionContext) {
3836

3937
// Create the language client and start the client.
4038
let disposable = new LanguageClient('Language Server Example', serverOptions, clientOptions).start();
41-
let command = commands.registerCommand('nodemcu.upload', () => {
42-
if (window.activeTextEditor && window.activeTextEditor.document.languageId == "lua") {
43-
nodemanager.findDevice((device) => {
44-
nodemanager.uploadFile(device, window.activeTextEditor.document.fileName);
45-
}
46-
);
47-
} else{
48-
window.showErrorMessage("There must be an opened lua file");
49-
}
50-
});
5139

5240
// Push the disposable to the context's subscriptions so that the
5341
// client can be deactivated on extension deactivation

0 commit comments

Comments
 (0)