Skip to content

Commit

Permalink
Added additionalSyncFolders
Browse files Browse the repository at this point in the history
- Fixes #40, Config additional sync folders per project
  • Loading branch information
paulober committed Jun 19, 2023
1 parent 2994b7b commit ac64692
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 50 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ while True:

This extension contributes the following settings:

* `picowgo.autoConnect`: Ignores any 'device address' setting and automatically connects to the top item in the serialport list.
* `picowgo.autoConnect`: Ignores any 'device address' setting and automatically connects to the top item in the serial-port list (of Picos).
* `picowgo.manualComDevice`: If autoConnect is set to false Pico-W-Go will automatically connect to the serial port specified here.
* `picowgo.syncFolder`: This folder will be uploaded to the pyboard when using the sync button. Leave empty to sync the complete project. (only allows folders within the project). Use a path relative to the project you opened in vscode, without leading or trailing slash.
* `picowgo.additionalSyncFolders`: Specifies additional folders that can be selected as upload sources when uploading a project. If left empty, the sync will be performed based on the folder specified in the 'syncFolder' setting. Only folders within the project are allowed. Specify the path relative to the project you have opened in Visual Studio Code, without a leading or trailing slash.
* `picowgo.syncAllFileTypes`: If enabled, all files will be uploaded no matter the file type. The list of file types below will be ignored.
* `picowgo.syncFileTypes`: All types of files that will be uploaded to the board, seperated by comma. All other filetypes will be ignored during an upload (or download) action.
* `picowgo.pyIgnore`: Comma separated list of files and folders to ignore when uploading (no wildcard or regular expressions supported).
* `picowgo.openOnStart`: Automatically open the Pico-W-Go console and connect to the board after starting VS Code.
* `picowgo.statusbarButtons`: Select which buttons to show in the statusbar (DO NOT CHANGE, unless you know what you are doing)
* `picowgo.gcBeforeUpload`: [Only works with firmware v1.16.0.b1 and up.] Run garbage collection before uploading files to the board. This will free up some memory usefull when uploading large files but adds about a second or two to the upload process.
* `picowgo.gcBeforeUpload`: Run garbage collection before uploading files to the board. This will free up some memory usefull when uploading large files but adds about a second or two to the upload process.
* `picowgo.softResetAfterUpload`: Soft-resets your board after any upload action. Usefull if you are developing with `main.py` or `boot.py`.
* `picowgo.pythonPath`: Path to the Python interpreter. Defaults to null so it will try to auto-detect a suitable python installation.
* `picowgo.pythonPath`: Path to the Python interpreter. Defaults to null so it will try to auto-detect a suitable python installation. NOTE: Must be deleted from global settings.json when switing between operating systems and settings-sync is enabled!

---

Expand Down
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,25 @@
"description": "This folder will be uploaded to the pyboard when using the sync button. Leave empty to sync the complete project. (only allows folders within the project). Use a path relative to the project you opened in vscode, without leading or trailing slash",
"order": 4
},
"picowgo.additionalSyncFolders": {
"type": "array",
"items": {
"type": "string",
"uniqueItems": true
},
"default": [],
"scope": "resource",
"title": "Additional Sync Folders",
"description": "Specifies additional folders that can be selected as upload sources when uploading a project. If left empty, the sync will be performed based on the folder specified in the 'syncFolder' setting. Only folders within the project are allowed. Specify the path relative to the project you have opened in Visual Studio Code, without a leading or trailing slash.",
"order": 5
},
"picowgo.syncAllFileTypes": {
"type": "boolean",
"default": false,
"scope": "machine-overridable",
"title": "Upload all file types",
"description": "If enabled, all files will be uploaded no matter the file type. The list of file types below will be ignored",
"order": 5
"order": 6
},
"picowgo.syncFileTypes": {
"type": "array",
Expand All @@ -292,7 +304,7 @@
"scope": "machine-overridable",
"title": "Upload file types",
"description": "All types of files that will be uploaded to the board, seperated by comma. All other filetypes will be ignored during an upload (or download) action",
"order": 6
"order": 7
},
"picowgo.pyIgnore": {
"title": "Pyignore list",
Expand All @@ -311,15 +323,15 @@
"env",
"venv"
],
"order": 7
"order": 8
},
"picowgo.openOnStart": {
"type": "boolean",
"default": false,
"scope": "machine",
"title": "Open on start",
"description": "Automatically open the Pico-W-Go console after starting VS Code. Could cause random terminal freezes on Linux.",
"order": 8
"order": 9
},
"picowgo.statusbarButtons": {
"type": "array",
Expand Down Expand Up @@ -350,15 +362,15 @@
"softreset",
"togglepicowfs"
],
"order": 9
"order": 10
},
"picowgo.gcBeforeUpload": {
"type": "boolean",
"default": true,
"scope": "machine-overridable",
"title": "Garbage collection before upload",
"description": "Run garbage collection before uploading files to the board. This will free up some memory usefull when uploading large files but adds about a second or two to the upload process.",
"order": 10
"order": 11
},
"picowgo.softResetAfterUpload": {
"type": "boolean",
Expand All @@ -374,7 +386,7 @@
"scope": "machine",
"title": "Python Path",
"description": "Path to the Python interpreter. Default for Windows is 'python.exe' and 'python3' for Linux and MacOS.",
"order": 12
"order": 13
}
}
},
Expand Down
87 changes: 47 additions & 40 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,12 @@ export default class Activator {
return;
}

const syncDir = settings.getSyncFolderAbsPath();
const syncDir = await settings.requestSyncFolder("Upload");

if (syncDir === undefined) {
void vscode.window.showErrorMessage("No open project found!");
void vscode.window.showWarningMessage(
"Upload canceled. No sync folder selected."
);

return;
}
Expand Down Expand Up @@ -635,51 +637,56 @@ export default class Activator {

// [Command] Download project
// TODO: maybe add diffent warning methods for overwritten files in syncFolder
disposable = vscode.commands.registerCommand("picowgo.download", () => {
if (!this.pyb?.isPipeConnected()) {
void vscode.window.showWarningMessage(
"Please connect to the Pico first."
);
disposable = vscode.commands.registerCommand(
"picowgo.download",
async () => {
if (!this.pyb?.isPipeConnected()) {
void vscode.window.showWarningMessage(
"Please connect to the Pico first."
);

return;
}
return;
}

const syncDir = settings.getSyncFolderAbsPath();
const syncDir = await settings.requestSyncFolder("Download");

if (syncDir === undefined) {
void vscode.window.showErrorMessage(
"No open project with syncFolder as download target found!"
);
if (syncDir === undefined) {
void vscode.window.showWarningMessage(
"Download canceled. No sync folder selected."
);

return;
}
return;
}

void vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Downloading Project...",
cancellable: false,
},
async (progress /*, token*/) => {
const data = await this.pyb?.downloadProject(
syncDir,
(/*data: string*/) => undefined
);
if (data && data.type === PyOutType.status) {
const result = data as PyOutStatus;
if (result.status) {
progress.report({
increment: 100,
message: "Project downloaded.",
});
void vscode.window.showInformationMessage("Project downloaded.");
} else {
void vscode.window.showErrorMessage("Project download failed.");
void vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Downloading Project...",
cancellable: false,
},
async (progress /*, token*/) => {
const data = await this.pyb?.downloadProject(
syncDir,
(/*data: string*/) => undefined
);
if (data && data.type === PyOutType.status) {
const result = data as PyOutStatus;
if (result.status) {
progress.report({
increment: 100,
message: "Project downloaded.",
});
void vscode.window.showInformationMessage(
"Project downloaded."
);
} else {
void vscode.window.showErrorMessage("Project download failed.");
}
}
}
}
);
});
);
}
);
context.subscriptions.push(disposable);

// [Command] Delete all files on Pico
Expand Down
53 changes: 53 additions & 0 deletions src/settings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum SettingsKey {
autoConnect = "autoConnect",
manualComDevice = "manualComDevice",
syncFolder = "syncFolder",
additionalSyncFolders = "additionalSyncFolders",
syncAllFileTypes = "syncAllFileTypes",
syncFileTypes = "syncFileTypes",
pyIgnore = "pyIgnore",
Expand Down Expand Up @@ -120,6 +121,58 @@ export default class Settings {
return join(projectDir, syncDir);
}

/**
* Returns the absolute path to one sync folder based on the user's selection
* when multiple folders are configured.
* If only one folder is configured, its absolute path is returned.
*
* @param actionTitle The title of the action to perform. Used in the selection dialog.
* E.g. "Upload" or "Download".
*
* @returns The absolute path to one sync folder.
*/
public async requestSyncFolder(
actionTitle: string
): Promise<string | undefined> {
const syncFolder = this.getSyncFolderAbsPath();
const projectDir = getProjectPath();

if (projectDir === undefined) {
// How can this ever happen??!
return;
}

let additionalSyncFolders = this.getArray(
SettingsKey.additionalSyncFolders
)?.map(sf => join(projectDir, sf));

if (
additionalSyncFolders === undefined ||
additionalSyncFolders.length === 0
) {
return syncFolder;
}

// prepend normal syncFolder if available to options
if (
syncFolder !== undefined &&
!additionalSyncFolders.includes(syncFolder)
) {
additionalSyncFolders = [syncFolder, ...additionalSyncFolders];
}

const selectedFolder = await window.showQuickPick(additionalSyncFolders, {
placeHolder:
`Select a sync folder to ${actionTitle.toLowerCase()} ` +
"(add more in settings)",
canPickMany: false,
ignoreFocusOut: false,
title: `${actionTitle} sync folder selection`,
});

return selectedFolder;
}

/**
* Returns the file types to sync.
* If syncAllFileTypes is false and syncFileTypes is undefined, an
Expand Down

0 comments on commit ac64692

Please sign in to comment.