Skip to content

Commit 17b1e30

Browse files
authored
Added command to "Refresh file contents" (intersystems-community#1066)
1 parent 9c700c5 commit 17b1e30

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"workspaceContains:**/*.csr",
6464
"onCommand:vscode-objectscript.export",
6565
"onCommand:vscode-objectscript.compile",
66+
"onCommand:vscode-objectscript.refreshLocalFile",
6667
"onCommand:vscode-objectscript.viewOthers",
6768
"onCommand:vscode-objectscript.jumpToTagAndOffset",
6869
"onCommand:vscode-objectscript.previewXml",
@@ -139,6 +140,10 @@
139140
"command": "vscode-objectscript.compile",
140141
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
141142
},
143+
{
144+
"command": "vscode-objectscript.refreshLocalFile",
145+
"when": "resourceScheme == file && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
146+
},
142147
{
143148
"command": "vscode-objectscript.compileWithFlags",
144149
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
@@ -930,6 +935,11 @@
930935
"command": "vscode-objectscript.compileFolder",
931936
"title": "Import and Compile"
932937
},
938+
{
939+
"category": "ObjectScript",
940+
"command": "vscode-objectscript.refreshLocalFile",
941+
"title": "Overwrite from Server"
942+
},
933943
{
934944
"category": "ObjectScript",
935945
"command": "vscode-objectscript.importFolder",

src/extension.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
checkChangedOnServer,
2727
compileOnly,
2828
importLocalFilesToServerSideFolder,
29+
loadChanges,
2930
} from "./commands/compile";
3031
import { deleteExplorerItems } from "./commands/delete";
3132
import { exportAll, exportCurrentFile, exportExplorerItems, getCategory } from "./commands/export";
@@ -785,6 +786,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
785786
vscode.commands.registerCommand("vscode-objectscript.compileWithFlags", () => importAndCompile(true)),
786787
vscode.commands.registerCommand("vscode-objectscript.compileAll", () => namespaceCompile(false)),
787788
vscode.commands.registerCommand("vscode-objectscript.compileAllWithFlags", () => namespaceCompile(true)),
789+
vscode.commands.registerCommand("vscode-objectscript.refreshLocalFile", async (_file, files) => {
790+
const file = currentFile();
791+
if (!file) {
792+
return;
793+
}
794+
795+
try {
796+
await loadChanges([file]);
797+
} catch (error) {
798+
let message = `Failed to overwrite file from server '${file.fileName}'.`;
799+
if (error && error.errorText && error.errorText !== "") {
800+
outputChannel.appendLine("\n" + error.errorText);
801+
outputChannel.show(true);
802+
message += " Check 'ObjectScript' output channel for details.";
803+
}
804+
vscode.window.showErrorMessage(message, "Dismiss");
805+
return;
806+
}
807+
}),
788808
vscode.commands.registerCommand("vscode-objectscript.compileFolder", (_file, files) =>
789809
Promise.all(files.map((file) => importFileOrFolder(file, false)))
790810
),

0 commit comments

Comments
 (0)