From 8d244e516651d2669953efd78b01940b2f1215d7 Mon Sep 17 00:00:00 2001 From: jakergrossman Date: Thu, 18 Nov 2021 12:00:46 -0600 Subject: [PATCH] Add logger, output --- package.json | 55 ++++++++++++++++++++++++++--------------------- src/extension.ts | 11 ++++------ src/hubManager.ts | 12 +++++------ 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 0f7c969..2c21fa6 100644 --- a/package.json +++ b/package.json @@ -56,35 +56,35 @@ "title": "Run Cursor Context" }, - { - "command": "mind-reader.connectHub", - "title": "Connect LEGO Hub" - }, + { + "command": "mind-reader.connectHub", + "title": "Connect LEGO Hub" + }, - { - "command": "mind-reader.disconnectHub", - "title": "Disconnect LEGO Hub" - }, + { + "command": "mind-reader.disconnectHub", + "title": "Disconnect LEGO Hub" + }, - { - "command": "mind-reader.uploadCurrentFile", - "title": "Upload current file to LEGO Hub" - }, + { + "command": "mind-reader.uploadCurrentFile", + "title": "Upload current file to LEGO Hub" + }, - { - "command": "mind-reader.runProgram", - "title": "Run a program from the LEGO Hub" - }, + { + "command": "mind-reader.runProgram", + "title": "Run a program from the LEGO Hub" + }, - { - "command": "mind-reader.stopExecution", - "title": "Stop running program on the LEGO Hub" - }, + { + "command": "mind-reader.stopExecution", + "title": "Stop running program on the LEGO Hub" + }, - { - "command": "mind-reader.deleteProgram", - "title": "Delete a program from the LEGO Hub" - } + { + "command": "mind-reader.deleteProgram", + "title": "Delete a program from the LEGO Hub" + } ], "keybindings": [ { @@ -207,7 +207,12 @@ "mindreader.connection.portPath": { "type": "string", "markdownDescription": "Specifies the serial port path to use if `#mindreader.connectAutomatically#` is not set." - } + }, + "mindreader.connection.clearOutputOnRun": { + "type": "boolean", + "description": "Whether to clear the output each time the program is run", + "default": "true" + } } }, "views": { diff --git a/src/extension.ts b/src/extension.ts index 40e0294..d527a33 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,17 +1,14 @@ import * as vscode from 'vscode'; - import * as pl from './pylex'; + import commands from './commands'; import AccessNodeProvider from './accessNodeProvider'; +import Logger from './log'; -// create output channel +// Output Logger const outputChannel = vscode.window.createOutputChannel("SPIKE Prime Output"); - -export function MindReaderOutput(line: string) { - outputChannel.show(); - outputChannel.appendLine(line); -} +export const logger = new Logger(outputChannel); let parser: pl.Parser = new pl.Parser(); diff --git a/src/hubManager.ts b/src/hubManager.ts index 31fac9f..5a2d1b0 100644 --- a/src/hubManager.ts +++ b/src/hubManager.ts @@ -2,7 +2,8 @@ import * as vscode from 'vscode'; import * as SerialPort from 'serialport'; import * as fs from 'fs'; import { performance } from 'perf_hooks'; -import { MindReaderOutput } from './extension'; + +import { logger } from './extension'; /** * @type RPCRequest an RPC request message @@ -104,11 +105,11 @@ export default class HubManager { const params = json['p']; switch (json['m']) { case 'user_program_error': - MindReaderOutput(Buffer.from(params[3], 'base64').toString()); - MindReaderOutput(Buffer.from(params[4], 'base64').toString()); + logger.error(Buffer.from(params[3], 'base64').toString()); + logger.error(Buffer.from(params[4], 'base64').toString()); break; case 'runtime_error': - MindReaderOutput(Buffer.from(params[3], 'base64').toString()); + logger.error(Buffer.from(params[3], 'base64').toString()); break; } } @@ -141,7 +142,7 @@ export default class HubManager { let mgr = this; this.port.on('data', data => { - mgr.receiveData(data) + mgr.receiveData(data); }); } @@ -364,7 +365,6 @@ export default class HubManager { options = { port: '/dev/ttyACM0', magic: true, - timeout: 2500, ...options };