diff --git a/CHANGELOG.md b/CHANGELOG.md index 811fa4d..e2c6b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,21 +1,33 @@ # Release Notes -## 2.3.0 (2021-??-??) +## 2.3.1 (2021-03-23) + +- Added a new setting ``platformio-ide.autoOpenPlatformIOIniFile`` to control an automatic opening of the `platformio.ini` file from a project when no other editors are opened (issue [#2419](https://github.com/platformio/platformio-vscode-ide/issues/2419)) +- Added a new setting ``platformio-ide.activateProjectOnTextEditorChange`` to enable automatic project activation depending on an active opened text editor (issue [#2410](https://github.com/platformio/platformio-vscode-ide/issues/2410)) +- Automatically activate project environment opened via "PIO Home > New Project / Open Project" (issue [#2414](https://github.com/platformio/platformio-vscode-ide/issues/2414)) +- Do not show "Default" environment when a project does not have any build environments (issue [#2450](https://github.com/platformio/platformio-vscode-ide/issues/2450)) +- Fixed an issue "Failed to load symbols from executable file" when debugging native/desktop application +- PlatformIO IDE Installer + * Updated PlatformIO Core installer to v1.0.1 + * Rebuild project index only when the environment changes + * Fixed an issue "The 'path' argument must be of type string. Received undefined" + +## 2.3.0 (2021-03-03) **Requires PlatformIO Core 5.1 or above** -* Project management: - - Show active project in the status bar (issue [#2276](https://github.com/platformio/platformio-vscode-ide/issues/2276)) - - Automatically switch to the latest project on restart (issue [#2365](https://github.com/platformio/platformio-vscode-ide/issues/2365)) - - Automatically restore the latest project environment (issue [#2344](https://github.com/platformio/platformio-vscode-ide/issues/2344)) -* Allowed passing custom base URL of the Python Package Index using new `customPyPiIndexUrl` setting -* Open ["platformio.ini" configuration file](https://docs.platformio.org/page/projectconf/index.html) from newly added project (if there are no other active editors) (issue [#2263](https://github.com/platformio/platformio-vscode-ide/issues/2263)) -* Updated PlatformIO Core installer to v1.0.0 ([release notes](https://github.com/platformio/platformio-core-installer/releases/tag/v1.0.0)) -* Added protection for infinite IntelliSense index rebuilding (issue [#2363](https://github.com/platformio/platformio-vscode-ide/issues/2363)) -* Added "OpenAPI (Swagger) Editor" extension to the conflicted list (issue [#2324](https://github.com/platformio/platformio-vscode-ide/issues/2324)) -* Fixed issues when the "Upload and Monitor" command didn't terminate the running task and didn't reopen a monitor with delay (issue [#2266](https://github.com/platformio/platformio-vscode-ide/issues/2266), issue [#2319](https://github.com/platformio/platformio-vscode-ide/issues/2319)) -* Fixed an issue with broken IntelliSense index rebuilding or tasks loading for big projects (issue [#2321](https://github.com/platformio/platformio-vscode-ide/issues/2321)) -* Fixed an issue when a debug breakpoint was not allowed for Assembly files +- Project management: + * Show active project in the status bar (issue [#2276](https://github.com/platformio/platformio-vscode-ide/issues/2276)) + * Automatically switch to the latest project on restart (issue [#2365](https://github.com/platformio/platformio-vscode-ide/issues/2365)) + * Automatically restore the latest project environment (issue [#2344](https://github.com/platformio/platformio-vscode-ide/issues/2344)) +- Allowed passing custom base URL of the Python Package Index using new `customPyPiIndexUrl` setting +- Open ["platformio.ini" configuration file](https://docs.platformio.org/page/projectconf/index.html) from newly added project (if there are no other active editors) (issue [#2263](https://github.com/platformio/platformio-vscode-ide/issues/2263)) +- Updated PlatformIO Core installer to v1.0.0 ([release notes](https://github.com/platformio/platformio-core-installer/releases/tag/v1.0.0)) +- Added protection for infinite IntelliSense index rebuilding (issue [#2363](https://github.com/platformio/platformio-vscode-ide/issues/2363)) +- Added "OpenAPI (Swagger) Editor" extension to the conflicted list (issue [#2324](https://github.com/platformio/platformio-vscode-ide/issues/2324)) +- Fixed issues when the "Upload and Monitor" command didn't terminate the running task and didn't reopen a monitor with delay (issue [#2266](https://github.com/platformio/platformio-vscode-ide/issues/2266), issue [#2319](https://github.com/platformio/platformio-vscode-ide/issues/2319)) +- Fixed an issue with broken IntelliSense index rebuilding or tasks loading for big projects (issue [#2321](https://github.com/platformio/platformio-vscode-ide/issues/2321)) +- Fixed an issue when a debug breakpoint was not allowed for Assembly files ## 2.2.1 (2020-11-12) @@ -50,36 +62,36 @@ ## 2.1.0 (2020-09-16) -* Added a new setting ``platformio-ide.autoPreloadEnvTasks`` to enable automatic preloading of the project environment tasks (issue [#2004](https://github.com/platformio/platformio-vscode-ide/issues/2004)) -* Renamed "PIO Remote" group of tasks to "Remote Development" -* Updated PlatformIO Core installer to [v0.3.5](https://github.com/platformio/platformio-core-installer/releases/tag/v0.3.5) +- Added a new setting ``platformio-ide.autoPreloadEnvTasks`` to enable automatic preloading of the project environment tasks (issue [#2004](https://github.com/platformio/platformio-vscode-ide/issues/2004)) +- Renamed "PIO Remote" group of tasks to "Remote Development" +- Updated PlatformIO Core installer to [v0.3.5](https://github.com/platformio/platformio-core-installer/releases/tag/v0.3.5) ## 2.0.1 (2020-09-10) -* Moved "Project Tasks" view back to "PlatformIO" activity (you can now drag it to any location) +- Moved "Project Tasks" view back to "PlatformIO" activity (you can now drag it to any location) ## 2.0.0 (2020-09-10) **Requires PlatformIO Core 5.0 or above** **Requires VSCode 1.44 or above** -* New PlatformIO Task Explorer - - Instant access to the Project Tasks within the VSCode Explorer - - Grouped tasks: Generic, Advanced, PIO Remote, Platform, Custom, etc. - - Support for PlatformIO dev-platform tasks (Program FPGA bitstream, Burn bootloader, Upload to FS, OTA Update, etc). The list of tasks depends on a particular dev-platform - - Access to [User Custom Targets](https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#custom-targets) -* New Project Environment Switcher - - Switch between project environments declared in [platformio.ini](https://docs.platformio.org/en/latest/projectconf/index.html) project configuration file (issue [#544](https://github.com/platformio/platformio-vscode-ide/issues/544)) - - Activate IntelliSense service based on the current environment - - Automatically generate a debugging configuration for the active environment -* New PlatformIO IDE Installer - - Added progress information - - Switched to the cross-platform and portable [get-platformio.py](https://github.com/platformio/platformio-core-installer) installer script - - Use built-in portable Python 3 on Windows and macOS (it can be disabled with ``platformio-ide.useBuiltinPython`` setting) -* Added support for ``extends`` option in ``platformio.ini`` project configuration file (issue [#1371](https://github.com/platformio/platformio-vscode-ide/issues/1371)) -* Contribute PlatformIO Core CLI into VSCode's default Terminal -* Reduced startup time (PlatformIO Core verification process) -* Fixed a bug when hotkeys in PlatformIO Home did not work on macOS (issue [#606](https://github.com/platformio/platformio-vscode-ide/issues/606)) +- New PlatformIO Task Explorer + * Instant access to the Project Tasks within the VSCode Explorer + * Grouped tasks: Generic, Advanced, PIO Remote, Platform, Custom, etc. + * Support for PlatformIO dev-platform tasks (Program FPGA bitstream, Burn bootloader, Upload to FS, OTA Update, etc). The list of tasks depends on a particular dev-platform + * Access to [User Custom Targets](https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#custom-targets) +- New Project Environment Switcher + * Switch between project environments declared in [platformio.ini](https://docs.platformio.org/en/latest/projectconf/index.html) project configuration file (issue [#544](https://github.com/platformio/platformio-vscode-ide/issues/544)) + * Activate IntelliSense service based on the current environment + * Automatically generate a debugging configuration for the active environment +- New PlatformIO IDE Installer + * Added progress information + * Switched to the cross-platform and portable [get-platformio.py](https://github.com/platformio/platformio-core-installer) installer script + * Use built-in portable Python 3 on Windows and macOS (it can be disabled with ``platformio-ide.useBuiltinPython`` setting) +- Added support for ``extends`` option in ``platformio.ini`` project configuration file (issue [#1371](https://github.com/platformio/platformio-vscode-ide/issues/1371)) +- Contribute PlatformIO Core CLI into VSCode's default Terminal +- Reduced startup time (PlatformIO Core verification process) +- Fixed a bug when hotkeys in PlatformIO Home did not work on macOS (issue [#606](https://github.com/platformio/platformio-vscode-ide/issues/606)) ## 1.10.0 (2019-11-20) diff --git a/package.json b/package.json index 806c8bf..fde984f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "platformio-ide", - "version": "2.3.0", + "version": "2.3.1", "publisher": "platformio", "engines": { "vscode": "^1.44.0" @@ -517,6 +517,16 @@ "default": false, "description": "Activate the PlatformIO extension only when a PlatformIO-based project (with `platformio.ini`) is opened in the workspace" }, + "platformio-ide.activateProjectOnTextEditorChange": { + "type": "boolean", + "default": false, + "description": "Automatically activate project depending on an active opened text editor" + }, + "platformio-ide.autoOpenPlatformIOIniFile": { + "type": "boolean", + "default": true, + "description": "Automatically open the `platformio.ini` file from a project when no other editors are opened" + }, "platformio-ide.autoCloseSerialMonitor": { "type": "boolean", "default": true, @@ -606,25 +616,25 @@ "vscode:package": "webpack --mode production && vsce package" }, "devDependencies": { - "@babel/core": "~7.13.8", + "@babel/core": "~7.13.10", "@types/node": "~12", "@types/vscode": "~1.44.0", "babel-eslint": "~10.1.0", "babel-loader": "~8.2.2", "babel-plugin-transform-class-properties": "~6.24.1", "babel-preset-env": "~1.7.0", - "eslint": "~7.21.0", + "eslint": "~7.22.0", "eslint-import-resolver-webpack": "~0.13.0", "eslint-plugin-import": "~2.22.1", "prettier": "~2.2.1", - "vsce": "~1.85.1", - "webpack": "~5.24.2", + "vsce": "~1.87.0", + "webpack": "~5.27.2", "webpack-cli": "~4.5.0" }, "dependencies": { "fs-plus": "~3.1.1", - "platformio-node-helpers": "~9.1.1", - "platformio-vscode-debug": "~1.3.0" + "platformio-node-helpers": "~9.1.2", + "platformio-vscode-debug": "~1.3.1" }, "extensionDependencies": [ "ms-vscode.cpptools" diff --git a/src/home.js b/src/home.js index fbd4dda..02f68ce 100644 --- a/src/home.js +++ b/src/home.js @@ -97,6 +97,13 @@ export default class PIOHome { port: extension.getSetting('pioHomeServerHttpPort'), onIDECommand: async (command, params) => { if (command === 'open_project') { + if (extension.projectObservable) { + extension.projectObservable.saveProjectStateItem( + vscode.Uri.file(params).fsPath, + 'activeEnv', + undefined + ); + } this.disposePanel(); if (vscode.workspace.workspaceFolders) { vscode.workspace.updateWorkspaceFolders( diff --git a/src/installer/python-prompt.js b/src/installer/python-prompt.js index 3e0a496..800ba91 100644 --- a/src/installer/python-prompt.js +++ b/src/installer/python-prompt.js @@ -16,13 +16,15 @@ export default class PythonPrompt { async prompt() { const selectedItem = await vscode.window.showInformationMessage( - 'PlatformIO: Can not find working Python 2.7 or 3.5+ Interpreter. Please install the latest Python 3 and restart VSCode', + 'PlatformIO: Can not find working Python 3.6+ Interpreter. Please install the latest Python 3 and restart VSCode', { title: 'Install Python', isCloseAffordance: false }, { title: 'I have Python', isCloseAffordance: false }, { title: 'Try again', isCloseAffordance: false }, { title: 'Abort PlatformIO IDE Installation', isCloseAffordance: true } ); + let result = { status: this.STATUS_TRY_AGAIN }; + let pythonExecutable = undefined; switch (selectedItem ? selectedItem.title : undefined) { case 'Install Python': vscode.commands.executeCommand( @@ -31,21 +33,26 @@ export default class PythonPrompt { 'http://docs.platformio.org/page/faq.html#install-python-interpreter' ) ); - return { status: this.STATUS_TRY_AGAIN }; + break; case 'I have Python': - return { - status: this.STATUS_CUSTOMEXE, - pythonExecutable: await vscode.window.showInputBox({ - prompt: 'Please specify a full path to Python executable file', - placeHolder: 'Full path to python/python.exe', - validateInput: (value) => - !fs.isFileSync(value) ? 'Invalid path to Python Interpreter' : null, - }), - }; + pythonExecutable = await vscode.window.showInputBox({ + prompt: 'Please specify a full path to Python executable file', + placeHolder: 'Full path to python/python.exe', + validateInput: (value) => + !fs.isFileSync(value) ? 'Invalid path to Python Interpreter' : null, + }); + if (pythonExecutable) { + result = { + status: this.STATUS_CUSTOMEXE, + pythonExecutable, + }; + } + break; case 'Abort PlatformIO IDE Installation': - return { status: this.STATUS_ABORT }; - default: - return { status: this.STATUS_TRY_AGAIN }; + result = { status: this.STATUS_ABORT }; + break; } + + return result; } } diff --git a/src/main.js b/src/main.js index 9fcfe1b..851e72c 100644 --- a/src/main.js +++ b/src/main.js @@ -26,6 +26,7 @@ class PlatformIOVSCodeExtension { this.context = undefined; this.pioTerm = undefined; this.pioHome = undefined; + this.projectObservable = undefined; this.subscriptions = []; this._enterpriseSettings = undefined; @@ -84,7 +85,8 @@ class PlatformIOVSCodeExtension { this.initToolbar({ ignoreCommands: this.getEnterpriseSetting('ignoreToolbarCommands'), }); - this.subscriptions.push(new ProjectObservable()); + this.projectObservable = new ProjectObservable(); + this.subscriptions.push(this.projectObservable); this.startPIOHome(); diff --git a/src/project/observable.js b/src/project/observable.js index 9f83791..927f5d8 100644 --- a/src/project/observable.js +++ b/src/project/observable.js @@ -66,7 +66,15 @@ export default class ProjectObservable { this.subscriptions = [ this._pool, - // vscode.window.onDidChangeActiveTextEditor(() => this.switchToProject()), + vscode.window.onDidChangeActiveTextEditor(() => { + if (!extension.getSetting('activateProjectOnTextEditorChange')) { + return; + } + const projectDir = this.getActiveEditorProjectDir(); + if (projectDir) { + this.switchToProject(projectDir); + } + }), vscode.workspace.onDidChangeWorkspaceFolders(() => this.switchToProject(this.findActiveProjectDir()) ), @@ -105,6 +113,14 @@ export default class ProjectObservable { } findActiveProjectDir() { + let projectDir = undefined; + if (extension.getSetting('activateProjectOnTextEditorChange')) { + projectDir = this.getActiveEditorProjectDir(); + } + return projectDir || this.getSelectedProjectDir(); + } + + getSelectedProjectDir() { const pioProjectDirs = ProjectObservable.getPIOProjectDirs(); const currentActiveDir = this._pool.getActiveProjectDir(); if (pioProjectDirs.length < 1) { @@ -126,6 +142,27 @@ export default class ProjectObservable { return pioProjectDirs[0]; } + getActiveEditorProjectDir() { + const pioProjectDirs = ProjectObservable.getPIOProjectDirs(); + if (pioProjectDirs.length < 1) { + return undefined; + } + const editor = vscode.window.activeTextEditor; + if (!editor) { + return undefined; + } + const resource = editor.document.uri; + if (resource.scheme !== 'file') { + return undefined; + } + const folder = vscode.workspace.getWorkspaceFolder(resource); + if (!folder || !ProjectObservable.isPIOProjectSync(folder.uri.fsPath)) { + // outside workspace + return undefined; + } + return folder.uri.fsPath; + } + loadProjectStateItem(projectDir, name) { const data = (this._persistentState.getValue('projects') || {})[projectDir] || {}; return data[name]; @@ -169,27 +206,45 @@ export default class ProjectObservable { } this._sbEnvSwitcher.text = '$(root-folder) Loading...'; + let currentProjectDir = undefined; + let currentEnvName = undefined; + if (this._pool.getActiveObserver()) { + currentProjectDir = this._pool.getActiveObserver().projectDir; + currentEnvName = this._pool.getActiveObserver().getActiveEnvName(); + } + const observer = this._pool.getObserver(projectDir); - let envName = undefined; if ('envName' in options) { - envName = options.envName; + await observer.switchProjectEnv(options.envName); } else if (!observer.getActiveEnvName()) { - envName = this.loadProjectStateItem(projectDir, 'activeEnv'); + await observer.switchProjectEnv( + this.loadProjectStateItem(projectDir, 'activeEnv') + ); } - await observer.switchProjectEnv(envName); - this._pool.switch(projectDir); - if (this._taskManager) { - this._taskManager.dispose(); - this._taskManager = undefined; - } - this._taskManager = new ProjectTaskManager(projectDir, observer); + // ignore active project and & env + if ( + !currentProjectDir || + currentProjectDir !== projectDir || + currentEnvName !== observer.getActiveEnvName() + ) { + this._pool.switch(projectDir); - // open "platformio.ini" if no visible editors - if (vscode.window.visibleTextEditors.length === 0) { - vscode.window.showTextDocument( - vscode.Uri.file(path.join(projectDir, 'platformio.ini')) - ); + if (this._taskManager) { + this._taskManager.dispose(); + this._taskManager = undefined; + } + this._taskManager = new ProjectTaskManager(projectDir, observer); + + // open "platformio.ini" if no visible editors + if ( + vscode.window.visibleTextEditors.length === 0 && + extension.getSetting('autoOpenPlatformIOIniFile') + ) { + vscode.window.showTextDocument( + vscode.Uri.file(path.join(projectDir, 'platformio.ini')) + ); + } } this.updateEnvSwitcher(); @@ -230,21 +285,25 @@ export default class ProjectObservable { async pickProjectEnv() { const items = []; for (const projectDir of ProjectObservable.getPIOProjectDirs()) { - const shortPrpjectDir = `${path.basename( + const observer = this._pool.getObserver(projectDir); + const envs = await observer.getProjectEnvs(); + if (!envs || !envs.length) { + continue; + } + const shortProjectDir = `${path.basename( path.dirname(projectDir) )}/${path.basename(projectDir)}`; items.push({ projectDir, label: 'Default', - description: `$(folder) ${shortPrpjectDir} ("default_envs" from "platformio.ini")`, + description: `$(folder) ${shortProjectDir} ("default_envs" from "platformio.ini")`, }); - const observer = this._pool.getObserver(projectDir); items.push( - ...(await observer.getProjectEnvs()).map((item) => ({ + ...envs.map((item) => ({ projectDir, envName: item.name, label: `env:${item.name}`, - description: `$(folder) ${shortPrpjectDir}`, + description: `$(folder) ${shortProjectDir}`, })) ); }