Skip to content

Commit

Permalink
Merge pull request #217 from paulober/develop
Browse files Browse the repository at this point in the history
Patch v3.7.6
  • Loading branch information
paulober authored Apr 30, 2024
2 parents 8ac4292 + 30bb4cd commit bf1e02f
Show file tree
Hide file tree
Showing 8 changed files with 513 additions and 353 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ All notable changes to the "MicroPico" extension will be documented in this file

---

## [3.7.6] - 2024-04-30

### Changed
- Updated dependencies
- Fixed #215 and #209, Failed to switch stubs on Linux and macOS / use stubs on external drive

## [3.7.5] - 2024-02-22

### Changed
Expand Down
606 changes: 336 additions & 270 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pico-w-go",
"displayName": "MicroPico",
"description": "Auto-completion, remote workspace and a REPL console integration for the Raspberry Pi Pico (W) with MicroPython firmware.",
"version": "3.7.5",
"version": "3.7.6",
"publisher": "paulober",
"license": "MPL-2.0",
"homepage": "https://github.com/paulober/MicroPico/blob/main/README.md",
Expand Down Expand Up @@ -589,26 +589,26 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.14.202",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
"@types/node": "^18.x",
"@types/node": "^18.17.x",
"@types/uuid": "^9.0.8",
"@types/vscode": "^1.86.0",
"@types/which": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@vscode/test-electron": "^2.3.9",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"glob": "^9.3.4",
"mocha": "^10.3.0",
"rollup": "^4.12.0",
"rollup": "^4.17.1",
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.3.3"
"typescript": "^5.4.5"
},
"dependencies": {
"@paulober/pyboard-serial-com": "^3.0.7",
"axios": "^1.6.7",
"axios": "^1.6.8",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"rimraf": "^5.0.5",
Expand Down
17 changes: 13 additions & 4 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class Activator {
);

this.stubs = new Stubs();
await this.stubs.update();
await this.stubs.update(settings);

this.comDevice = await settings.getComDevice();

Expand Down Expand Up @@ -354,6 +354,14 @@ export default class Activator {
frozen = true;
}
if (data.includes("!!ERR!!")) {
this.logger.error(
"Exception occured (maybe a connection loss). " +
`Message dump: ${data}`
);
console.log(
"Exception occured (maybe a connection loss). " +
`Message dump: ${data}`
);
// write red text into terminal
terminal?.write(
"\x1b[31mException occured (maybe a connection loss)\x1b[0m\r\n"
Expand Down Expand Up @@ -1113,7 +1121,7 @@ export default class Activator {
}

if (version.toLowerCase() === "included") {
await installIncludedStubs();
await installIncludedStubs(settings);

void vscode.window.showInformationMessage("Included stubs selected.");
} else {
Expand All @@ -1131,7 +1139,8 @@ export default class Activator {
// TODO: implement cancellation
const result = await installStubsByVersion(
versionParts[1],
displayStringToStubPort(versionParts[0])
displayStringToStubPort(versionParts[0]),
settings
);

if (result) {
Expand Down Expand Up @@ -1266,7 +1275,7 @@ export default class Activator {
//this.ui?.refreshState(true);
this.logger.info("Connection to wrapper successfully established");
void vscode.window.showInformationMessage(
"Connection to Pico established."
"Connection to board established."
);

return;
Expand Down
6 changes: 5 additions & 1 deletion src/activitybar/packagesWebview.mts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export default class PackagesWebviewProvider implements WebviewViewProvider {
);

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

// Restrict the webview to only load specific scripts
const nonce = getNonce();
Expand All @@ -167,7 +171,7 @@ export default class PackagesWebviewProvider implements WebviewViewProvider {
<div style="width: 100%;" class="input-div">
${
this._isDisabled
? "<p>Your Pico must be connected to Wifi for this feature to work</p>"
? "<p>Your board must be connected to Wifi for this feature to work</p>"
: `
<input type="text" id="packageInput" placeholder="mip package" style=""/>
<button id="installButton"><strong>Install</strong></button>`
Expand Down
29 changes: 29 additions & 0 deletions src/api.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { homedir } from "os";
import { join } from "path";
import { join as joinPosix } from "path/posix";
import { TextDecoder } from "util";
import {
commands,
Expand Down Expand Up @@ -75,6 +76,34 @@ export function getVsCodeUserPath(): string {
return join(folder, "Code", "User");
}

export function getStubsBasePath(): string {
return join(homedir(), ".micropico-stubs");
}

export function getStubsBasePathPosix(): string {
return joinPosix(homedir(), ".micropico-stubs");
}

export function getIncludedStubsPath(): string {
return join(getStubsBasePath(), "included");
}

export function settingsStubsBasePath(): string {
return joinPosix("~", ".micropico-stubs");
}

export function getStubsPathForVersion(version: string): string {
return join(getStubsBasePath(), version);
}

export function getStubsPathForVersionPosix(version: string): string {
return joinPosix(getStubsBasePathPosix(), version);
}

export function settingsStubsPathForVersion(version: string): string {
return join(settingsStubsBasePath(), version);
}

/**
* Returns the path to the currently opened project (aka first workspace folder)
*
Expand Down
56 changes: 53 additions & 3 deletions src/settings.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Memento, Uri, WorkspaceConfiguration } from "vscode";
import { window, workspace as vsWorkspace } from "vscode";
import { PyboardRunner } from "@paulober/pyboard-serial-com";
import { extName, getProjectPath } from "./api.mjs";
import { extName, getProjectPath, settingsStubsBasePath } from "./api.mjs";
import { join, relative } from "path";

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

export default class Settings {
private config: WorkspaceConfiguration;
private pythonConfig: WorkspaceConfiguration;
public context: Memento;

constructor(context: Memento) {
this.config = vsWorkspace.getConfiguration(extName);
this.pythonConfig = vsWorkspace.getConfiguration("python.analysis");

this.context = context;
}
Expand All @@ -36,7 +38,11 @@ export default class Settings {
this.config = vsWorkspace.getConfiguration(extName);
}

public get(key: SettingsKey): Setting {
public reloadPython(): void {
this.pythonConfig = vsWorkspace.getConfiguration("python.analysis");
}

public get(key: SettingsKey | string): Setting {
return this.config.get(key);
}

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

public update<T>(key: SettingsKey, value: T): Thenable<void> {
public getArrayPython(key: string): string[] | undefined {
const value = this.pythonConfig.get(key);

return Array.isArray(value) ? value : undefined;
}

public update<T>(key: SettingsKey | string, value: T): Thenable<void> {
return this.config.update(key, value, true);
}

public updatePython<T>(key: string, value: T): Thenable<void> {
return this.pythonConfig.update(key, value, null);
}

// helpers
/**
* Get the COM port to connect to.
Expand Down Expand Up @@ -200,6 +216,40 @@ export default class Settings {
public getIngoredSyncItems(): string[] {
return this.getArray(SettingsKey.pyIgnore) || [];
}

public async updateStubsPath(newStubs: string): Promise<boolean> {
// catch if stubs where updated before after starting the extension
this.reloadPython();

const typeshedPaths = this.getArrayPython("typeshedPaths");
const extraPaths = this.getArrayPython("extraPaths");

if (typeshedPaths === undefined || extraPaths === undefined) {
return false;
}

// Remove paths starting with '~/.micropico-stubs'
const filteredTypeshedPaths = typeshedPaths.filter(
path =>
!path.startsWith(settingsStubsBasePath()) &&
!path.includes("Pico-W-Stub")
);
const filteredExtraPaths = extraPaths.filter(
path =>
!path.startsWith(settingsStubsBasePath()) &&
!path.includes("Pico-W-Stub")
);

// Add newStubs to both arrays
filteredTypeshedPaths.push(newStubs);
filteredExtraPaths.push(newStubs);

// Update the settings with the modified arrays
await this.updatePython("typeshedPaths", filteredTypeshedPaths);
await this.updatePython("extraPaths", filteredExtraPaths);

return true;
}
}

/**
Expand Down
Loading

0 comments on commit bf1e02f

Please sign in to comment.