Skip to content

Commit 27e1411

Browse files
committed
Add support for the ${command:platformio-ide.activeEnvironment} variable // Issue platformio#1697
1 parent 534081c commit 27e1411

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 3.0.1 (2023-??-??)
44

5-
* Added new ``platformio-ide.uploadAndMonitor`` command to "Upload and Monitor" active environment (useful for custom PlatformIO Toolbar) (issue [#1697](https://github.com/platformio/platformio-vscode-ide/issues/1697))
5+
* Add support for the ``${command:platformio-ide.activeEnvironment}`` variable that can be used in a custom [PlatformIO Toolbar](https://docs.platformio.org/en/latest/integration/ide/vscode.html#platformio-toolbar) and [VSCode variable substitution](https://code.visualstudio.com/docs/editor/variables-reference) (issue [#1697](https://github.com/platformio/platformio-vscode-ide/issues/1697))
66
* Focus on the project configuration output tab only on error (issue [#3535](https://github.com/platformio/platformio-vscode-ide/issues/3535))
77
* Fixed an issue with a task runner on Windows 7 (issue [#3481](https://github.com/platformio/platformio-vscode-ide/issues/3481))
88
* Fixed "Select All", "Undo", and "Redo" operations on macOS for PIO Home (pull [#3451](https://github.com/platformio/platformio-vscode-ide/pull/3451))

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@
154154
"icon": "$(arrow-right)",
155155
"enablement": "pioProjectReady"
156156
},
157-
{
158-
"command": "platformio-ide.uploadAndMonitor",
159-
"title": "Upload and Monitor active environment",
160-
"category": "PlatformIO",
161-
"icon": "$(arrow-right)",
162-
"enablement": "pioProjectReady"
163-
},
164157
{
165158
"command": "platformio-ide.clean",
166159
"title": "Clean active environment",

src/project/manager.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export default class ProjectManager {
102102
vscode.commands.registerCommand('platformio-ide._runProjectTask', (task) =>
103103
this._taskManager.runTask(task)
104104
),
105+
vscode.commands.registerCommand('platformio-ide.activeEnvironment', () =>
106+
this._pool.getActiveObserver().getActiveEnvName()
107+
),
105108
];
106109
this.internalSubscriptions = [];
107110

src/project/tasks.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ export default class ProjectTaskManager {
235235
vscode.commands.registerCommand('platformio-ide.upload', () =>
236236
_runTask('Upload')
237237
),
238-
vscode.commands.registerCommand('platformio-ide.uploadAndMonitor', () =>
239-
_runTask('Upload and Monitor')
240-
),
241238
vscode.commands.registerCommand('platformio-ide.test', () => _runTask('Test')),
242239
vscode.commands.registerCommand('platformio-ide.clean', () => _runTask('Clean')),
243240
vscode.commands.registerCommand('platformio-ide.serialMonitor', () =>

src/toolbar.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,37 @@ export default class PIOToolbar {
111111
),
112112
vscode.commands.registerCommand(
113113
PIOToolbar.RUN_BUTTON_COMMANDS_ID,
114-
async (button) => {
115-
for (const cmd of button.commands) {
116-
const args = cmd.args || [];
117-
await vscode.commands.executeCommand(
118-
cmd.id,
119-
...(Array.isArray(args) ? args : [args])
120-
);
121-
}
122-
}
114+
this.onButtonClick.bind(this)
123115
)
124116
);
125117
}
118+
119+
async onButtonClick(button) {
120+
for (const cmd of button.commands) {
121+
let args = cmd.args || [];
122+
if (!Array.isArray(args)) {
123+
args = [args];
124+
}
125+
for (let i = 0; i < args.length; i++) {
126+
args[i] = await this._expandArgVariables(args[i]);
127+
}
128+
await vscode.commands.executeCommand(cmd.id, ...args);
129+
}
130+
}
131+
132+
async _expandArgVariables(arg) {
133+
if (!arg.includes('${')) {
134+
return arg;
135+
}
136+
const matches = arg.match(/\$\{[^\}]+\}/g);
137+
for (const match of matches) {
138+
if (match.startsWith('${command:')) {
139+
arg = arg.replace(
140+
match,
141+
await vscode.commands.executeCommand(match.substring(10, match.length - 1))
142+
);
143+
}
144+
}
145+
return arg;
146+
}
126147
}

0 commit comments

Comments
 (0)