Skip to content

Commit 114a76b

Browse files
committed
Server-side source control improvements
1 parent 904bb7a commit 114a76b

File tree

2 files changed

+78
-87
lines changed

2 files changed

+78
-87
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@
201201
},
202202
{
203203
"command": "vscode-objectscript.serverCommands.sourceControl",
204-
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || vscode-objectscript.connectActive && !editorIsOpen"
204+
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || (vscode-objectscript.connectActive && !editorIsOpen)"
205205
},
206206
{
207207
"command": "vscode-objectscript.serverCommands.contextSourceControl",
208208
"when": "false"
209209
},
210210
{
211211
"command": "vscode-objectscript.serverCommands.other",
212-
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ || vscode-objectscript.connectActive && !editorIsOpen"
212+
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ || (vscode-objectscript.connectActive && !editorIsOpen)"
213213
},
214214
{
215215
"command": "vscode-objectscript.serverCommands.contextOther",
@@ -575,12 +575,12 @@
575575
},
576576
{
577577
"command": "vscode-objectscript.serverCommands.contextSourceControl",
578-
"when": "resourceScheme == isfs && vscode-objectscript.connectActive",
578+
"when": "resourceScheme == isfs && vscode-objectscript.connectActive && resourcePath && !(resourcePath =~ /^\\/?$/) && !(explorerResourceIsFolder && resource =~ /\\?csp(%3D1|$)/)",
579579
"group": "objectscript_servercommand@1"
580580
},
581581
{
582582
"command": "vscode-objectscript.serverCommands.contextOther",
583-
"when": "resourceScheme =~ /^isfs(-readonly)?$/ && vscode-objectscript.connectActive",
583+
"when": "resourceScheme =~ /^isfs(-readonly)?$/ && vscode-objectscript.connectActive && resourcePath && !(resourcePath =~ /^\\/?$/) && !(explorerResourceIsFolder && resource =~ /\\?csp(%3D1|$)/)",
584584
"group": "objectscript_servercommand@2"
585585
},
586586
{

src/commands/studio.ts

Lines changed: 74 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -295,94 +295,85 @@ export class StudioActions {
295295
? [type.toString(), action.id, this.name, answer, msg]
296296
: [type.toString(), action.id, this.name, selectedText];
297297

298-
return vscode.window.withProgress(
299-
{
300-
cancellable: false,
301-
location: vscode.ProgressLocation.Notification,
302-
title: `Executing ${afterUserAction ? "AfterUserAction" : "UserAction"}: ${action.label}`,
303-
},
304-
() => {
305-
return new Promise((resolve, reject) => {
306-
this.api
307-
.actionQuery(query, parameters)
308-
.then(async (data) => {
309-
if (action.save && action.id != "6" /* No save for import list */) {
310-
await this.processSaveFlag(action.save);
311-
}
312-
if (!afterUserAction) {
313-
outputConsole(data.console);
314-
}
315-
if (!data.result.content.length) {
316-
// nothing to-do, just ignore it
317-
return;
318-
}
319-
const actionToProcess = data.result.content.pop();
298+
if (config().studioActionDebugOutput) {
299+
outputChannel.appendLine(`${query.slice(0, query.indexOf("("))}(${JSON.stringify(parameters).slice(1, -1)})`);
300+
}
320301

321-
if (actionToProcess.reload) {
322-
// Avoid the reload triggering the edit listener here
323-
suppressEditListenerMap.set(this.uri.toString(), true);
324-
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
325-
}
302+
return new Promise((resolve, reject) => {
303+
this.api
304+
.actionQuery(query, parameters)
305+
.then(async (data) => {
306+
if (action.save && action.id != "6" /* No save for import list */) {
307+
await this.processSaveFlag(action.save);
308+
}
309+
if (!afterUserAction) {
310+
outputConsole(data.console);
311+
}
312+
if (!data.result.content.length) {
313+
// Nothing to do. Most likely no source control class is enabled.
314+
this.projectEditAnswer = "1";
315+
return;
316+
}
317+
const actionToProcess = data.result.content.pop();
326318

327-
// CSP pages should not have a progress bar
328-
if (actionToProcess.action === 2) {
329-
resolve();
330-
}
319+
if (actionToProcess.reload) {
320+
// Avoid the reload triggering the edit listener here
321+
suppressEditListenerMap.set(this.uri.toString(), true);
322+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
323+
}
331324

332-
const attemptedEditLabel = getOtherStudioActionLabel(OtherStudioAction.AttemptedEdit);
333-
if (afterUserAction && actionToProcess.errorText !== "") {
334-
if (action.label === attemptedEditLabel) {
335-
if (this.name.toUpperCase().endsWith(".PRJ")) {
336-
// Store the "answer" so the caller knows there was an error
337-
this.projectEditAnswer = "-1";
338-
} else if (this.uri) {
339-
// Only revert if we have a URI
340-
suppressEditListenerMap.set(this.uri.toString(), true);
341-
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
342-
}
343-
}
344-
outputChannel.appendLine(actionToProcess.errorText);
345-
outputChannel.show();
325+
const attemptedEditLabel = getOtherStudioActionLabel(OtherStudioAction.AttemptedEdit);
326+
if (afterUserAction && actionToProcess.errorText !== "") {
327+
if (action.label === attemptedEditLabel) {
328+
if (this.name.toUpperCase().endsWith(".PRJ")) {
329+
// Store the "answer" so the caller knows there was an error
330+
this.projectEditAnswer = "-1";
331+
} else if (this.uri) {
332+
// Only revert if we have a URI
333+
suppressEditListenerMap.set(this.uri.toString(), true);
334+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
346335
}
347-
if (actionToProcess && !afterUserAction) {
348-
const answer = await this.processUserAction(actionToProcess);
349-
// call AfterUserAction only if there is a valid answer
350-
if (action.label === attemptedEditLabel) {
351-
if (answer != "1" && this.uri) {
352-
// Only revert if we have a URI
353-
suppressEditListenerMap.set(this.uri.toString(), true);
354-
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
355-
}
356-
if (this.name.toUpperCase().endsWith(".PRJ")) {
357-
// Store the answer. No answer means "allow the edit".
358-
this.projectEditAnswer = answer ?? "1";
359-
}
360-
}
361-
if (answer) {
362-
answer.msg || answer.msg === ""
363-
? this.userAction(action, true, answer.answer, answer.msg, type)
364-
: this.userAction(action, true, answer, "", type);
365-
}
336+
}
337+
outputChannel.appendLine(actionToProcess.errorText);
338+
outputChannel.show(true);
339+
}
340+
if (actionToProcess && !afterUserAction) {
341+
const answer = await this.processUserAction(actionToProcess);
342+
// call AfterUserAction only if there is a valid answer
343+
if (action.label === attemptedEditLabel) {
344+
if (answer != "1" && this.uri) {
345+
// Only revert if we have a URI
346+
suppressEditListenerMap.set(this.uri.toString(), true);
347+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
366348
}
367-
})
368-
.then(() => resolve())
369-
.catch((err) => {
370-
outputChannel.appendLine(
371-
`Executing Studio Action "${action.label}" on ${this.api.config.host}:${this.api.config.port}${
372-
this.api.config.pathPrefix
373-
}[${this.api.config.ns}] failed${
374-
err.errorText && err.errorText !== "" ? " with the following error:" : "."
375-
}`
376-
);
377-
if (err.errorText && err.errorText !== "") {
378-
outputChannel.appendLine("\n" + err.errorText);
349+
if (this.name.toUpperCase().endsWith(".PRJ")) {
350+
// Store the answer. No answer means "allow the edit".
351+
this.projectEditAnswer = answer ?? "1";
379352
}
380-
outputChannel.show();
381-
reject();
382-
});
353+
}
354+
if (answer) {
355+
answer.msg || answer.msg === ""
356+
? this.userAction(action, true, answer.answer, answer.msg, type)
357+
: this.userAction(action, true, answer, "", type);
358+
}
359+
}
360+
})
361+
.then(() => resolve())
362+
.catch((err) => {
363+
outputChannel.appendLine(
364+
`Executing Studio Action "${action.label}" on ${this.api.config.host}:${this.api.config.port}${
365+
this.api.config.pathPrefix
366+
}[${this.api.config.ns}] failed${
367+
err.errorText && err.errorText !== "" ? " with the following error:" : "."
368+
}`
369+
);
370+
if (err.errorText && err.errorText !== "") {
371+
outputChannel.appendLine("\n" + err.errorText);
372+
}
373+
outputChannel.show(true);
374+
reject();
383375
});
384-
}
385-
);
376+
});
386377
}
387378

388379
private prepareMenuItems(menus, sourceControl: boolean): StudioAction[] {
@@ -501,7 +492,8 @@ export class StudioActions {
501492
return this.api
502493
.actionQuery("SELECT %Atelier_v1_Utils.Extension_ExtensionEnabled() AS Enabled", [])
503494
.then((data) => data.result.content)
504-
.then((content) => (content && content.length ? content[0].Enabled : false));
495+
.then((content) => (content && content.length ? content[0]?.Enabled ?? false : false))
496+
.catch(() => false); // Treat any errors as "no source control"
505497
}
506498

507499
public getServerInfo(): { server: string; namespace: string } {
@@ -576,7 +568,6 @@ export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vsc
576568
const studioActions = new StudioActions(uri);
577569
return (
578570
studioActions &&
579-
(await studioActions.isSourceControlEnabled()) &&
580571
!openCustomEditors.includes(uri?.toString()) && // The custom editor will handle all server-side source control interactions
581572
studioActions.fireOtherStudioAction(action, userAction)
582573
);

0 commit comments

Comments
 (0)