diff --git a/package.json b/package.json index e1605c2..8854d43 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "ms-vscode.cpptools-extension-pack", "ms-vscode.vscode-serial-monitor", "marus25.cortex-debug", - "paulober.pico-w-go" + "paulober.pico-w-go", + "ms-python.python" ], "main": "./dist/extension.cjs", "markdown": "github", @@ -64,7 +65,8 @@ }, "activationEvents": [ "workspaceContains:./pico_sdk_import.cmake", - "onWebviewPanel:newPicoProject" + "onWebviewPanel:newPicoProject", + "onWebviewPanel:newPicoMicroPythonProject" ], "contributes": { "commands": [ @@ -273,6 +275,7 @@ "typescript-eslint": "^8.1.0" }, "dependencies": { + "@vscode/python-extension": "^1.0.5", "adm-zip": "^0.5.14 <0.5.15", "ini": "^4.1.3", "rimraf": "^5.0.7", diff --git a/src/utils/githubREST.mts b/src/utils/githubREST.mts index 74cd1f7..51c95d0 100644 --- a/src/utils/githubREST.mts +++ b/src/utils/githubREST.mts @@ -60,15 +60,13 @@ export const PYENV_REPOSITORY_URL = "https://github.com/pyenv/pyenv.git"; export function ownerOfRepository(repository: GithubRepository): string { switch (repository) { case GithubRepository.picoSDK: + case GithubRepository.tools: + case GithubRepository.picotool: return "raspberrypi"; case GithubRepository.cmake: return "Kitware"; case GithubRepository.ninja: return "ninja-build"; - case GithubRepository.tools: - return "raspberrypi"; - case GithubRepository.picotool: - return "raspberrypi"; } } diff --git a/src/webview/newMicroPythonProjectPanel.mts b/src/webview/newMicroPythonProjectPanel.mts index 2bc6c1e..4a582f9 100644 --- a/src/webview/newMicroPythonProjectPanel.mts +++ b/src/webview/newMicroPythonProjectPanel.mts @@ -22,6 +22,7 @@ import { import which from "which"; import { existsSync } from "fs"; import { join } from "path"; +import { PythonExtension } from "@vscode/python-extension"; interface SubmitMessageValue { projectName: string; @@ -37,10 +38,11 @@ export class NewMicroPythonProjectPanel { private readonly _panel: WebviewPanel; private readonly _extensionUri: Uri; private readonly _settings: Settings; - private readonly _logger: Logger = new Logger("NewProjectPanel"); + private readonly _logger: Logger = new Logger("NewMicroPythonProjectPanel"); private _disposables: Disposable[] = []; private _projectRoot?: Uri; + private _pythonExtensionApi?: PythonExtension; public static createOrShow(extensionUri: Uri, projectUri?: Uri): void { const column = window.activeTextEditor @@ -347,6 +349,9 @@ print("Finished.")\r\n`; "web", "raspberry-128.png" ); + if (!this._pythonExtensionApi) { + this._pythonExtensionApi = await PythonExtension.api(); + } const html = await this._getHtmlForWebview(this._panel.webview); if (html !== "") { @@ -407,8 +412,13 @@ print("Finished.")\r\n`; Uri.joinPath(this._extensionUri, "web", "raspberrypi-nav-header-dark.svg") ); - // TODO: maybe use python extension api - // TODO: check python version, workaround, ownly allow python3 commands on unix + // TODO: add support for onDidChangeActiveEnvironment and filter envs that don't directly point + // to an executable + const environments = this._pythonExtensionApi?.environments; + const knownEnvironments = environments?.known; + const activeEnv = environments?.getActiveEnvironmentPath(); + + // TODO: check python version, workaround, only allow python3 commands on unix const isPythonSystemAvailable = (await which("python3", { nothrow: true })) !== null || (await which("python", { nothrow: true })) !== null; @@ -484,29 +494,54 @@ print("Finished.")\r\n`;