Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -43,6 +43,10 @@
{
"command": "zesty-vscode-extension.run",
"title": "Sync to Instance"
},
{
"command": "zesty-vscode-extension.saveAndSyncFile",
"title": "Save & Push to Instance"
}
],
"keybindings": [
Expand All @@ -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"
}
]
}
Expand Down
55 changes: 54 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -476,4 +529,4 @@ function deactivate() {}
module.exports = {
activate,
deactivate,
};
};