Skip to content

Server-side source control improvements #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@
},
{
"command": "vscode-objectscript.serverCommands.sourceControl",
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || vscode-objectscript.connectActive && !editorIsOpen"
"when": "vscode-objectscript.connectActive && resourceScheme == isfs || (vscode-objectscript.connectActive && !editorIsOpen)"
},
{
"command": "vscode-objectscript.serverCommands.contextSourceControl",
"when": "false"
},
{
"command": "vscode-objectscript.serverCommands.other",
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ || vscode-objectscript.connectActive && !editorIsOpen"
"when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ || (vscode-objectscript.connectActive && !editorIsOpen)"
},
{
"command": "vscode-objectscript.serverCommands.contextOther",
Expand Down Expand Up @@ -575,12 +575,12 @@
},
{
"command": "vscode-objectscript.serverCommands.contextSourceControl",
"when": "resourceScheme == isfs && vscode-objectscript.connectActive",
"when": "resourceScheme == isfs && vscode-objectscript.connectActive && resourcePath && !(resourcePath =~ /^\\/?$/) && !(explorerResourceIsFolder && resource =~ /\\?csp(%3D1|$)/)",
"group": "objectscript_servercommand@1"
},
{
"command": "vscode-objectscript.serverCommands.contextOther",
"when": "resourceScheme =~ /^isfs(-readonly)?$/ && vscode-objectscript.connectActive",
"when": "resourceScheme =~ /^isfs(-readonly)?$/ && vscode-objectscript.connectActive && resourcePath && !(resourcePath =~ /^\\/?$/) && !(explorerResourceIsFolder && resource =~ /\\?csp(%3D1|$)/)",
"group": "objectscript_servercommand@2"
},
{
Expand Down
11 changes: 10 additions & 1 deletion src/api/atelier.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ interface ServerInfoFeature {
enabled: string;
}

export interface UserAction {
action: number;
target: string;
message: string;
reload: boolean;
doc: any;
errorText: string;
}

export interface Document {
name: string;
db: string;
Expand All @@ -34,7 +43,7 @@ export interface Document {
enc: boolean;
flags: number;
content: string[] | Buffer;
ext: string;
ext?: UserAction | UserAction[];
}

export interface ServerInfo {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { explorerProvider } from "../extension";
import { outputChannel } from "../utils";
import { OtherStudioAction, fireOtherStudioAction } from "./studio";
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
import { UserAction } from "../api/atelier";

function deleteList(items: string[], workspaceFolder: string, namespace: string): Promise<any> {
if (!items || !items.length) {
Expand All @@ -20,7 +21,7 @@ function deleteList(items: string[], workspaceFolder: string, namespace: string)
files.forEach((file) => {
if (file.result.ext) {
const uri = DocumentContentProvider.getUri(file.result.name);
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, file.result.ext);
fireOtherStudioAction(OtherStudioAction.DeletedDocument, uri, <UserAction>file.result.ext);
}
});
outputChannel.appendLine(`Deleted items: ${files.filter((el) => el.result).length}`);
Expand Down
49 changes: 25 additions & 24 deletions src/commands/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RoutineNode } from "../explorer/models/routineNode";
import { importAndCompile } from "./compile";
import { ProjectNode } from "../explorer/models/projectNode";
import { openCustomEditors } from "../providers/RuleEditorProvider";
import { UserAction } from "../api/atelier";

export let documentBeingProcessed: vscode.TextDocument = null;

Expand Down Expand Up @@ -119,9 +120,8 @@ export class StudioActions {
);
}

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

if (config().studioActionDebugOutput) {
outputChannel.appendLine(`${query.slice(0, query.indexOf("("))}(${JSON.stringify(parameters).slice(1, -1)})`);
}

return vscode.window.withProgress(
{
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: `Executing ${afterUserAction ? "AfterUserAction" : "UserAction"}: ${action.label}`,
location: vscode.ProgressLocation.Window,
title: `Executing ${afterUserAction ? "After" : ""}UserAction: ${action.label}`,
},
() => {
return new Promise((resolve, reject) => {
() =>
new Promise((resolve, reject) => {
this.api
.actionQuery(query, parameters)
.then(async (data) => {
Expand All @@ -313,22 +317,18 @@ export class StudioActions {
outputConsole(data.console);
}
if (!data.result.content.length) {
// nothing to-do, just ignore it
// Nothing to do. Most likely no source control class is enabled.
this.projectEditAnswer = "1";
return;
}
const actionToProcess = data.result.content.pop();
const actionToProcess: UserAction = data.result.content.pop();

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

// CSP pages should not have a progress bar
if (actionToProcess.action === 2) {
resolve();
}

const attemptedEditLabel = getOtherStudioActionLabel(OtherStudioAction.AttemptedEdit);
if (afterUserAction && actionToProcess.errorText !== "") {
if (action.label === attemptedEditLabel) {
Expand All @@ -342,7 +342,7 @@ export class StudioActions {
}
}
outputChannel.appendLine(actionToProcess.errorText);
outputChannel.show();
outputChannel.show(true);
}
if (actionToProcess && !afterUserAction) {
const answer = await this.processUserAction(actionToProcess);
Expand Down Expand Up @@ -377,11 +377,10 @@ export class StudioActions {
if (err.errorText && err.errorText !== "") {
outputChannel.appendLine("\n" + err.errorText);
}
outputChannel.show();
outputChannel.show(true);
reject();
});
});
}
})
);
}

Expand Down Expand Up @@ -438,8 +437,7 @@ export class StudioActions {
.then((action) => this.userAction(action));
}

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

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

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vscode.Uri, userAction?): Promise<void> {
export async function fireOtherStudioAction(
action: OtherStudioAction,
uri?: vscode.Uri,
userAction?: UserAction
): Promise<void> {
if (vscode.workspace.getConfiguration("objectscript.serverSourceControl", uri)?.get("disableOtherActionTriggers")) {
return;
}
const studioActions = new StudioActions(uri);
return (
studioActions &&
(await studioActions.isSourceControlEnabled()) &&
!openCustomEditors.includes(uri?.toString()) && // The custom editor will handle all server-side source control interactions
studioActions.fireOtherStudioAction(action, userAction)
);
Expand Down
4 changes: 2 additions & 2 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { config, intLangId, macLangId, workspaceState } from "../../extension";
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
import { DocumentContentProvider } from "../DocumentContentProvider";
import { Document } from "../../api/atelier";
import { Document, UserAction } from "../../api/atelier";

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

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