Skip to content

Commit 8fd3ed1

Browse files
authored
Reduce REST traffic for server-side folders (#1532)
1 parent 9c0e843 commit 8fd3ed1

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/commands/project.ts

-10
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,6 @@ export async function modifyProject(
680680
if (!args) return;
681681
const { node, api, project } = args;
682682

683-
// Technically a project is a "document", so tell the server that we're opening it
684-
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
685-
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
686-
});
687-
688683
let items: ProjectItem[] = await api
689684
.actionQuery("SELECT Name, Type FROM %Studio.Project_ProjectItemsList(?,?) WHERE Type != 'GBL'", [project, "1"])
690685
.then((data) => data.result.content);
@@ -1149,11 +1144,6 @@ export async function modifyProjectMetadata(nodeOrUri: NodeBase | vscode.Uri | u
11491144
if (!args) return;
11501145
const { api, project } = args;
11511146

1152-
// Technically a project is a "document", so tell the server that we're opening it
1153-
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
1154-
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
1155-
});
1156-
11571147
try {
11581148
const oldDesc: string = await api
11591149
.actionQuery("SELECT Description FROM %Studio.Project WHERE Name = ?", [project])

src/extension.ts

+26
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
OtherStudioAction,
5959
contextSourceControlMenu,
6060
mainSourceControlMenu,
61+
StudioActions,
6162
} from "./commands/studio";
6263
import { addServerNamespaceToWorkspace, pickServerAndNamespace } from "./commands/addServerNamespaceToWorkspace";
6364
import { jumpToTagAndOffset, openErrorLocation } from "./commands/jumpToTagAndOffset";
@@ -153,6 +154,7 @@ import {
153154
} from "./utils/documentIndex";
154155
import { WorkspaceNode, NodeBase } from "./explorer/nodes";
155156
import { showPlanWebview } from "./commands/showPlanPanel";
157+
import { isfsConfig } from "./utils/FileProviderUtil";
156158

157159
const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
158160
const extensionVersion = packageJson.version;
@@ -708,6 +710,25 @@ async function systemModeWarning(wsFolders: readonly vscode.WorkspaceFolder[]):
708710
}
709711
}
710712

713+
/**
714+
* Fire the `OpenedDocument` UserAction for any workspace folders
715+
* that are showing the contents of a server-side project.
716+
* This must be done because technically a project is a "document".
717+
*/
718+
async function fireOpenProjectUserAction(wsFolders: readonly vscode.WorkspaceFolder[]): Promise<void> {
719+
if (!wsFolders || wsFolders.length == 0) return;
720+
for (const wsFolder of wsFolders) {
721+
if (notIsfs(wsFolder.uri)) return;
722+
const { project } = isfsConfig(wsFolder.uri);
723+
if (!project) return;
724+
const api = new AtelierAPI(wsFolder.uri);
725+
if (!api.active) return;
726+
new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
727+
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
728+
});
729+
}
730+
}
731+
711732
/**
712733
* Set when clause context keys so the ObjectScript Explorer and
713734
* Projects Explorer views are correctly shown or hidden depending
@@ -941,6 +962,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
941962
// Warn about SystemMode
942963
systemModeWarning(vscode.workspace.workspaceFolders);
943964

965+
// Fire OpenedDocument UserAction for folders showing the contents of a server-side project
966+
fireOpenProjectUserAction(vscode.workspace.workspaceFolders);
967+
944968
iscIcon = vscode.Uri.joinPath(context.extensionUri, "images", "fileIcon.svg");
945969

946970
// Index documents in all local workspace folders
@@ -1531,6 +1555,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
15311555
for (const r of e.removed) removeIndexOfWorkspaceFolder(r);
15321556
// Show or hide explorer views as needed
15331557
setExplorerContextKeys();
1558+
// Fire OpenedDocument UserAction for added folders showing the contents of a server-side project
1559+
fireOpenProjectUserAction(e.added);
15341560
}),
15351561
vscode.commands.registerCommand("vscode-objectscript.importXMLFiles", importXMLFiles),
15361562
vscode.commands.registerCommand("vscode-objectscript.exportToXMLFile", exportDocumentsToXMLFile),

src/providers/FileSystemProvider/FileSystemProvider.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "path";
22
import * as vscode from "vscode";
33
import { isText } from "istextorbinary";
44
import { AtelierAPI } from "../../api";
5-
import { fireOtherStudioAction, OtherStudioAction, StudioActions } from "../../commands/studio";
5+
import { fireOtherStudioAction, OtherStudioAction } from "../../commands/studio";
66
import { isfsConfig, projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/FileProviderUtil";
77
import {
88
classNameRegex,
@@ -234,6 +234,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
234234
}
235235

236236
public async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
237+
if (!new AtelierAPI(uri).active) throw vscode.FileSystemError.Unavailable("Server connection is inactive");
237238
let entryPromise: Promise<Entry>;
238239
let result: Entry;
239240
const redirectedUri = redirectDotvscodeRoot(uri);
@@ -284,19 +285,14 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
284285
}
285286

286287
public async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> {
287-
uri = redirectDotvscodeRoot(uri);
288+
if (uri.path.includes(".vscode/")) {
289+
throw vscode.FileSystemError.NoPermissions("Cannot read the /.vscode directory");
290+
}
288291
const parent = await this._lookupAsDirectory(uri);
289292
const api = new AtelierAPI(uri);
290293
if (!api.active) throw vscode.FileSystemError.Unavailable(uri);
291294
const { csp, project } = isfsConfig(uri);
292295
if (project) {
293-
if (["", "/"].includes(uri.path)) {
294-
// Technically a project is a "document", so tell the server that we're opening it
295-
await new StudioActions().fireProjectUserAction(api, project, OtherStudioAction.OpenedDocument).catch(() => {
296-
// Swallow error because showing it is more disruptive than using a potentially outdated project definition
297-
});
298-
}
299-
300296
// Get all items in the project
301297
return projectContentsFromUri(uri).then((entries) =>
302298
entries.map((entry) => {
@@ -864,11 +860,6 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
864860
// Fetch entry (a file or directory) from cache, else from server
865861
private async _lookup(uri: vscode.Uri, fillInPath?: boolean): Promise<Entry> {
866862
const api = new AtelierAPI(uri);
867-
if (uri.path === "/") {
868-
await api.serverInfo().catch((error) => {
869-
throw vscode.FileSystemError.Unavailable(stringifyError(error) || uri);
870-
});
871-
}
872863
const config = api.config;
873864
const rootName = `${config.username}@${config.host}:${config.port}${config.pathPrefix}/${config.ns.toUpperCase()}`;
874865
let entry: Entry = this.superRoot.entries.get(rootName);

0 commit comments

Comments
 (0)