Skip to content

Commit

Permalink
Upload via debug run support
Browse files Browse the repository at this point in the history
Debug console support
Give up to use nodemcu-tool
  • Loading branch information
Furkan DUMAN committed Jul 29, 2016
1 parent 178f054 commit 31251de
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 89 deletions.
8 changes: 3 additions & 5 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# NodeMCU Development Tools For Visual Studio Code
## Features

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

## TODO's

* Improve intellisense support for modules.
* Add signature support.
* Add documentation for modules.
* Support configurable baudrate, etc..
* Add more NodeMCU commands other than upload.

Expand Down
52 changes: 43 additions & 9 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "vscode-nodemcu",
"displayName": "NodeMcu",
"description": "Supports NodeMCU upload over serial port, lua error detection and lua optimization, intellisense",
"description": "Supports NodeMCU upload over serial port, debug console, lua error detection and lua optimization, intellisense",
"author": {
"name": "Furkan Duman",
"email": "[email protected]"
},
"license": "MIT",
"version": "1.0.4",
"version": "1.0.5",
"publisher": "fduman",
"icon": "esp8266.gif",
"repository": {
Expand All @@ -20,20 +20,52 @@
"engines": {
"vscode": "^0.10.10"
},
"keywords": [
"nodemcu",
"lua",
"debuggers"
],
"categories": [
"Languages",
"Debuggers",
"Other"
],
"activationEvents": [
"onLanguage:lua"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "nodemcu.upload",
"title": "Upload file to NodeMCU Device"
}
]
"debuggers": [
{
"type": "nodemcu",
"label": "NodeMCU Debug",

"program": "./out/src/debug.js",
"runtime": "node",

"configurationAttributes": {
"launch": {
"required": [ "program" ],
"properties": {
"program": {
"type": "string",
"description": "Absolute path to a text file.",
"default": "${file}"
}
}
}
},

"initialConfigurations": [
{
"name": "NodeMCU-Debug",
"type": "nodemcu",
"request": "launch",
"program": "${file}"
}
]
}
]
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
Expand All @@ -46,6 +78,8 @@
},
"dependencies": {
"vscode-languageclient": "^2.2.1",
"nodemcu-tool": "1.6.0"
"serialport": "4.0.1",
"vscode-debugprotocol": "^1.11.0",
"vscode-debugadapter": "^1.11.0"
}
}
18 changes: 18 additions & 0 deletions client/src/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out",
"preLaunchTask": "npm"
}
]
}
166 changes: 166 additions & 0 deletions client/src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

'use strict';

import {
DebugSession,
InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Event,
Thread
} from 'vscode-debugadapter';

import {DebugProtocol} from 'vscode-debugprotocol';
import {readFileSync} from 'fs';
import {basename} from 'path';

import * as nodemcu from "./nodeMcuCommunication";

export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
/** An absolute path to the program to debug. */
program: string;
}

class NodeMcuDebugSession extends DebugSession {

// we don't support multiple threads, so we can use a hardcoded ID for the default thread
private static THREAD_ID = 1;

// the contents (= lines) of the one and only file
private _sourceLines = new Array<string>();

private _terminal: nodemcu.NodeMcuCommunicator;

private _portclosing: boolean = false;

/**
* Creates a new debug adapter that is used for one debug session.
* We configure the default implementation of a debug adapter here.
*/
public constructor() {
super();

// this debugger uses zero-based lines and columns
this.setDebuggerLinesStartAt1(false);
this.setDebuggerColumnsStartAt1(false);
}


/**
* The 'initialize' request is the first request called by the frontend
* to interrogate the features the debug adapter provides.
*/
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {

// since this debug adapter can accept configuration requests like 'setBreakpoint' at any time,
// we request them early by sending an 'initializeRequest' to the frontend.
// The frontend will end the configuration sequence by calling 'configurationDone' request.
this.sendEvent(new InitializedEvent());

// This debug adapter implements the configurationDoneRequest.
response.body.supportsConfigurationDoneRequest = false;

// make VS Code to use 'evaluate' when hovering over source
response.body.supportsEvaluateForHovers = false;

// make VS Code to show a 'step back' button
response.body.supportsStepBack = false;

this.sendResponse(response);
}

protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {

let sourceCode = readFileSync(args.program).toString();
this._sourceLines = sourceCode.split('\n');

nodemcu.NodeMcuCommunicator.detectPort((error: string, ports: nodemcu.PortInformation[]) => {

if (ports.length > 0) {
this.sendEvent(new OutputEvent(`NodeMCU device found on: ` + ports[0].comName + "\n"));
this._terminal = new nodemcu.NodeMcuCommunicator(ports[0].comName);

this._terminal.registerOnPortDisconnect((error: string) => {
if (!this._portclosing) {
this.sendErrorResponse(response, 0, "NodeMCU device disconnected");
this.shutdown();
}
});

this._terminal.registerOnError((error: string) => {
this.sendErrorResponse(response, 0, "An error occured on NodeMCU device communication: " + error);
});

this._terminal.registerOnDataReceived((data: string) => {
this.sendEvent(new OutputEvent(data + "\n"));
});

this._terminal.registerOnPortOpen(() => {
this.sendEvent(new OutputEvent("Port opened\n"));
this.sendEvent(new OutputEvent("The file is uploading to NodeMCU device\n"));
this._terminal.uploadFile(this._sourceLines, basename(args.program));
});

this._terminal.open();
} else {

this.sendErrorResponse(response, 0, "NodeMCU device not found");
this.shutdown();
}
});
}

protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
if (this._terminal != null) {
this._portclosing = true;
this._terminal.close();
}

super.disconnectRequest(response, args);
}

protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
response.body = {
result: "",
variablesReference: 0
};

this._terminal.write(args.expression);

this.sendResponse(response);
}

protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {

// return the default thread
response.body = {
threads: [
new Thread(NodeMcuDebugSession.THREAD_ID, "thread 1")
]
};
this.sendResponse(response);
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
}

protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
}

protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
}

protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): void {
}

protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void {
}

protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
}

protected stepBackRequest(response: DebugProtocol.StepBackResponse, args: DebugProtocol.StepBackArguments): void {
}
}

DebugSession.run(NodeMcuDebugSession);
12 changes: 0 additions & 12 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import * as path from 'path';

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

export function activate(context: ExtensionContext) {

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

// Create the language client and start the client.
let disposable = new LanguageClient('Language Server Example', serverOptions, clientOptions).start();
let command = commands.registerCommand('nodemcu.upload', () => {
if (window.activeTextEditor && window.activeTextEditor.document.languageId == "lua") {
nodemanager.findDevice((device) => {
nodemanager.uploadFile(device, window.activeTextEditor.document.fileName);
}
);
} else{
window.showErrorMessage("There must be an opened lua file");
}
});

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
Expand Down
Loading

0 comments on commit 31251de

Please sign in to comment.