Skip to content
This repository was archived by the owner on Dec 22, 2024. It is now read-only.

Commit 1126a4b

Browse files
elektronikworkshophlovdal
authored andcommitted
Fixed tslint complaints
1 parent 085e5f8 commit 1126a4b

File tree

2 files changed

+78
-72
lines changed

2 files changed

+78
-72
lines changed

src/arduino/arduino.ts

+71-69
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
import * as ccp from "cocopa";
45
import * as fs from "fs";
56
import * as glob from "glob";
67
import * as os from "os";
78
import * as path from "path";
89
import * as vscode from "vscode";
9-
import * as ccp from "cocopa";
1010

1111
import * as constants from "../common/constants";
1212
import * as util from "../common/util";
@@ -94,33 +94,6 @@ export class ArduinoApp {
9494
}
9595
}
9696

97-
/** Runs the pre build command.
98-
* Usually before one of
99-
* * verify
100-
* * upload
101-
* * upload using programmer
102-
* @param dc Device context prepared during one of the above actions
103-
* @returns True if successful, false on error.
104-
*/
105-
protected async runPreBuildCommand(dc:DeviceContext): Promise<boolean>
106-
{
107-
if (dc.prebuild) {
108-
arduinoChannel.info(`Running pre-build command: ${dc.prebuild}`);
109-
const prebuildargs = dc.prebuild.split(" ");
110-
const prebuildCommand = prebuildargs.shift();
111-
try {
112-
await util.spawn(prebuildCommand,
113-
arduinoChannel.channel,
114-
prebuildargs,
115-
{ shell: true, cwd: ArduinoWorkspace.rootPath });
116-
} catch (ex) {
117-
arduinoChannel.error(`Running pre-build command failed: ${os.EOL}${ex.error}`);
118-
return false;
119-
}
120-
}
121-
return true;
122-
}
123-
12497
public async upload() {
12598
const dc = DeviceContext.getInstance();
12699
const boardDescriptor = this.getBoardBuildString();
@@ -315,16 +288,17 @@ export class ArduinoApp {
315288
arduinoChannel.show();
316289

317290
try {
318-
let compilerParserContext = this.makeCompilerParserContext(dc);
291+
const compilerParserContext = this.makeCompilerParserContext(dc);
319292

320293
await util.spawn(this._settings.commandPath,
321294
arduinoChannel.channel,
322295
args,
323296
{},
324297
compilerParserContext.callback);
325298

326-
compilerParserContext.conclude();
327-
299+
if (compilerParserContext.conclude) {
300+
compilerParserContext.conclude();
301+
}
328302
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
329303
return true;
330304
} catch (reason) {
@@ -338,44 +312,6 @@ export class ArduinoApp {
338312
}
339313
}
340314

341-
/** Creates a context which is used for compiler command parsing
342-
* during building (verify, upload, ...).
343-
*
344-
* This context makes sure that it can be used in those sections
345-
* without having to check whether this feature is en- or disabled
346-
* and keeps the calling context more readable.
347-
*
348-
* @param dc The device context of the caller.
349-
*/
350-
private makeCompilerParserContext(dc: DeviceContext)
351-
: { callback: (s:string)=>void; conclude: ()=>void; }
352-
{
353-
if (!VscodeSettings.getInstance().disableIntelliSenseAutoGen) {
354-
355-
// setup the parser with its engines
356-
let gccParserEngine = new ccp.ParserGcc(dc.sketch);
357-
let compilerParser = new ccp.Runner([gccParserEngine]);
358-
359-
// set up the function to be called after parsing
360-
let _conclude = () => {
361-
let cppPropsPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
362-
if (compilerParser.processResult(cppPropsPath)) {
363-
arduinoChannel.info("IntelliSense configuration generated successfully.");
364-
} else {
365-
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
366-
}
367-
};
368-
return {
369-
callback: compilerParser.callback(),
370-
conclude: _conclude,
371-
};
372-
}
373-
return {
374-
callback: undefined,
375-
conclude: ()=>void{},
376-
};
377-
};
378-
379315
public tryToUpdateIncludePaths() {
380316
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
381317
if (!fs.existsSync(configFilePath)) {
@@ -797,6 +733,72 @@ Please make sure the folder is not occupied by other procedures .`);
797733
this._programmerManager = value;
798734
}
799735

736+
/**
737+
* Runs the pre build command.
738+
* Usually before one of
739+
* * verify
740+
* * upload
741+
* * upload using programmer
742+
* @param dc Device context prepared during one of the above actions
743+
* @returns True if successful, false on error.
744+
*/
745+
protected async runPreBuildCommand(dc: DeviceContext): Promise<boolean> {
746+
if (dc.prebuild) {
747+
arduinoChannel.info(`Running pre-build command: ${dc.prebuild}`);
748+
const prebuildargs = dc.prebuild.split(" ");
749+
const prebuildCommand = prebuildargs.shift();
750+
try {
751+
await util.spawn(prebuildCommand,
752+
arduinoChannel.channel,
753+
prebuildargs,
754+
{ shell: true, cwd: ArduinoWorkspace.rootPath });
755+
} catch (ex) {
756+
arduinoChannel.error(`Running pre-build command failed: ${os.EOL}${ex.error}`);
757+
return false;
758+
}
759+
}
760+
return true;
761+
}
762+
763+
/**
764+
* Creates a context which is used for compiler command parsing
765+
* during building (verify, upload, ...).
766+
*
767+
* This context makes sure that it can be used in those sections
768+
* without having to check whether this feature is en- or disabled
769+
* and keeps the calling context more readable.
770+
*
771+
* @param dc The device context of the caller.
772+
*/
773+
private makeCompilerParserContext(dc: DeviceContext)
774+
: { callback: (s: string) => void; conclude: () => void; } {
775+
if (!VscodeSettings.getInstance().disableIntelliSenseAutoGen) {
776+
777+
// setup the parser with its engines
778+
const gccParserEngine = new ccp.ParserGcc(dc.sketch);
779+
const compilerParser = new ccp.Runner([gccParserEngine]);
780+
781+
// set up the function to be called after parsing
782+
const _conclude = () => {
783+
const cppPropsPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
784+
if (compilerParser.processResult(cppPropsPath)) {
785+
arduinoChannel.info("IntelliSense configuration generated successfully.");
786+
} else {
787+
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
788+
}
789+
};
790+
return {
791+
callback: compilerParser.callback(),
792+
conclude: _conclude,
793+
}
794+
}
795+
// const donothing = () => void {};
796+
return {
797+
callback: undefined,
798+
conclude: undefined,
799+
}
800+
};
801+
800802
private getProgrammerString(): string {
801803
const selectProgrammer = this.programmerManager.currentProgrammer;
802804
if (!selectProgrammer) {

src/common/util.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ export function isArduinoFile(filePath): boolean {
200200
return fileExistsSync(filePath) && (path.extname(filePath) === ".ino" || path.extname(filePath) === ".pde");
201201
}
202202

203-
type StdOutCallback = (msg: string)=>void;
203+
type StdOutCallback = (msg: string) => void;
204204

205-
export function spawn(command: string, outputChannel: vscode.OutputChannel, args: string[] = [], options: any = {}, stdoutCallback?: StdOutCallback): Thenable<object> {
205+
export function spawn(command: string,
206+
outputChannel: vscode.OutputChannel,
207+
args: string[] = [],
208+
options: any = {},
209+
stdoutCallback?: StdOutCallback): Thenable<object> {
206210
return new Promise((resolve, reject) => {
207211
const stdout = "";
208212
const stderr = "";
@@ -223,7 +227,7 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args
223227

224228
if (outputChannel) {
225229
child.stdout.on("data", (data: Buffer) => {
226-
let decoded = decodeData(data, codepage);
230+
const decoded = decodeData(data, codepage);
227231
outputChannel.append(decoded);
228232
if (stdoutCallback) {
229233
stdoutCallback(decoded);

0 commit comments

Comments
 (0)