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

Commit faf7735

Browse files
authored
Merge pull request #1425 from microsoft/dev/bemcmorr/bug-fixes
Show all supported boards and set default build directory
2 parents cdf1d94 + 68b8f23 commit faf7735

File tree

11 files changed

+62
-62
lines changed

11 files changed

+62
-62
lines changed

src/arduino/boardManager.ts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as util from "../common/util";
99

1010
import * as constants from "../common/constants";
1111
import { arduinoChannel } from "../common/outputChannel";
12+
import { versionCompare } from "../common/sharedUtilities/utils";
1213
import { DeviceContext } from "../deviceContext";
1314
import { ArduinoApp } from "./arduino";
1415
import { IArduinoSettings } from "./arduinoSettings";
@@ -228,6 +229,11 @@ export class BoardManager {
228229
// });
229230
if (addedPlatform.name === plat.name) {
230231
addedPlatform.versions.push(plat.version);
232+
// Check if this is the latest version. Platforms typically support more boards in later versions.
233+
addedPlatform.versions.sort(versionCompare);
234+
if (plat.version === addedPlatform.versions[addedPlatform.versions.length - 1]) {
235+
addedPlatform.boards = plat.boards;
236+
}
231237
}
232238
} else {
233239
plat.versions = [plat.version];

src/common/sharedUtilities/utils.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
// This file should work in both VS Code and browser contexts.
5+
6+
export function versionCompare(a, b) {
7+
return versionArrayCompare(a.split("."), b.split("."));
8+
}
9+
10+
function versionArrayCompare(a: any[], b: any[]) {
11+
for (let i = 0; i < Math.min(a.length, b.length); i++) {
12+
const na = parseInt(a[i], 10);
13+
const nb = parseInt(b[i], 10);
14+
if (!isNaN(na) && !isNaN(nb)) {
15+
if (na > nb) {
16+
return 1;
17+
} else if (nb > na) {
18+
return -1;
19+
}
20+
const compare = (isNaN(a[i]) ? -1 : 1) - (isNaN(b[i]) ? -1 : 1);
21+
if (compare !== 0) {
22+
return compare;
23+
}
24+
} else if (!isNaN(na) && isNaN(nb)) {
25+
return 1;
26+
} else if (isNaN(na) && !isNaN(nb)) {
27+
return -1;
28+
} else {
29+
const re = /-|\+/;
30+
const subA = a[i].split(re);
31+
const subB = b[i].split(re);
32+
if (subA.length > 1 || subB.length > 1 || subA[0] !== a[i] || subB[0] !== b[i]) {
33+
const compare = versionArrayCompare(subA, subB);
34+
if (compare !== 0) {
35+
return compare;
36+
}
37+
}
38+
}
39+
}
40+
return a.length - b.length;
41+
}

src/deviceContext.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -312,29 +312,14 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
312312
.then(async (fileUris) => {
313313
if (fileUris.length === 0) {
314314
let newSketchFileName = await vscode.window.showInputBox({
315-
value: "my-sketch.ino",
315+
value: "sketch.ino",
316316
prompt: "No sketch (*.ino) found in workspace, please provide a name",
317317
placeHolder: "Sketch file name (*.ino or *.cpp)",
318318
validateInput: (value) => {
319-
/* TODO (EW, 2020-02-18):
320-
* is 'c' actually allowed? Also found on within other files.
321-
* And the regular expression doesn't need the internal groups.
322-
* The outer group can be an anonymous group.
323-
* And \w doesn't match dashes - so any sketch containing dashes
324-
* will not be found.
325-
* The correct expression therefore would be something like this:
326-
*
327-
* /^[\w\-]+\.(?:ino|cpp)$/
328-
*
329-
* I'd recommend to define such regular expressions (including)
330-
* line splitting etc.) at the global constants file.
331-
* This is true for any hard coded paths (like the snippets below)
332-
* as well.
333-
*/
334-
if (value && /^\w+\.((ino)|(cpp)|c)$/.test(value.trim())) {
319+
if (value && /^[\w-]+\.(?:ino|cpp)$/.test(value.trim())) {
335320
return null;
336321
} else {
337-
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
322+
return "Invalid sketch file name. Should be *.ino/*.cpp";
338323
}
339324
},
340325
});
@@ -343,6 +328,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
343328
const snippets = fs.readFileSync(path.join(this.extensionPath, "snippets", "sample.ino"));
344329
fs.writeFileSync(path.join(ArduinoWorkspace.rootPath, newSketchFileName), snippets);
345330
this.sketch = newSketchFileName;
331+
// Set a build directory in new configurations to avoid warnings about slow builds.
332+
this.output = "build";
346333
// Open the new sketch file.
347334
const textDocument = await vscode.workspace.openTextDocument(path.join(ArduinoWorkspace.rootPath, newSketchFileName));
348335
vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One, true);

src/views/app/components/BoardItemView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import * as React from "react";
55
import { Button, DropdownButton, MenuItem } from "react-bootstrap";
6+
import { versionCompare } from "../../../common/sharedUtilities/utils";
67
import * as API from "../actions/api";
7-
import { versionCompare } from "../utils/util";
88

99
interface IBoardProps extends React.Props<any> {
1010
platform: any;

src/views/app/components/BoardManager.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as React from "react";
55
import { Button, DropdownButton, MenuItem } from "react-bootstrap";
66
import { connect } from "react-redux";
77
import SearchInput, { createFilter } from "react-search-input";
8+
import { versionCompare } from "../../../common/sharedUtilities/utils";
89
import * as actions from "../actions";
910
import * as API from "../actions/api";
10-
import { versionCompare } from "../utils/util";
1111
import BoardItemView from "./BoardItemView";
1212

1313
interface IBoardManagerProps extends React.Props<any> {

src/views/app/components/LibraryItemView.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as React from "react";
55
import { Button, DropdownButton, MenuItem } from "react-bootstrap";
6+
import { versionCompare } from "../../../common/sharedUtilities/utils";
67
import * as API from "../actions/api";
78
import * as util from "../utils/util";
89

@@ -133,7 +134,7 @@ export default class LibraryItemView extends React.Component<ILibraryProps, ILib
133134
)
134135
}
135136
{
136-
lib.versions && lib.versions.length && util.versionCompare(lib.versions[0], lib.version) > 0 && (
137+
lib.versions && lib.versions.length && versionCompare(lib.versions[0], lib.version) > 0 && (
137138
<Button className="operation-btn" onClick={() => this.installLibrary(lib.name, lib.versions[0])}>Update</Button>
138139
)
139140
}

src/views/app/components/LibraryManager.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Button, Checkbox, DropdownButton, MenuItem } from "react-bootstrap";
66
import * as ReactList from "react-list";
77
import { connect } from "react-redux";
88
import SearchInput, { createFilter } from "react-search-input";
9+
import { versionCompare } from "../../../common/sharedUtilities/utils";
910
import * as actions from "../actions";
10-
import { versionCompare } from "../utils/util";
1111
import LibraryItemView from "./LibraryItemView";
1212

1313
interface ILibraryManagerProps extends React.Props<any> {

src/views/app/reducers/boardManagerReducer.ts

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

4+
import { versionCompare } from "../../../common/sharedUtilities/utils";
45
import * as actions from "../actions";
56
import * as util from "../utils/util";
67

@@ -28,7 +29,7 @@ export default function boardManagerReducer(state = initalState, action) {
2829
const categories = util.parseGroups(action.platforms, "category");
2930
// Sorting versions in descending order.
3031
action.platforms.forEach((element) => {
31-
element.versions = element.versions.sort(util.versionCompare).reverse();
32+
element.versions = element.versions.sort(versionCompare).reverse();
3233
});
3334
return {
3435
...state,

src/views/app/reducers/libraryManagerReducer.ts

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

4+
import { versionCompare } from "../../../common/sharedUtilities/utils";
45
import * as actions from "../actions";
56
import * as util from "../utils/util";
67

@@ -30,7 +31,7 @@ export default function libraryManagerReducer(state = initalState, action) {
3031
// Sorting versions in descending order.
3132
// for loop is faster than forEach iterator.
3233
for (const element of action.libraries) {
33-
element.versions = element.versions ? element.versions.sort(util.versionCompare).reverse() : element.versions;
34+
element.versions = element.versions ? element.versions.sort(versionCompare).reverse() : element.versions;
3435
}
3536
return {
3637
...state,

src/views/app/utils/util.ts

-37
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,6 @@ export function parseGroups(sourceArray: any[], key): any[] {
2020
return Object.keys(groups);
2121
}
2222

23-
export function versionCompare(a, b) {
24-
return versionArrayCompare(a.split("."), b.split("."));
25-
}
26-
27-
function versionArrayCompare(a: any[], b: any[]) {
28-
for (let i = 0; i < Math.min(a.length, b.length); i++) {
29-
const na = parseInt(a[i], 10);
30-
const nb = parseInt(b[i], 10);
31-
if (!isNaN(na) && !isNaN(nb)) {
32-
if (na > nb) {
33-
return 1;
34-
} else if (nb > na) {
35-
return -1;
36-
}
37-
const compare = (isNaN(a[i]) ? -1 : 1) - (isNaN(b[i]) ? -1 : 1);
38-
if (compare !== 0) {
39-
return compare;
40-
}
41-
} else if (!isNaN(na) && isNaN(nb)) {
42-
return 1;
43-
} else if (isNaN(na) && !isNaN(nb)) {
44-
return -1;
45-
} else {
46-
const re = /-|\+/;
47-
const subA = a[i].split(re);
48-
const subB = b[i].split(re);
49-
if (subA.length > 1 || subB.length > 1 || subA[0] !== a[i] || subB[0] !== b[i]) {
50-
const compare = versionArrayCompare(subA, subB);
51-
if (compare !== 0) {
52-
return compare;
53-
}
54-
}
55-
}
56-
}
57-
return a.length - b.length;
58-
}
59-
6023
export function shallowEqual(objA, objB, keys?: any[]) {
6124
if (Object.is(objA, objB)) {
6225
return true;

src/views/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"outDir": "out",
88
"alwaysStrict": true,
99
"sourceMap": true,
10-
"rootDir": "."
10+
"rootDirs": [".", "../common/sharedUtilities"]
1111
},
1212
"exclude": [
1313
"node_modules"

0 commit comments

Comments
 (0)