8000 Merge branch 'master' into debugger · Netoperz/vscode-arduino@15f9b91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15f9b91

Browse files
committed
Merge branch 'master' into debugger
2 parents 37be0b7 + baaf686 commit 15f9b91

17 files changed

+330
-209
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line number 77F4 Diff line change
@@ -1,6 +1,21 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## Version 0.1.3
5+
- Release date: May 12, 2017
6+
### Added
7+
- Support auto-discovery of AZ3166 board
8+
9+
### Changed
10+
- Make activation condition to activate always for keeping USB auto-detection work background
11+
- Auto-resolve arduino path from Registry on windows
12+
- Well handle the case when vscode has no workspace
13+
14+
### Fixed
15+
- Fix the issue of HTML view showing weird background color in vscode 1.12.1
16+
- Fix arduino board installation failure on Mac after usb detection
17+
18+
419
## Version 0.1.2
520
- Release date: April 28, 2017
621

misc/usbmapping.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,14 @@
6363
"architecture": "samd",
6464
"id": "adafruit_feather_m0"
6565
}]
66+
}, {
67+
"index_file": "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json",
68+
"boards": [{
69+
"vid": "0483",
70+
"pid": "374b",
71+
"name": "MXCHIP AZ3166",
72+
"package": "AZ3166",
73+
"architecture": "stm32f4",
74+
"id": "MXCHIP_AZ3166"
75+
}]
6676
}]

package.json

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-arduino",
33
"displayName": "Arduino",
44
"description": "Arduino for Visual Studio Code",
5-
"version": "0.1.2",
5+
"version": "0.1.3",
66
"publisher": "vsciot-vscode",
77
"aiKey": "83dd2c27-6594-41d3-85a9-bdb22070eb42",
88
"preview": true,
@@ -24,18 +24,7 @@
2424
"C++"
2525
],
2626
"activationEvents": [
27-
"onLanguage:c",
28-
"onLanguage:cpp",
29-
"workspaceContains:.vscode/arduino.json",
30-
"onCommand:arduino.initialize",
31-
"onCommand:arduino.verify",
32-
"onCommand:arduino.upload",
33-
"onCommand:arduino.selectSerialPort",
34-
"onCommand:arduino.changeBoardType",
35-
"onCommand:arduino.showBoardManager",
36-
"onCommand:arduino.showLibraryManager",
37-
"onCommand:arduino.showExamples",
38-
"onCommand:arduino.debug.startSession"
27+
"*"
3928
],
4029
"main": "./out/src/extension",
4130
"contributes": {
@@ -517,4 +506,4 @@
517506
"winreg": "^1.2.3",
518507
"winston": "^2.3.1"
519508
}
520-
}
509+
}

src/arduino/arduino.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ export class ArduinoApp {
9696
if (!boardDescriptor) {
9797
return;
9898
}
99+
100+
if (!vscode.workspace.rootPath) {
101+
vscode.window.showWarningMessage("Cannot find the sketch file.");
102+
return;
103+
}
104+
99105
if (!dc.sketch || !util.fileExistsSync(path.join(vscode.workspace.rootPath, dc.sketch))) {
100106
await this.getMainSketch(dc);
101107
}
@@ -134,6 +140,11 @@ export class ArduinoApp {
134140
return;
135141
}
136142

143+
if (!vscode.workspace.rootPath) {
144+
vscode.window.showWarningMessage("Cannot find the sketch file.");
145+
return;
146+
}
147+
137148
if (!dc.sketch || !util.fileExistsSync(path.join(vscode.workspace.rootPath, dc.sketch))) {
138149
await this.getMainSketch(dc);
139150
}
@@ -167,7 +178,9 @@ export class ArduinoApp {
167178
} else {
168179
libPaths = this.getDefaultPackageLibPaths();
169180
}
170-
181+
if (!vscode.workspace.rootPath) {
182+
return;
183+
}
171184
const configFilePath = path.join(vscode.workspace.rootPath, constants.CPP_CONFIG_FILE);
172185
let deviceContext = null;
173186
if (!util.fileExistsSync(configFilePath)) {
@@ -218,6 +231,9 @@ export class ArduinoApp {
218231

219232
// Include the *.h header files from selected library to the arduino sketch.
220233
public async includeLibrary(libraryPath: string) {
234+
if (!vscode.workspace.rootPath) {
235+
return;
236+
}
221237
const dc = DeviceContext.getIntance();
222238
const appPath = path.join(vscode.workspace.rootPath, dc.sketch);
223239
if (util.fileExistsSync(appPath)) {

src/arduino/arduinoSettings.ts

Lines changed: 56 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*-------------------------------------------------------------------------------------------*/
55

6-
import * as fs from "fs";
76
import * as os from "os";
87
import * as path from "path";
98
import * as vscode from "vscode";
109
import * as WinReg from "winreg";
11-
12-
import * as constants from "../common/constants";
1310
import * as util from "../common/util";
1411

1512
import { resolveArduinoPath, validateArduinoPath } from "../common/platform";
@@ -43,8 +40,9 @@ export class ArduinoSettings implements IArduinoSettings {
4340

4441
public async initialize() {
4542
const platform = os.platform();
43+
await this.tryResolveArduinoPath();
4644
if (platform === "win32") {
47-
await this.updateWindowsPath(this.arduinoPath);
45+
await this.updateWindowsPath();
4846
} else if (platform === "linux") {
4947
this._packagePath = path.join(process.env.HOME, ".arduino15");
5048
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(process.env.HOME, "Arduino");
@@ -55,38 +53,14 @@ export class ArduinoSettings implements IArduinoSettings {
5553
}
5654

5755
public get arduinoPath(): string {
58-
if (this._arduinoPath) {
59-
return this._arduinoPath;
60-
} else {
61-
// Query arduino path sequentially from the following places such as "vscode user settings", "system environment variables",
62-
// "usual software installation directory for each os".
63-
// 1. Search vscode user settings first.
64-
const configValue = VscodeSettings.getIntance().arduinoPath;
65-
if (!configValue || !configValue.trim()) {
66-
// 2 & 3. Resolve arduino path from system environment varialbes and usual software installation directory.
67-
this._arduinoPath = resolveArduinoPath();
68-
} else {
69-
this._arduinoPath = configValue;
70-
}
71-
72-
if (!this._arduinoPath) { // Pop up vscode User Settings page when cannot resolve arduino path.
73-
vscode.window.showErrorMessage(`Cannot find the arduino installation path. Please specify the "arduino.path" in the User Settings.` +
74-
" Requires a restart after change.");
75-
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
76-
} else if (!validateArduinoPath(this._arduinoPath)) { // Validate if arduino path is the correct path.
77-
vscode.window.showErrorMessage(`Cannot find arduino executable program under directory "${this._arduinoPath}". ` +
78-
`Please set the correct "arduino.path" in the User Settings. Requires a restart after change.`);
79-
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
80-
}
81-
return this._arduinoPath;
82-
}
56+
return this._arduinoPath;
8357
}
8458

8559
public get defaultExamplePath(): string {
8660
if (os.platform() === "darwin") {
87-
return path.join(this.arduinoPath, "Arduino.app/Contents/Java/examples");
61+
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/examples");
8862
} else {
89-
return path.join(this.arduinoPath, "examples");
63+
return path.join(this._arduinoPath, "examples");
9064
}
9165
}
9266

@@ -96,28 +70,28 @@ export class ArduinoSettings implements IArduinoSettings {
9670

9771
public get defaultPackagePath(): string {
9872
if (os.platform() === "darwin") {
99-
return path.join(this.arduinoPath, "Arduino.app/Contents/Java/hardware");
73+
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/hardware");
10074
} else { // linux and win32.
101-
return path.join(this.arduinoPath, "hardware");
75+
return path.join(this._arduinoPath, "hardware");
10276
}
10377
}
10478

10579
public get defaultLibPath(): string {
10680
if (os.platform() === "darwin") {
107-
return path.join(this.arduinoPath, "Arduino.app/Contents/Java/libraries");
81+
return path.join(this._arduinoPath, "Arduino.app/Contents/Java/libraries");
10882
} else { // linux and win32
109-
return path.join(this.arduinoPath, "libraries");
83+
return path.join(this._arduinoPath, "libraries");
11084
}
11185
}
11286

11387
public get commandPath(): string {
11488
const platform = os.platform();
11589
if (platform === "darwin") {
116-
return path.join(this.arduinoPath, path.normalize("Arduino.app/Contents/MacOS/Arduino"));
90+
return path.join(this._arduinoPath, path.normalize("Arduino.app/Contents/MacOS/Arduino"));
11791
} else if (platform === "linux") {
118-
return path.join(this.arduinoPath, "arduino");
92+
return path.join(this._arduinoPath, "arduino");
11993
} else if (platform === "win32") {
120-
return path.join(this.arduinoPath, "arduino_debug.exe");
94+
return path.join(this._arduinoPath, "arduino_debug.exe");
12195
}
12296
}
12397

@@ -145,44 +119,50 @@ export class ArduinoSettings implements IArduinoSettings {
145119
* - User change the location of the default *Documents* folder.
146120
* - Use the windows store Arduino app.
147121
*/
148-
private updateWindowsPath(arduinoPath: string): Thenable<boolean> {
149-
let docFolder = path.join(process.env.USERPROFILE, "Documents");
150-
return new Promise((resolve, reject) => {
151-
try {
152-
const regKey = new WinReg({
153-
hive: WinReg.HKCU,
154-
key: "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
155-
});
156-
157-
regKey.valueExists("Personal", (e, exists) => {
158-
if (!e && exists) {
159-
regKey.get("Personal", (err, result) => {
160-
if (!err && result) {
161-
docFolder = result.value;
162-
}
163-
resolve(docFolder);
164-
165-
});
166-
} else {
167-
resolve(docFolder);
168-
}
169-
});
170-
} catch (ex) {
171-
resolve(docFolder);
172-
}
173-
}).then((folder: string) => {
174-
// For some case, docFolder parsed from win32 registry looks like "%USERPROFILE%\Documents,
175-
// Should replace the environment variables with actual value.
176-
folder = folder.replace(/%([^%]+)%/g, (match, p1) => {
177-
return process.env[p1];
178-
});
179-
if (util.fileExistsSync(path.join(arduinoPath, "AppxManifest.xml"))) {
180-
this._packagePath = path.join(folder, "ArduinoData");
181-
} else {
182-
this._packagePath = path.join(process.env.LOCALAPPDATA, "Arduino15");
183-
}
184-
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(folder, "Arduino");
185-
return true;
122+
private async updateWindowsPath(): Promise<void> {
123+
let folder;
124+
try {
125+
folder = await util.getRegistryValues(WinReg.HKCU,
126+
"\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
127+
"Personal");
128+
} catch (ex) {
129+
}
130+
if (!folder) {
131+
folder = path.join(process.env.USERPROFILE, "Documents");
132+
}
133+
// For some case, docFolder parsed from win32 registry looks like "%USERPROFILE%\Documents,
134+
// Should replace the environment variables with actual value.
135+
folder = folder.replace(/%([^%]+)%/g, (match, p1) => {
136+
return process.env[p1];
186137
});
138+
if (util.fileExistsSync(path.join(this._arduinoPath, "AppxManifest.xml"))) {
139+
this._packagePath = path.join(folder, "ArduinoData");
140+
} else {
141+
this._packagePath = path.join(process.env.LOCALAPPDATA, "Arduino15");
142+
}
143+
this._sketchbookPath = this.preferences.get("sketchbook.path") || path.join(folder, "Arduino");
144+
}
145+
146+
private async tryResolveArduinoPath(): Promise<void> {
147+
// Query arduino path sequentially from the following places such as "vscode user settings", "system environment variables",
148+
// "usual software installation directory for each os".
149+
// 1. Search vscode user settings first.
150+
const configValue = VscodeSettings.getIntance().arduinoPath;
151+
if (!configValue || !configValue.trim()) {
152+
// 2 & 3. Resolve arduino path from system environment varialbes and usual software installation directory.
153+
this._arduinoPath = await Promise.resolve(resolveArduinoPath());
154+
} else {
155+
this._arduinoPath = configValue;
156+
}
157+
158+
if (!this._arduinoPath) { // Pop up vscode User Settings page when cannot resolve arduino path.
159+
vscode.window.showErrorMessage(`Cannot find the arduino installation path. Please specify the "arduino.path" in the User Settings.` +
160+
" Requires a restart after change.");
161+
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
162+
} else if (!validateArduinoPath(this._arduinoPath)) { // Validate if arduino path is the correct path.
163+
vscode.window.showErrorMessage(`Cannot find arduino executable program under directory "${this._arduinoPath}". ` +
164+
`Please set the correct "arduino.path" in the User Settings. Requires a restart after change.`);
165+
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
166+
}
187167
}
188168
}

src/arduino/boardManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ export class BoardManager {
107107

108108
public async updatePackageIndex(indexUri: string): Promise<boolean> {
109109
const indexFileName = this.getIndexFileName(indexUri);
110-
if (util.fileExistsSync(path.join(this._settings.packagePath, indexFileName))) {
111-
return false;
112-
}
110+
113111
let allUrls = this.getAdditionalUrls();
114112
if (!(allUrls.indexOf(indexUri) >= 0)) {
115113
allUrls = allUrls.concat(indexUri);

src/arduino/vscodeSettings.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
import * as vscode from "vscode";
77

8+
const configKeys = {
9+
ARDUINO_PATH: "arduino.path",
10+
ADDITIONAL_URLS: "arduino.additionalUrls",
11+
LOG_LEVEL: "arduino.logLevel",
12+
AUTO_UPDATE_INDEX_FILES: "arduino.autoUpdateIndexFiles",
13+
};
14+
815
export interface IVscodeSettings {
916
arduinoPath: string;
1017
additionalUrls: string | string[];
@@ -26,27 +33,32 @@ export class VscodeSettings implements IVscodeSettings {
2633
}
2734

2835
public get arduinoPath(): string {
29-
const workspaceConfig = vscode.workspace.getConfiguration();
30-
return workspaceConfig.get<string>("arduino.path");
36+
return this.getConfigValue<string>(configKeys.ARDUINO_PATH);
3137
}
3238

33-
public get additionalUrls(): string {
34-
const workspaceConfig = vscode.workspace.getConfiguration();
35-
return workspaceConfig.get<string>("arduino.additionalUrls");
39+
public get additionalUrls(): string | string[] {
40+
return this.getConfigValue<string | string[]>(configKeys.ADDITIONAL_URLS);
41+
}
42+
43+
public get autoUpdateIndexFiles(): boolean {
44+
return this.getConfigValue<boolean>(configKeys.AUTO_UPDATE_INDEX_FILES);
45+
}
46+
47+
public get logLevel(): string {
48+
return this.getConfigValue<string>(configKeys.LOG_LEVEL) || "info";
3649
}
3750

3851
public async updateAdditionalUrls(value) {
39-
const workspaceConfig = vscode.workspace.getConfiguration();
40-
await workspaceConfig.update("arduino.additionalUrls", value, true);
52+
await this.setConfigValue(configKeys.ADDITIONAL_URLS, value, true);
4153
}
4254

43-
public get autoUpdateIndexFiles(): boolean {
55+
private getConfigValue<T>(key: string): T {
4456
const workspaceConfig = vscode.workspace.getConfiguration();
45-
return workspaceConfig.get<boolean>("arduino.autoUpdateIndexFiles");
57+
return workspaceConfig.get<T>(key);
4658
}
4759

48-
public get logLevel(): string {
60+
private async setConfigValue(key: string, value, global: boolean = true) {
4961
const workspaceConfig = vscode.workspace.getConfiguration();
50-
return workspaceConfig.get<string>("arduino.logLevel") || "info";
62+
await workspaceConfig.update(key, value, global);
5163
}
5264
}

0 commit comments

Comments
 (0)
0