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 7 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
69 changes: 68 additions & 1 deletion src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isCSPFile } from "../providers/FileSystemProvider/FileSystemProvider";
import { notNull, outputChannel } from "../utils";
import { pickServerAndNamespace } from "./addServerNamespaceToWorkspace";
import { exportList } from "./export";
import { OtherStudioAction, StudioActions } from "./studio";

export interface ProjectItem {
Name: string;
Expand Down Expand Up @@ -137,6 +138,21 @@ export async function createProject(node: NodeBase | undefined, api?: AtelierAPI
return;
}

// Technically a project is a "document", so tell the server that we created it
try {
const studioActions = new StudioActions();
await studioActions.fireProjectUserAction(api, name, OtherStudioAction.CreatedNewDocument);
await studioActions.fireProjectUserAction(api, name, OtherStudioAction.FirstTimeDocumentSave);
} catch (error) {
let message = `Source control actions failed for project '${name}'.`;
if (error && error.errorText && error.errorText !== "") {
outputChannel.appendLine("\n" + error.errorText);
outputChannel.show(true);
message += " Check 'ObjectScript' output channel for details.";
}
vscode.window.showErrorMessage(message, "Dismiss");
}

// Refresh the explorer
projectsExplorerProvider.refresh();

Expand Down Expand Up @@ -179,6 +195,19 @@ export async function deleteProject(node: ProjectNode | undefined): Promise<any>
return vscode.window.showErrorMessage(message, "Dismiss");
}

// Technically a project is a "document", so tell the server that we deleted it
try {
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.DeletedDocument);
} catch (error) {
let message = `'DeletedDocument' source control action failed for project '${project}'.`;
if (error && error.errorText && error.errorText !== "") {
outputChannel.appendLine("\n" + error.errorText);
outputChannel.show(true);
message += " Check 'ObjectScript' output channel for details.";
}
vscode.window.showErrorMessage(message, "Dismiss");
}

// Refresh the explorer
projectsExplorerProvider.refresh();

Expand Down Expand Up @@ -706,6 +735,12 @@ export async function modifyProject(
return;
}
}

// Technically a project is a "document", so tell the server that we're opening it
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
});

let items: ProjectItem[] = await api
.actionQuery("SELECT Name, Type FROM %Studio.Project_ProjectItemsList(?,?) WHERE Type != 'GBL'", [project, "1"])
.then((data) => data.result.content);
Expand Down Expand Up @@ -862,6 +897,23 @@ export async function modifyProject(
}

try {
if (add.length || remove.length) {
// Technically a project is a "document", so tell the server that we're editing it
const studioActions = new StudioActions();
await studioActions.fireProjectUserAction(api, project, OtherStudioAction.AttemptedEdit);
if (studioActions.projectEditAnswer != "1") {
// Don't perform the edit
if (studioActions.projectEditAnswer == "-1") {
// Source control action failed
vscode.window.showErrorMessage(
`'AttemptedEdit' source control action failed for project '${project}'. Check the 'ObjectScript' Output channel for details.`,
"Dismiss"
);
}
return;
}
}

if (remove.length) {
// Delete the obsolete items
await api.actionQuery(
Expand Down Expand Up @@ -900,7 +952,7 @@ export async function modifyProject(

// Refresh the files explorer if there's an isfs folder for this project
if (node == undefined && isfsFolderForProject(project, node ?? api.configName) != -1) {
await vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer");
vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer");
}
}
}
Expand Down Expand Up @@ -1070,6 +1122,21 @@ export async function addIsfsFileToProject(

try {
if (add.length) {
// Technically a project is a "document", so tell the server that we're editing it
const studioActions = new StudioActions();
await studioActions.fireProjectUserAction(api, project, OtherStudioAction.AttemptedEdit);
if (studioActions.projectEditAnswer != "1") {
// Don't perform the edit
if (studioActions.projectEditAnswer == "-1") {
// Source control action failed
vscode.window.showErrorMessage(
`'AttemptedEdit' source control action failed for project '${project}'. Check the 'ObjectScript' Output channel for details.`,
"Dismiss"
);
}
return;
}

// Add any new items
await api.actionQuery(
`INSERT INTO %Studio.ProjectItem (Project,Name,Type) SELECT * FROM (${add
Expand Down
Loading