10000 refact some typos, useless codes. (#316) · Netoperz/vscode-arduino@9bb7e6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9bb7e6f

Browse files
authored
refact some typos, useless codes. (microsoft#316)
* refact some typos, useless codes. * refact some typos, useless codes.
1 parent 5c271f7 commit 9bb7e6f

16 files changed

+99
-132
lines changed

src/arduino/arduino.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as constants from "../common/constants";
1313
import * as util from "../common/util";
1414
import * as Logger from "../logger/logger";
1515

16-
import { DeviceContext, IDeviceContext } from "../deviceContext";
16+
import { DeviceContext } from "../deviceContext";
1717
import { IArduinoSettings } from "./arduinoSettings";
1818
import { BoardManager } from "./boardManager";
1919
import { ExampleManager } from "./exampleManager";
@@ -35,14 +35,14 @@ export class ArduinoApp {
3535
private _exampleManager: ExampleManager;
3636

3737
/**
38-
* @param {IArduinoSettings} ArduinoSetting object.
38+
* @param {IArduinoSettings} _settings ArduinoSetting object.
3939
*/
4040
constructor(private _settings: IArduinoSettings) {
4141
}
4242

4343
/**
4444
* Need refresh Arduino IDE's setting when starting up.
45-
* @param {boolean} force - Whether force initialzie the arduino
45+
* @param {boolean} force - Whether force initialize the arduino
4646
*/
4747
public async initialize(force: boolean = false) {
4848
if (!util.fileExistsSync(this._settings.preferencePath)) {
@@ -91,8 +91,8 @@ export class ArduinoApp {
9191
}
9292

9393
public async upload() {
94-
const dc = DeviceContext.getIntance();
95-
const boardDescriptor = this.getBoardBuildString(dc);
94+
const dc = DeviceContext.getInstance();
95+
const boardDescriptor = this.getBoardBuildString();
9696
if (!boardDescriptor) {
9797
return;
9898
}
@@ -113,17 +113,17 @@ export class ArduinoApp {
113113
arduinoChannel.show();
114114
arduinoChannel.start(`Upload sketch - ${dc.sketch}`);
115115

116-
const serialMonitor = SerialMonitor.getIntance();
116+
const serialMonitor = SerialMonitor.getInstance();
117117

118118
const needRestore = await serialMonitor.closeSerialMonitor(dc.port);
119119
await vscode.workspace.saveAll(false);
120120

121121
const appPath = path.join(vscode.workspace.rootPath, dc.sketch);
122122
const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, appPath];
123-
if (VscodeSettings.getIntance().logLevel === "verbose") {
123+
if (VscodeSettings.getInstance().logLevel === "verbose") {
124124
args.push("--verbose");
125125
}
126-
await util.spawn(this._settings.commandPath, arduinoChannel.channel, args).then(async (result) => {
126+
await util.spawn(this._settings.commandPath, arduinoChannel.channel, args).then(async () => {
127127
if (needRestore) {
128128
await serialMonitor.openSerialMonitor();
129129
}
@@ -134,8 +134,8 @@ export class ArduinoApp {
134134
}
135135

136136
public async verify(output: string = "") {
137-
const dc = DeviceContext.getIntance();
138-
const boardDescriptor = this.getBoardBuildString(dc);
137+
const dc = DeviceContext.getInstance();
138+
const boardDescriptor = this.getBoardBuildString();
139139
if (!boardDescriptor) {
140140
return;
141141
}
@@ -154,18 +154,18 @@ export class ArduinoApp {
154154
arduinoChannel.start(`Verify sketch - ${dc.sketch}`);
155155
const appPath = path.join(vscode.workspace.rootPath, dc.sketch);
156156
const args = ["--verify", "--board", boardDescriptor, appPath];
157-
if (VscodeSettings.getIntance().logLevel === "verbose") {
157+
if (VscodeSettings.getInstance().logLevel === "verbose") {
158158
args.push("--verbose");
159159
}
160-
if (output) {
161-
const outputPath = path.join(vscode.workspace.rootPath, output);
160+
if (output || dc.output) {
161+
const outputPath = path.join(vscode.workspace.rootPath, output || dc.output);
162162
args.push("--pref", `build.path=${outputPath}`);
163163
}
164164

165165
arduinoChannel.show();
166166
// we need to return the result of verify
167167
try {
168-
const result = await util.spawn(this._settings.commandPath, arduinoChannel.channel, args);
168+
await util.spawn(this._settings.commandPath, arduinoChannel.channel, args);
169169
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
170170
return true;
171171
} catch (reason) {
@@ -239,7 +239,7 @@ export class ArduinoApp {
239239
if (!vscode.workspace.rootPath) {
240240
return;
241241
}
242-
const dc = DeviceContext.getIntance();
242+
const dc = DeviceContext.getInstance();
243243
const appPath = path.join(vscode.workspace.rootPath, dc.sketch);
244244
if (util.fileExistsSync(appPath)) {
245245
const hFiles = glob.sync(`${libraryPath}/*.h`, {
@@ -398,7 +398,7 @@ export class ArduinoApp {
398398
});
399399
if (sketchFile) {
400400
// Generate arduino.json
401-
const dc = DeviceContext.getIntance();
401+
const dc = DeviceContext.getInstance();
402402
const arduinoJson = {
403403
sketch: sketchFile,
404404
port: dc.port || "COM1",
@@ -458,14 +458,13 @@ export class ArduinoApp {
458458
this._exampleManager = value;
459459
}
460460

461-
private getBoardBuildString(deviceContext: IDeviceContext): string {
461+
private getBoardBuildString(): string {
462462
const selectedBoard = this.boardManager.currentBoard;
463463
if (!selectedBoard) {
464464
Logger.notifyUserError("getBoardBuildString", new Error(constants.messages.NO_BOARD_SELECTED));
465465
return;
466466
}
467-
const boardString = selectedBoard.getBuildConfig();
468-
return boardString;
467+
return selectedBoard.getBuildConfig();
469468
}
470469

471470
private async getMainSketch(dc: DeviceContext) {

src/arduino/arduinoContentProvider.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import * as Constants from "../common/constants";
1010
import * as JSONHelper from "../common/cycle";
1111
import * as Logger from "../logger/logger";
1212
import { ArduinoApp } from "./arduino";
13-
import { IArduinoSettings } from "./arduinoSettings";
14-
import { BoardManager } from "./boardManager";
15-
import { LibraryManager } from "./libraryManager";
1613
import LocalWebServer from "./localWebServer";
1714
import { VscodeSettings } from "./vscodeSettings";
1815

@@ -21,7 +18,6 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
2118
private _onDidChange = new vscode.EventEmitter<vscode.Uri>();
2219

2320
constructor(
24-
private _settings: IArduinoSettings,
2521
private _arduinoApp: ArduinoApp,
2622
private _extensionPath: string) {
2723
this.initialize();
@@ -57,7 +53,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
5753
this._webserver.start();
5854
}
5955

60-
public provideTextDocumentContent(uri: vscode.Uri) {
56+
public provideTextDocumentContent(uri: vscode.Uri): string {
6157
let type = "";
6258
if (uri.toString() === Constants.BOARD_MANAGER_URI.toString()) {
6359
type = "boardmanager";
@@ -74,7 +70,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
7470
<html>
7571
<head>
7672
<script type="text/javascript">
77-
window.onload = function(event) {
73+
window.onload = function() {
7874
console.log('reloaded results window at time ${timeNow}ms');
7975
var doc = document.documentElement;
8076
var styles = window.getComputedStyle(doc);
@@ -108,7 +104,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
108104
}
109105

110106
public async getBoardPackages(req, res) {
111-
const update = (VscodeSettings.getIntance().autoUpdateIndexFiles && req.query.update === "true");
107+
const update = (VscodeSettings.getInstance().autoUpdateIndexFiles && req.query.update === "true");
112108
await this._arduinoApp.boardManager.loadPackages(update);
113109
return res.json({
114110
platforms: JSONHelper.decycle(this._arduinoApp.boardManager.platforms, undefined),
@@ -168,7 +164,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
168164
}
169165

170166
public async getLibraries(req, res) {
171-
const update = (VscodeSettings.getIntance().autoUpdateIndexFiles && req.query.update === "true");
167+
const update = (VscodeSettings.getInstance().autoUpdateIndexFiles && req.query.update === "true");
172168
await this._arduinoApp.libraryManager.loadLibraries(update);
173169
return res.json({
174170
libraries: this._arduinoApp.libraryManager.libraries,
@@ -264,9 +260,9 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
264260
}
265261
}
266262

267-
private async addHandlerWithLogger(handlerName: string, url: string, handler: (req, res) => void, post: boolean = false): Promise<void> {
263+
private addHandlerWithLogger(handlerName: string, url: string, handler: (req, res) => void, post: boolean = false): void {
268264
const wrappedHandler = async (req, res) => {
269-
const guid = Uuid().replace(/\-/g, "");
265+
const guid = Uuid().replace(/-/g, "");
270266
let properties = {};
271267
if (post) {
272268
properties = { ...req.body };

src/arduino/arduinoSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ export class ArduinoSettings implements IArduinoSettings {
147147
// Query arduino path sequentially from the following places such as "vscode user settings", "system environment variables",
148148
// "usual software installation directory for each os".
149149
// 1. Search vscode user settings first.
150-
const configValue = VscodeSettings.getIntance().arduinoPath;
150+
const configValue = VscodeSettings.getInstance().arduinoPath;
151151
if (!configValue || !configValue.trim()) {
152-
// 2 & 3. Resolve arduino path from system environment varialbes and usual software installation directory.
152+
// 2 & 3. Resolve arduino path from system environment variables and usual software installation directory.
153153
this._arduinoPath = await Promise.resolve(resolveArduinoPath());
154154
} else {
155155
this._arduinoPath = configValue;

src/arduino/board.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function parseBoardDescriptor(boardDescriptor: string, plat: IPlatform):
2828

2929
let boardObject = result.get(match[1]);
3030
if (!boardObject) {
31-
boardObject = new Board(match[1], plat, new Map<string, string>(), menuMap);
31+
boardObject = new Board(match[1], plat, menuMap);
3232
result.set(boardObject.board, boardObject);
3333
}
3434
if (match[2] === "name") {
@@ -44,21 +44,24 @@ export function parseBoardDescriptor(boardDescriptor: string, plat: IPlatform):
4444
const MENU_REGEX = /menu\.([^\.]+)\.([^\.]+)(\.?(\S+)?)/;
4545

4646
export class Board implements IBoard {
47-
48-
public board: string;
49-
5047
public name?: string;
5148

52-
public platform: IPlatform;
53-
5449
private _configItems: IBoardConfigItem[];
5550

56-
constructor(_board: string, _platform: IPlatform, _parameters: Map<string, string>, private _menuMap: Map<string, string>) {
57-
this.platform = _platform;
58-
this.board = _board;
51+
constructor(private _board: string,
52+
private _platform: IPlatform,
53+
private _menuMap: Map<string, string>) {
5954
this._configItems = [];
6055
}
6156

57+
public get board(): string {
58+
return this._board;
59+
}
60+
61+
public get platform(): IPlatform {
62+
return this._platform;
63+
}
64+
6265
public addParameter(key: string, value: string): void {
6366
const match = key.match(MENU_REGEX);
6467
if (match) {
@@ -83,9 +86,7 @@ export class Board implements IBoard {
8386
}
8487

8588
public getBuildConfig(): string {
86-
const config = this.customConfig;
87-
const res = `${this.getPackageName()}:${this.platform.architecture}:${this.board}${config ? ":" + config : ""}`;
88-
return res;
89+
return `${this.getPackageName()}:${this.platform.architecture}:${this.board}${this.customConfig ? ":" + this.customConfig : ""}`;
8990
}
9091

9192
/**
@@ -96,11 +97,9 @@ export class Board implements IBoard {
9697
}
9798

9899
public get customConfig(): string {
99-
let res;
100100
if (this._configItems && this._configItems.length > 0) {
101-
res = this._configItems.map((configItem) => `${configItem.id}=${configItem.selectedOption}`).join(",");
101+
return this._configItems.map((configItem) => `${configItem.id}=${configItem.selectedOption}`).join(",");
102102
}
103-
return res;
104103
}
105104

106105
public get configItems(): IBoardConfigItem[] {
@@ -125,7 +124,7 @@ export class Board implements IBoard {
125124
}
126125
if (targetConfig.selectedOption !== optionId) {
127126
targetConfig.selectedOption = optionId;
128-
const dc = DeviceContext.getIntance();
127+
const dc = DeviceContext.getInstance();
129128
dc.configuration = this.customConfig;
130129
return true;
131130
}

0 commit comments

Comments
 (0)
0