Hello,
This is a beginner question which started with the simple question “does the upload action in VSCode includes a build stage if needed”. From various discussions (e.g. this feature request for “upload without rebuild”), I understand that the answer is yes. However, I was frustrated to not find the proper doc which states “upload action does trigger a build if needed”. Does such a doc exist?
Then, this raised the more general question of “how are VSCode actions defined”, since the “Build” action in fact triggers the platformio run(same as pio run CLI?) task from what I can see in the terminal, while “Upload” action triggers platformio run --target upload, which, to be honest is hard to understand from the doc since the central word “upload” is not defined there…
Then looking at the VSCode PlatformIO toolbar doc, I see that it can be customized from settings, but there I see that the Build/Upload toolbar buttons are shorcuts for platformio-ide.upload/.build commands, so this doesn’t tell how those commands are defined.
So sorry for the confusing questions, but I’d be happy to get the pointers to the relevant doc. Or if something is missing, I’ll be glad to add once I understand where it should fit.
I think the actions are defined internally.
If you take a look at the settings.json you’ll find things like platformio-ide.showHome, platformio-ide.clean and so on:
"platformio-ide.toolbar": [
{
"text": "$(home)",
"tooltip": "PlatformIO: Home",
"commands": "platformio-ide.showHome"
},
{
"text": "$(trashcan)",
"tooltip": "PlatformIO: Clean",
"commands": "platformio-ide.clean"
},
{
"text": "$(check)",
"tooltip": "PlatformIO: Build",
"commands": "platformio-ide.build"
},
...
You can add your own buttons.
Here is an example for "upload without build":
{
"text": "$(debug-step-out)",
"tooltip": "PlatformIO: Upload without build",
"commands": [
{
"id": "platformio-ide.runPIOCoreCommand",
"args": "pio run -t nobuild -t upload"
}
]
},
Unfortunately this might not answer your question but allows you to define your own buttons (if that was your intention)
Thanks for your feedback. My intention was more to understand how things works, but thanks for sharing the recipe to add new action buttons.
Well, I would say that is is only going one level down in the stack of indirections, since I see:
vscode.commands.registerCommand('platformio-ide.build', () => _runTask('Build')),
which associates the 'platformio-ide.build' string to the locally defined _runTask() function, passing it a name argument 'Build'. If I understand _runTask correcly, it only runs a task with an appropriate name that it has found within the tasks list. This list comes as argument to the registerTaskBasedCommands(tasks) function which contains all these lines of code.
So now the question becomes: where are these tasks defined?
I see that registerTaskBasedCommands() is called in the refresh() function platformio-vscode-ide/src/project/tasks.js at develop · platformio/platformio-vscode-ide · GitHub. Here the tasks list is named projectTasks and is the concatenation of two origins:
So now the question becomes… 
I’m not a PlatformIO developer.
Maybe @ivankravets or @valeros can answer your question.
1 Like
Great! So we have the following mapping:
- Build:
$pio run
- Upload:
$pio run --target upload
- …
and each of these commands is documented in CLI Guide — PlatformIO latest documentation, so it’s possible to create links in a future version of the doc.
1 Like