diff --git a/package-lock.json b/package-lock.json index 2db7f6a..8ce8521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zesty-vscode-extension", - "version": "0.0.1", + "version": "0.0.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "zesty-vscode-extension", - "version": "0.0.1", + "version": "0.0.7", "dependencies": { "@zesty-io/sdk": "^0.3.3", "node-fetch": "^2.6.0" diff --git a/package.json b/package.json index c1b25c7..38d23ba 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "icon": "images/zesty-io.png", "publisher": "zesty-io", "description": "", - "version": "0.0.6", + "version": "0.0.7", "engines": { "vscode": "^1.74.0" }, @@ -43,6 +43,10 @@ { "command": "zesty-vscode-extension.run", "title": "Sync to Instance" + }, + { + "command": "zesty-vscode-extension.saveAndSyncFile", + "title": "Save & Push to Instance" } ], "keybindings": [ @@ -57,6 +61,18 @@ "when": "resourceFilename == zesty.config.json", "command": "zesty-vscode-extension.run", "group": "zestyio-menu@1" + }, + { + "when": "resourcePath =~ /webengine/", + "command": "zesty-vscode-extension.saveAndSyncFile", + "group": "zestyio-menu@2" + } + ], + "editor/context": [ + { + "when": "resourcePath =~ /webengine/", + "command": "zesty-vscode-extension.saveAndSyncFile", + "group": "zestyio-menu@2" } ] } diff --git a/src/extension.js b/src/extension.js index ad7be99..558e0ec 100644 --- a/src/extension.js +++ b/src/extension.js @@ -258,6 +258,50 @@ async function saveFile(document) { } } +async function syncFileFromUri(uri) { + + let document = null; + const activeEditor = vscode.window.activeTextEditor; + + if (uri) { + if ( + activeEditor && + activeEditor.document && + activeEditor.document.uri.toString() === uri.toString() + ) { + document = activeEditor.document; + } else { + document = await vscode.workspace.openTextDocument(uri); + } + } else if (activeEditor && activeEditor.document) { + document = activeEditor.document; + } + + if (!document) { + vscode.window.showErrorMessage("No file selected to sync."); + return; + } + + if (document.isDirty) { + const choice = await vscode.window.showWarningMessage( + "File has unsaved changes. Save before syncing?", + "Save & Sync", + "Sync Without Saving", + "Cancel" + ); + if (choice === "Cancel" || !choice) return; + if (choice === "Save & Sync") { + const saved = await document.save(); + if (!saved) { + vscode.window.showErrorMessage("Save failed. Sync cancelled."); + return; + } + } + } + + await saveFile(document); +} + function getFile(file) { var splitPath = file.fsPath.split("\\"); var newSplitPath = splitPath.slice( @@ -321,6 +365,15 @@ async function activate(context) { }) ); + context.subscriptions.push( + vscode.commands.registerCommand( + "zesty-vscode-extension.saveAndSyncFile", + async (uri) => { + await syncFileFromUri(uri); + } + ) + ); + vscode.workspace.onDidSaveTextDocument(async (document) => { if (!isFileSaveSyncEnabled()) return; await saveFile(document); @@ -476,4 +529,4 @@ function deactivate() {} module.exports = { activate, deactivate, -}; +}; \ No newline at end of file