Skip to content

Commit bf1e02f

Browse files
authored
Merge pull request #217 from paulober/develop
Patch v3.7.6
2 parents 8ac4292 + 30bb4cd commit bf1e02f

File tree

8 files changed

+513
-353
lines changed

8 files changed

+513
-353
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ All notable changes to the "MicroPico" extension will be documented in this file
1010

1111
---
1212

13+
## [3.7.6] - 2024-04-30
14+
15+
### Changed
16+
- Updated dependencies
17+
- Fixed #215 and #209, Failed to switch stubs on Linux and macOS / use stubs on external drive
18+
1319
## [3.7.5] - 2024-02-22
1420

1521
### Changed

package-lock.json

Lines changed: 336 additions & 270 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pico-w-go",
33
"displayName": "MicroPico",
44
"description": "Auto-completion, remote workspace and a REPL console integration for the Raspberry Pi Pico (W) with MicroPython firmware.",
5-
"version": "3.7.5",
5+
"version": "3.7.6",
66
"publisher": "paulober",
77
"license": "MPL-2.0",
88
"homepage": "https://github.com/paulober/MicroPico/blob/main/README.md",
@@ -589,26 +589,26 @@
589589
"@rollup/plugin-terser": "^0.4.4",
590590
"@rollup/plugin-typescript": "^11.1.6",
591591
"@types/fs-extra": "^11.0.4",
592-
"@types/lodash": "^4.14.202",
592+
"@types/lodash": "^4.17.0",
593593
"@types/mocha": "^10.0.6",
594-
"@types/node": "^18.x",
594+
"@types/node": "^18.17.x",
595595
"@types/uuid": "^9.0.8",
596596
"@types/vscode": "^1.86.0",
597597
"@types/which": "^3.0.3",
598-
"@typescript-eslint/eslint-plugin": "^7.0.2",
599-
"@typescript-eslint/parser": "^7.0.2",
598+
"@typescript-eslint/eslint-plugin": "^7.3.1",
599+
"@typescript-eslint/parser": "^7.3.1",
600600
"@vscode/test-electron": "^2.3.9",
601-
"eslint": "^8.56.0",
601+
"eslint": "^8.57.0",
602602
"eslint-config-prettier": "^9.1.0",
603603
"glob": "^9.3.4",
604604
"mocha": "^10.3.0",
605-
"rollup": "^4.12.0",
605+
"rollup": "^4.17.1",
606606
"rollup-plugin-copy": "^3.5.0",
607-
"typescript": "^5.3.3"
607+
"typescript": "^5.4.5"
608608
},
609609
"dependencies": {
610610
"@paulober/pyboard-serial-com": "^3.0.7",
611-
"axios": "^1.6.7",
611+
"axios": "^1.6.8",
612612
"fs-extra": "^11.2.0",
613613
"lodash": "^4.17.21",
614614
"rimraf": "^5.0.5",

src/activator.mts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class Activator {
6666
);
6767

6868
this.stubs = new Stubs();
69-
await this.stubs.update();
69+
await this.stubs.update(settings);
7070

7171
this.comDevice = await settings.getComDevice();
7272

@@ -354,6 +354,14 @@ export default class Activator {
354354
frozen = true;
355355
}
356356
if (data.includes("!!ERR!!")) {
357+
this.logger.error(
358+
"Exception occured (maybe a connection loss). " +
359+
`Message dump: ${data}`
360+
);
361+
console.log(
362+
"Exception occured (maybe a connection loss). " +
363+
`Message dump: ${data}`
364+
);
357365
// write red text into terminal
358366
terminal?.write(
359367
"\x1b[31mException occured (maybe a connection loss)\x1b[0m\r\n"
@@ -1113,7 +1121,7 @@ export default class Activator {
11131121
}
11141122

11151123
if (version.toLowerCase() === "included") {
1116-
await installIncludedStubs();
1124+
await installIncludedStubs(settings);
11171125

11181126
void vscode.window.showInformationMessage("Included stubs selected.");
11191127
} else {
@@ -1131,7 +1139,8 @@ export default class Activator {
11311139
// TODO: implement cancellation
11321140
const result = await installStubsByVersion(
11331141
versionParts[1],
1134-
displayStringToStubPort(versionParts[0])
1142+
displayStringToStubPort(versionParts[0]),
1143+
settings
11351144
);
11361145

11371146
if (result) {
@@ -1266,7 +1275,7 @@ export default class Activator {
12661275
//this.ui?.refreshState(true);
12671276
this.logger.info("Connection to wrapper successfully established");
12681277
void vscode.window.showInformationMessage(
1269-
"Connection to Pico established."
1278+
"Connection to board established."
12701279
);
12711280

12721281
return;

src/activitybar/packagesWebview.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ export default class PackagesWebviewProvider implements WebviewViewProvider {
144144
);
145145

146146
const installedPackages = await this._getInstalledPackages();
147+
/* clean up the package names */
148+
installedPackages.forEach((pkg, i) => {
149+
installedPackages[i] = pkg.replace(".mpy", "").replace(".py", "");
150+
});
147151

148152
// Restrict the webview to only load specific scripts
149153
const nonce = getNonce();
@@ -167,7 +171,7 @@ export default class PackagesWebviewProvider implements WebviewViewProvider {
167171
<div style="width: 100%;" class="input-div">
168172
${
169173
this._isDisabled
170-
? "<p>Your Pico must be connected to Wifi for this feature to work</p>"
174+
? "<p>Your board must be connected to Wifi for this feature to work</p>"
171175
: `
172176
<input type="text" id="packageInput" placeholder="mip package" style=""/>
173177
<button id="installButton"><strong>Install</strong></button>`

src/api.mts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { homedir } from "os";
22
import { join } from "path";
3+
import { join as joinPosix } from "path/posix";
34
import { TextDecoder } from "util";
45
import {
56
commands,
@@ -75,6 +76,34 @@ export function getVsCodeUserPath(): string {
7576
return join(folder, "Code", "User");
7677
}
7778

79+
export function getStubsBasePath(): string {
80+
return join(homedir(), ".micropico-stubs");
81+
}
82+
83+
export function getStubsBasePathPosix(): string {
84+
return joinPosix(homedir(), ".micropico-stubs");
85+
}
86+
87+
export function getIncludedStubsPath(): string {
88+
return join(getStubsBasePath(), "included");
89+
}
90+
91+
export function settingsStubsBasePath(): string {
92+
return joinPosix("~", ".micropico-stubs");
93+
}
94+
95+
export function getStubsPathForVersion(version: string): string {
96+
return join(getStubsBasePath(), version);
97+
}
98+
99+
export function getStubsPathForVersionPosix(version: string): string {
100+
return joinPosix(getStubsBasePathPosix(), version);
101+
}
102+
103+
export function settingsStubsPathForVersion(version: string): string {
104+
return join(settingsStubsBasePath(), version);
105+
}
106+
78107
/**
79108
* Returns the path to the currently opened project (aka first workspace folder)
80109
*

src/settings.mts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Memento, Uri, WorkspaceConfiguration } from "vscode";
22
import { window, workspace as vsWorkspace } from "vscode";
33
import { PyboardRunner } from "@paulober/pyboard-serial-com";
4-
import { extName, getProjectPath } from "./api.mjs";
4+
import { extName, getProjectPath, settingsStubsBasePath } from "./api.mjs";
55
import { join, relative } from "path";
66

77
export enum SettingsKey {
@@ -24,10 +24,12 @@ export type Setting = string | boolean | string[] | null | undefined;
2424

2525
export default class Settings {
2626
private config: WorkspaceConfiguration;
27+
private pythonConfig: WorkspaceConfiguration;
2728
public context: Memento;
2829

2930
constructor(context: Memento) {
3031
this.config = vsWorkspace.getConfiguration(extName);
32+
this.pythonConfig = vsWorkspace.getConfiguration("python.analysis");
3133

3234
this.context = context;
3335
}
@@ -36,7 +38,11 @@ export default class Settings {
3638
this.config = vsWorkspace.getConfiguration(extName);
3739
}
3840

39-
public get(key: SettingsKey): Setting {
41+
public reloadPython(): void {
42+
this.pythonConfig = vsWorkspace.getConfiguration("python.analysis");
43+
}
44+
45+
public get(key: SettingsKey | string): Setting {
4046
return this.config.get(key);
4147
}
4248

@@ -58,10 +64,20 @@ export default class Settings {
5864
return Array.isArray(value) ? value : undefined;
5965
}
6066

61-
public update<T>(key: SettingsKey, value: T): Thenable<void> {
67+
public getArrayPython(key: string): string[] | undefined {
68+
const value = this.pythonConfig.get(key);
69+
70+
return Array.isArray(value) ? value : undefined;
71+
}
72+
73+
public update<T>(key: SettingsKey | string, value: T): Thenable<void> {
6274
return this.config.update(key, value, true);
6375
}
6476

77+
public updatePython<T>(key: string, value: T): Thenable<void> {
78+
return this.pythonConfig.update(key, value, null);
79+
}
80+
6581
// helpers
6682
/**
6783
* Get the COM port to connect to.
@@ -200,6 +216,40 @@ export default class Settings {
200216
public getIngoredSyncItems(): string[] {
201217
return this.getArray(SettingsKey.pyIgnore) || [];
202218
}
219+
220+
public async updateStubsPath(newStubs: string): Promise<boolean> {
221+
// catch if stubs where updated before after starting the extension
222+
this.reloadPython();
223+
224+
const typeshedPaths = this.getArrayPython("typeshedPaths");
225+
const extraPaths = this.getArrayPython("extraPaths");
226+
227+
if (typeshedPaths === undefined || extraPaths === undefined) {
228+
return false;
229+
}
230+
231+
// Remove paths starting with '~/.micropico-stubs'
232+
const filteredTypeshedPaths = typeshedPaths.filter(
233+
path =>
234+
!path.startsWith(settingsStubsBasePath()) &&
235+
!path.includes("Pico-W-Stub")
236+
);
237+
const filteredExtraPaths = extraPaths.filter(
238+
path =>
239+
!path.startsWith(settingsStubsBasePath()) &&
240+
!path.includes("Pico-W-Stub")
241+
);
242+
243+
// Add newStubs to both arrays
244+
filteredTypeshedPaths.push(newStubs);
245+
filteredExtraPaths.push(newStubs);
246+
247+
// Update the settings with the modified arrays
248+
await this.updatePython("typeshedPaths", filteredTypeshedPaths);
249+
await this.updatePython("extraPaths", filteredExtraPaths);
250+
251+
return true;
252+
}
203253
}
204254

205255
/**

0 commit comments

Comments
 (0)