Skip to content

Commit 4165510

Browse files
authored
Server-side source control improvements (#1314)
1 parent 9ada3df commit 4165510

File tree

5 files changed

+43
-32
lines changed

5 files changed

+43
-32
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/api/atelier.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ interface ServerInfoFeature {
2424
enabled: string;
2525
}
2626

27+
export interface UserAction {
28+
action: number;
29+
target: string;
30+
message: string;
31+
reload: boolean;
32+
doc: any;
33+
errorText: string;
34+
}
35+
2736
export interface Document {
2837
name: string;
2938
db: string;
@@ -34,7 +43,7 @@ export interface Document {
3443
enc: boolean;
3544
flags: number;
3645
content: string[] | Buffer;
37-
ext: string;
46+
ext?: UserAction | UserAction[];
3847
}
3948

4049
export interface ServerInfo {

src/commands/delete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { explorerProvider } from "../extension";
88
import { outputChannel } from "../utils";
99
import { OtherStudioAction, fireOtherStudioAction } from "./studio";
1010
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
11+
import { UserAction } from "../api/atelier";
1112

1213
function deleteList(items: string[], workspaceFolder: string, namespace: string): Promise<any> {
1314
if (!items || !items.length) {
@@ -20,7 +21,7 @@ function deleteList(items: string[], workspaceFolder: string, namespace: string)
2021
files.forEach((file) => {
2122
if (file.result.ext) {
2223
const uri = DocumentContentProvider.getUri(file.result.name);
23-
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, file.result.ext);
24+
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, <UserAction>file.result.ext);
2425
}
2526
});
2627
outputChannel.appendLine(`Deleted items: ${files.filter((el) => el.result).length}`);

src/commands/studio.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RoutineNode } from "../explorer/models/routineNode";
99
import { importAndCompile } from "./compile";
1010
import { ProjectNode } from "../explorer/models/projectNode";
1111
import { openCustomEditors } from "../providers/RuleEditorProvider";
12+
import { UserAction } from "../api/atelier";
1213

1314
export let documentBeingProcessed: vscode.TextDocument = null;
1415

@@ -119,9 +120,8 @@ export class StudioActions {
119120
);
120121
}
121122

122-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
123-
public processUserAction(userAction): Thenable<any> {
124-
const serverAction = parseInt(userAction.action || 0, 10);
123+
public processUserAction(userAction: UserAction): Thenable<any> {
124+
const serverAction = userAction.action;
125125
const { target, errorText } = userAction;
126126
if (errorText !== "") {
127127
outputChannel.appendLine(errorText);
@@ -295,14 +295,18 @@ export class StudioActions {
295295
? [type.toString(), action.id, this.name, answer, msg]
296296
: [type.toString(), action.id, this.name, selectedText];
297297

298+
if (config().studioActionDebugOutput) {
299+
outputChannel.appendLine(`${query.slice(0, query.indexOf("("))}(${JSON.stringify(parameters).slice(1, -1)})`);
300+
}
301+
298302
return vscode.window.withProgress(
299303
{
300304
cancellable: false,
301-
location: vscode.ProgressLocation.Notification,
302-
title: `Executing ${afterUserAction ? "AfterUserAction" : "UserAction"}: ${action.label}`,
305+
location: vscode.ProgressLocation.Window,
306+
title: `Executing ${afterUserAction ? "After" : ""}UserAction: ${action.label}`,
303307
},
304-
() => {
305-
return new Promise((resolve, reject) => {
308+
() =>
309+
new Promise((resolve, reject) => {
306310
this.api
307311
.actionQuery(query, parameters)
308312
.then(async (data) => {
@@ -313,22 +317,18 @@ export class StudioActions {
313317
outputConsole(data.console);
314318
}
315319
if (!data.result.content.length) {
316-
// nothing to-do, just ignore it
320+
// Nothing to do. Most likely no source control class is enabled.
321+
this.projectEditAnswer = "1";
317322
return;
318323
}
319-
const actionToProcess = data.result.content.pop();
324+
const actionToProcess: UserAction = data.result.content.pop();
320325

321326
if (actionToProcess.reload) {
322327
// Avoid the reload triggering the edit listener here
323328
suppressEditListenerMap.set(this.uri.toString(), true);
324329
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
325330
}
326331

327-
// CSP pages should not have a progress bar
328-
if (actionToProcess.action === 2) {
329-
resolve();
330-
}
331-
332332
const attemptedEditLabel = getOtherStudioActionLabel(OtherStudioAction.AttemptedEdit);
333333
if (afterUserAction && actionToProcess.errorText !== "") {
334334
if (action.label === attemptedEditLabel) {
@@ -342,7 +342,7 @@ export class StudioActions {
342342
}
343343
}
344344
outputChannel.appendLine(actionToProcess.errorText);
345-
outputChannel.show();
345+
outputChannel.show(true);
346346
}
347347
if (actionToProcess && !afterUserAction) {
348348
const answer = await this.processUserAction(actionToProcess);
@@ -377,11 +377,10 @@ export class StudioActions {
377377
if (err.errorText && err.errorText !== "") {
378378
outputChannel.appendLine("\n" + err.errorText);
379379
}
380-
outputChannel.show();
380+
outputChannel.show(true);
381381
reject();
382382
});
383-
});
384-
}
383+
})
385384
);
386385
}
387386

@@ -438,8 +437,7 @@ export class StudioActions {
438437
.then((action) => this.userAction(action));
439438
}
440439

441-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
442-
public fireOtherStudioAction(action: OtherStudioAction, userAction?): void {
440+
public fireOtherStudioAction(action: OtherStudioAction, userAction?: UserAction): void {
443441
const actionObject = {
444442
id: action.toString(),
445443
label: getOtherStudioActionLabel(action),
@@ -501,7 +499,8 @@ export class StudioActions {
501499
return this.api
502500
.actionQuery("SELECT %Atelier_v1_Utils.Extension_ExtensionEnabled() AS Enabled", [])
503501
.then((data) => data.result.content)
504-
.then((content) => (content && content.length ? content[0].Enabled : false));
502+
.then((content) => (content && content.length ? content[0]?.Enabled ?? false : false))
503+
.catch(() => false); // Treat any errors as "no source control"
505504
}
506505

507506
public getServerInfo(): { server: string; namespace: string } {
@@ -568,15 +567,17 @@ export async function _contextMenu(sourceControl: boolean, node: PackageNode | C
568567
}
569568
}
570569

571-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
572-
export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vscode.Uri, userAction?): Promise<void> {
570+
export async function fireOtherStudioAction(
571+
action: OtherStudioAction,
572+
uri?: vscode.Uri,
573+
userAction?: UserAction
574+
): Promise<void> {
573575
if (vscode.workspace.getConfiguration("objectscript.serverSourceControl", uri)?.get("disableOtherActionTriggers")) {
574576
return;
575577
}
576578
const studioActions = new StudioActions(uri);
577579
return (
578580
studioActions &&
579-
(await studioActions.isSourceControlEnabled()) &&
580581
!openCustomEditors.includes(uri?.toString()) && // The custom editor will handle all server-side source control interactions
581582
studioActions.fireOtherStudioAction(action, userAction)
582583
);

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { config, intLangId, macLangId, workspaceState } from "../../extension";
1717
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
1818
import { DocumentContentProvider } from "../DocumentContentProvider";
19-
import { Document } from "../../api/atelier";
19+
import { Document, UserAction } from "../../api/atelier";
2020

2121
declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout;
2222

@@ -453,7 +453,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
453453
const events: vscode.FileChangeEvent[] = [];
454454
try {
455455
if (doc.ext) {
456-
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, doc.ext);
456+
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, <UserAction>doc.ext);
457457
}
458458
// Remove entry from our cache, plus any now-empty ancestor entries
459459
let thisUri = vscode.Uri.parse(uri.toString(), true);

0 commit comments

Comments
 (0)