Skip to content

Commit

Permalink
John's suggestion, other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Feb 14, 2024
1 parent 955c818 commit ce9aebb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
23 changes: 8 additions & 15 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ export async function createProject(node: NodeBase | undefined, api?: AtelierAPI

// Technically a project is a "document", so tell the server that we created it
try {
await new StudioActions().fireProjectUserAction(api, name, OtherStudioAction.CreatedNewDocument);
await new StudioActions().fireProjectUserAction(api, name, OtherStudioAction.FirstTimeDocumentSave);
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.";
}
return vscode.window.showErrorMessage(message, "Dismiss");
vscode.window.showErrorMessage(message, "Dismiss");
}

// Refresh the explorer
Expand Down Expand Up @@ -204,7 +205,7 @@ export async function deleteProject(node: ProjectNode | undefined): Promise<any>
outputChannel.show(true);
message += " Check 'ObjectScript' output channel for details.";
}
return vscode.window.showErrorMessage(message, "Dismiss");
vscode.window.showErrorMessage(message, "Dismiss");
}

// Refresh the explorer
Expand Down Expand Up @@ -736,17 +737,9 @@ export async function modifyProject(
}

// Technically a project is a "document", so tell the server that we're opening it
try {
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument);
} catch (error) {
let message = `'OpenedDocument' 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.";
}
return vscode.window.showErrorMessage(message, "Dismiss");
}
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"])
Expand Down
7 changes: 6 additions & 1 deletion src/commands/unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getFileText, methodOffsetToLine, outputChannel, stripClassMemberNameQuo
import { fileSpecFromURI } from "../utils/FileProviderUtil";
import { AtelierAPI } from "../api";
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
import { StudioActions, OtherStudioAction } from "./studio";

enum TestStatus {
Failed = 0,
Expand Down Expand Up @@ -259,7 +260,7 @@ function replaceRootTestItems(testController: vscode.TestController): void {
}

/** Create a `Promise` that resolves to a query result containing an array of children for `item`. */
function childrenForServerSideFolderItem(
async function childrenForServerSideFolderItem(
item: vscode.TestItem
): Promise<Atelier.Response<Atelier.Content<{ Name: string }[]>>> {
let query: string;
Expand All @@ -275,6 +276,10 @@ function childrenForServerSideFolderItem(
const params = new URLSearchParams(item.uri.query);
const api = new AtelierAPI(item.uri);
if (params.has("project")) {
// Technically a project is a "document", so tell the server that we're opening it
await new StudioActions()
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
query =
"SELECT DISTINCT CASE " +
"WHEN $LENGTH(SUBSTR(Name,?),'.') > 1 THEN $PIECE(SUBSTR(Name,?),'.') " +
Expand Down
15 changes: 15 additions & 0 deletions src/explorer/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { config, OBJECTSCRIPT_FILE_SCHEMA, projectsExplorerProvider } from "../e
import { WorkspaceNode } from "./models/workspaceNode";
import { outputChannel } from "../utils";
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
import { StudioActions, OtherStudioAction } from "../commands/studio";

/** Get the URI for this leaf node */
export function getLeafNodeUri(node: NodeBase, forceServerCopy = false): vscode.Uri {
Expand Down Expand Up @@ -74,6 +75,20 @@ export function registerExplorerOpen(): vscode.Disposable {
if (remove == "Yes") {
const api = new AtelierAPI(uri);
try {
// 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;
}
// Remove the item from the project
let prjFileName = fullName.startsWith("/") ? fullName.slice(1) : fullName;
const ext = prjFileName.split(".").pop().toLowerCase();
Expand Down
4 changes: 3 additions & 1 deletion src/explorer/models/projectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export class ProjectNode extends NodeBase {
// Technically a project is a "document", so tell the server that we're opening it
const api = new AtelierAPI(this.workspaceFolderUri);
api.setNamespace(this.namespace);
await new StudioActions().fireProjectUserAction(api, this.label, OtherStudioAction.OpenedDocument);
await new StudioActions()
.fireProjectUserAction(api, this.label, OtherStudioAction.OpenedDocument)
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);

node = new ProjectRootNode(
"Classes",
Expand Down
13 changes: 10 additions & 3 deletions src/providers/FileSystemProvider/FileSearchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/Fil
import { notNull } from "../../utils";
import { DocumentContentProvider } from "../DocumentContentProvider";
import { ProjectItem } from "../../commands/project";
import { StudioActions, OtherStudioAction } from "../../commands/studio";
import { AtelierAPI } from "../../api";

export class FileSearchProvider implements vscode.FileSearchProvider {
/**
Expand All @@ -11,20 +13,25 @@ export class FileSearchProvider implements vscode.FileSearchProvider {
* @param options A set of options to consider while searching files.
* @param token A cancellation token.
*/
public provideFileSearchResults(
public async provideFileSearchResults(
query: vscode.FileSearchQuery,
options: vscode.FileSearchOptions,
token: vscode.CancellationToken
): vscode.ProviderResult<vscode.Uri[]> {
): Promise<vscode.Uri[]> {
let counter = 0;
let pattern = query.pattern.charAt(0) == "/" ? query.pattern.slice(1) : query.pattern;
const params = new URLSearchParams(options.folder.query);
const csp = params.has("csp") && ["", "1"].includes(params.get("csp"));
if (params.has("project") && params.get("project").length) {
const patternRegex = new RegExp(`.*${pattern}.*`.replace(/\.|\//g, "[./]"), "i");
// Technically a project is a "document", so tell the server that we're opening it
await new StudioActions()
.fireProjectUserAction(new AtelierAPI(options.folder), params.get("project"), OtherStudioAction.OpenedDocument)
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
if (token.isCancellationRequested) {
return;
}

const patternRegex = new RegExp(`.*${pattern}.*`.replace(/\.|\//g, "[./]"), "i");
return projectContentsFromUri(options.folder, true).then((docs) =>
docs
.map((doc: ProjectItem) => {
Expand Down
10 changes: 3 additions & 7 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
if (params.has("project") && params.get("project").length) {
if (["", "/"].includes(uri.path)) {
// Technically a project is a "document", so tell the server that we're opening it
try {
await new StudioActions().fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument);
} catch {
throw vscode.FileSystemError.Unavailable(
`'OpenedDocument' source control action failed for '${params.get("project")}.PRJ'`
);
}
await new StudioActions()
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
}

// Get all items in the project
Expand Down
11 changes: 11 additions & 0 deletions src/providers/FileSystemProvider/TextSearchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DocumentContentProvider } from "../DocumentContentProvider";
import { notNull, outputChannel, throttleRequests } from "../../utils";
import { config } from "../../extension";
import { fileSpecFromURI } from "../../utils/FileProviderUtil";
import { OtherStudioAction, StudioActions } from "../../commands/studio";

/**
* Convert an `attrline` in a description to a line number in document `content`.
Expand Down Expand Up @@ -395,6 +396,16 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
// Needed because the server matches the full line against the regex and ignores the case parameter when in regex mode
const pattern = query.isRegExp ? `${!query.isCaseSensitive ? "(?i)" : ""}.*${query.pattern}.*` : query.pattern;

if (params.has("project") && params.get("project").length) {
// Technically a project is a "document", so tell the server that we're opening it
await new StudioActions()
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
}
if (token.isCancellationRequested) {
return;
}

if (api.config.apiVersion >= 6) {
// Build the request object
const project = params.has("project") && params.get("project").length ? params.get("project") : undefined;
Expand Down

0 comments on commit ce9aebb

Please sign in to comment.