Skip to content

Commit ce9aebb

Browse files
committed
John's suggestion, other changes
1 parent 955c818 commit ce9aebb

File tree

7 files changed

+56
-27
lines changed

7 files changed

+56
-27
lines changed

src/commands/project.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,17 @@ export async function createProject(node: NodeBase | undefined, api?: AtelierAPI
140140

141141
// Technically a project is a "document", so tell the server that we created it
142142
try {
143-
await new StudioActions().fireProjectUserAction(api, name, OtherStudioAction.CreatedNewDocument);
144-
await new StudioActions().fireProjectUserAction(api, name, OtherStudioAction.FirstTimeDocumentSave);
143+
const studioActions = new StudioActions();
144+
await studioActions.fireProjectUserAction(api, name, OtherStudioAction.CreatedNewDocument);
145+
await studioActions.fireProjectUserAction(api, name, OtherStudioAction.FirstTimeDocumentSave);
145146
} catch (error) {
146147
let message = `Source control actions failed for project '${name}'.`;
147148
if (error && error.errorText && error.errorText !== "") {
148149
outputChannel.appendLine("\n" + error.errorText);
149150
outputChannel.show(true);
150151
message += " Check 'ObjectScript' output channel for details.";
151152
}
152-
return vscode.window.showErrorMessage(message, "Dismiss");
153+
vscode.window.showErrorMessage(message, "Dismiss");
153154
}
154155

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

210211
// Refresh the explorer
@@ -736,17 +737,9 @@ export async function modifyProject(
736737
}
737738

738739
// Technically a project is a "document", so tell the server that we're opening it
739-
try {
740-
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument);
741-
} catch (error) {
742-
let message = `'OpenedDocument' source control action failed for project '${project}'.`;
743-
if (error && error.errorText && error.errorText !== "") {
744-
outputChannel.appendLine("\n" + error.errorText);
745-
outputChannel.show(true);
746-
message += " Check 'ObjectScript' output channel for details.";
747-
}
748-
return vscode.window.showErrorMessage(message, "Dismiss");
749-
}
740+
await new StudioActions()
741+
.fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument)
742+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
750743

751744
let items: ProjectItem[] = await api
752745
.actionQuery("SELECT Name, Type FROM %Studio.Project_ProjectItemsList(?,?) WHERE Type != 'GBL'", [project, "1"])

src/commands/unitTest.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getFileText, methodOffsetToLine, outputChannel, stripClassMemberNameQuo
55
import { fileSpecFromURI } from "../utils/FileProviderUtil";
66
import { AtelierAPI } from "../api";
77
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
8+
import { StudioActions, OtherStudioAction } from "./studio";
89

910
enum TestStatus {
1011
Failed = 0,
@@ -259,7 +260,7 @@ function replaceRootTestItems(testController: vscode.TestController): void {
259260
}
260261

261262
/** Create a `Promise` that resolves to a query result containing an array of children for `item`. */
262-
function childrenForServerSideFolderItem(
263+
async function childrenForServerSideFolderItem(
263264
item: vscode.TestItem
264265
): Promise<Atelier.Response<Atelier.Content<{ Name: string }[]>>> {
265266
let query: string;
@@ -275,6 +276,10 @@ function childrenForServerSideFolderItem(
275276
const params = new URLSearchParams(item.uri.query);
276277
const api = new AtelierAPI(item.uri);
277278
if (params.has("project")) {
279+
// Technically a project is a "document", so tell the server that we're opening it
280+
await new StudioActions()
281+
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
282+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
278283
query =
279284
"SELECT DISTINCT CASE " +
280285
"WHEN $LENGTH(SUBSTR(Name,?),'.') > 1 THEN $PIECE(SUBSTR(Name,?),'.') " +

src/explorer/explorer.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { config, OBJECTSCRIPT_FILE_SCHEMA, projectsExplorerProvider } from "../e
66
import { WorkspaceNode } from "./models/workspaceNode";
77
import { outputChannel } from "../utils";
88
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
9+
import { StudioActions, OtherStudioAction } from "../commands/studio";
910

1011
/** Get the URI for this leaf node */
1112
export function getLeafNodeUri(node: NodeBase, forceServerCopy = false): vscode.Uri {
@@ -74,6 +75,20 @@ export function registerExplorerOpen(): vscode.Disposable {
7475
if (remove == "Yes") {
7576
const api = new AtelierAPI(uri);
7677
try {
78+
// Technically a project is a "document", so tell the server that we're editing it
79+
const studioActions = new StudioActions();
80+
await studioActions.fireProjectUserAction(api, project, OtherStudioAction.AttemptedEdit);
81+
if (studioActions.projectEditAnswer != "1") {
82+
// Don't perform the edit
83+
if (studioActions.projectEditAnswer == "-1") {
84+
// Source control action failed
85+
vscode.window.showErrorMessage(
86+
`'AttemptedEdit' source control action failed for project '${project}'. Check the 'ObjectScript' Output channel for details.`,
87+
"Dismiss"
88+
);
89+
}
90+
return;
91+
}
7792
// Remove the item from the project
7893
let prjFileName = fullName.startsWith("/") ? fullName.slice(1) : fullName;
7994
const ext = prjFileName.split(".").pop().toLowerCase();

src/explorer/models/projectNode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export class ProjectNode extends NodeBase {
1818
// Technically a project is a "document", so tell the server that we're opening it
1919
const api = new AtelierAPI(this.workspaceFolderUri);
2020
api.setNamespace(this.namespace);
21-
await new StudioActions().fireProjectUserAction(api, this.label, OtherStudioAction.OpenedDocument);
21+
await new StudioActions()
22+
.fireProjectUserAction(api, this.label, OtherStudioAction.OpenedDocument)
23+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
2224

2325
node = new ProjectRootNode(
2426
"Classes",

src/providers/FileSystemProvider/FileSearchProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/Fil
33
import { notNull } from "../../utils";
44
import { DocumentContentProvider } from "../DocumentContentProvider";
55
import { ProjectItem } from "../../commands/project";
6+
import { StudioActions, OtherStudioAction } from "../../commands/studio";
7+
import { AtelierAPI } from "../../api";
68

79
export class FileSearchProvider implements vscode.FileSearchProvider {
810
/**
@@ -11,20 +13,25 @@ export class FileSearchProvider implements vscode.FileSearchProvider {
1113
* @param options A set of options to consider while searching files.
1214
* @param token A cancellation token.
1315
*/
14-
public provideFileSearchResults(
16+
public async provideFileSearchResults(
1517
query: vscode.FileSearchQuery,
1618
options: vscode.FileSearchOptions,
1719
token: vscode.CancellationToken
18-
): vscode.ProviderResult<vscode.Uri[]> {
20+
): Promise<vscode.Uri[]> {
1921
let counter = 0;
2022
let pattern = query.pattern.charAt(0) == "/" ? query.pattern.slice(1) : query.pattern;
2123
const params = new URLSearchParams(options.folder.query);
2224
const csp = params.has("csp") && ["", "1"].includes(params.get("csp"));
2325
if (params.has("project") && params.get("project").length) {
24-
const patternRegex = new RegExp(`.*${pattern}.*`.replace(/\.|\//g, "[./]"), "i");
26+
// Technically a project is a "document", so tell the server that we're opening it
27+
await new StudioActions()
28+
.fireProjectUserAction(new AtelierAPI(options.folder), params.get("project"), OtherStudioAction.OpenedDocument)
29+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
2530
if (token.isCancellationRequested) {
2631
return;
2732
}
33+
34+
const patternRegex = new RegExp(`.*${pattern}.*`.replace(/\.|\//g, "[./]"), "i");
2835
return projectContentsFromUri(options.folder, true).then((docs) =>
2936
docs
3037
.map((doc: ProjectItem) => {

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
204204
if (params.has("project") && params.get("project").length) {
205205
if (["", "/"].includes(uri.path)) {
206206
// Technically a project is a "document", so tell the server that we're opening it
207-
try {
208-
await new StudioActions().fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument);
209-
} catch {
210-
throw vscode.FileSystemError.Unavailable(
211-
`'OpenedDocument' source control action failed for '${params.get("project")}.PRJ'`
212-
);
213-
}
207+
await new StudioActions()
208+
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
209+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
214210
}
215211

216212
// Get all items in the project

src/providers/FileSystemProvider/TextSearchProvider.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DocumentContentProvider } from "../DocumentContentProvider";
66
import { notNull, outputChannel, throttleRequests } from "../../utils";
77
import { config } from "../../extension";
88
import { fileSpecFromURI } from "../../utils/FileProviderUtil";
9+
import { OtherStudioAction, StudioActions } from "../../commands/studio";
910

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

399+
if (params.has("project") && params.get("project").length) {
400+
// Technically a project is a "document", so tell the server that we're opening it
401+
await new StudioActions()
402+
.fireProjectUserAction(api, params.get("project"), OtherStudioAction.OpenedDocument)
403+
.catch(/* Swallow error because showing it is more disruptive than using a potentially outdated project definition */);
404+
}
405+
if (token.isCancellationRequested) {
406+
return;
407+
}
408+
398409
if (api.config.apiVersion >= 6) {
399410
// Build the request object
400411
const project = params.has("project") && params.get("project").length ? params.get("project") : undefined;

0 commit comments

Comments
 (0)