Skip to content

Commit e9dba8c

Browse files
authored
Client-side improvements (#1470)
1 parent b20cb15 commit e9dba8c

File tree

7 files changed

+166
-135
lines changed

7 files changed

+166
-135
lines changed

src/commands/compile.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import {
2323
exportedUris,
2424
handleError,
2525
isClassDeployed,
26+
isClassOrRtn,
2627
notIsfs,
2728
notNull,
2829
outputChannel,
30+
RateLimiter,
2931
routineNameTypeRegex,
30-
throttleRequests,
3132
} from "../utils";
3233
import { StudioActions } from "./studio";
3334
import { NodeBase, PackageNode, RootNode } from "../explorer/nodes";
35+
import { updateIndexForDocument } from "../utils/documentIndex";
3436

3537
async function compileFlags(): Promise<string> {
3638
const defaultFlags = config().compileFlags;
@@ -226,6 +228,10 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
226228
file.uri,
227229
Buffer.isBuffer(content) ? content : new TextEncoder().encode(content.join("\n"))
228230
);
231+
if (isClassOrRtn(file.uri)) {
232+
// Update the document index
233+
updateIndexForDocument(file.uri, undefined, undefined, content);
234+
}
229235
exportedUris.push(file.uri.toString());
230236
} else if (filesystemSchemas.includes(file.uri.scheme)) {
231237
fileSystemProvider.fireFileChanged(file.uri);
@@ -414,9 +420,10 @@ export async function namespaceCompile(askFlags = false): Promise<any> {
414420

415421
async function importFiles(files: vscode.Uri[], noCompile = false) {
416422
const toCompile: CurrentFile[] = [];
423+
const rateLimiter = new RateLimiter(50);
417424
await Promise.allSettled<void>(
418-
files.map(
419-
throttleRequests((uri: vscode.Uri) => {
425+
files.map((uri) =>
426+
rateLimiter.call(async () => {
420427
return vscode.workspace.fs
421428
.readFile(uri)
422429
.then((contentBytes) => {
@@ -661,7 +668,7 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
661668
return;
662669
}
663670
// Filter out non-ISC files
664-
uris = uris.filter((uri) => ["cls", "mac", "int", "inc"].includes(uri.path.split(".").pop().toLowerCase()));
671+
uris = uris.filter(isClassOrRtn);
665672
if (uris.length == 0) {
666673
vscode.window.showErrorMessage("No classes or routines were selected.", "Dismiss");
667674
return;
@@ -711,9 +718,10 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
711718
docs.map((e) => e.name)
712719
);
713720
// Import the files
721+
const rateLimiter = new RateLimiter(50);
714722
return Promise.allSettled<string>(
715-
docs.map(
716-
throttleRequests((doc: { name: string; content: string; uri: vscode.Uri }) => {
723+
docs.map((doc) =>
724+
rateLimiter.call(async () => {
717725
// Allow importing over deployed classes since the XML import
718726
// command and SMP, terminal, and Studio imports allow it
719727
return importFileFromContent(doc.name, doc.content, api, false, true).then(() => {

src/commands/export.ts

+19-25
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import { AtelierAPI } from "../api";
44
import { config, explorerProvider, OBJECTSCRIPT_FILE_SCHEMA, schemas, workspaceState } from "../extension";
55
import {
66
currentFile,
7-
currentFileFromContent,
87
exportedUris,
98
handleError,
9+
isClassOrRtn,
1010
notNull,
1111
outputChannel,
12+
RateLimiter,
1213
stringifyError,
13-
throttleRequests,
1414
uriOfWorkspaceFolder,
15+
workspaceFolderOfUri,
1516
} from "../utils";
1617
import { pickDocuments } from "../utils/documentPicker";
1718
import { NodeBase } from "../explorer/nodes";
19+
import { updateIndexForDocument } from "../utils/documentIndex";
1820

1921
export function getCategory(fileName: string, addCategory: any | boolean): string {
2022
const fileExt = fileName.split(".").pop().toLowerCase();
@@ -99,28 +101,19 @@ async function exportFile(wsFolderUri: vscode.Uri, namespace: string, name: stri
99101
throw new Error("Received malformed JSON object from server fetching document");
100102
}
101103
const content = data.result.content;
102-
103-
// Local function to update local record of mtime
104-
const recordMtime = async () => {
105-
const contentString = Buffer.isBuffer(content) ? "" : content.join("\n");
106-
const file = currentFileFromContent(fileUri, contentString);
107-
const serverTime = Number(new Date(data.result.ts + "Z"));
108-
await workspaceState.update(`${file.uniqueId}:mtime`, serverTime);
109-
};
110-
if (Buffer.isBuffer(content)) {
111-
// This is a binary file
112-
await vscode.workspace.fs.writeFile(fileUri, content);
113-
exportedUris.push(fileUri.toString());
114-
await recordMtime();
115-
log("Success");
116-
} else {
117-
// This is a text file
118-
const joinedContent = content.join("\n");
119-
await vscode.workspace.fs.writeFile(fileUri, new TextEncoder().encode(joinedContent));
120-
exportedUris.push(fileUri.toString());
121-
await recordMtime();
122-
log("Success");
104+
await vscode.workspace.fs.writeFile(
105+
fileUri,
106+
Buffer.isBuffer(content) ? content : new TextEncoder().encode(content.join("\n"))
107+
);
108+
if (isClassOrRtn(fileUri)) {
109+
// Update the document index
110+
updateIndexForDocument(fileUri, undefined, undefined, content);
123111
}
112+
exportedUris.push(fileUri.toString());
113+
const ws = workspaceFolderOfUri(fileUri);
114+
const mtime = Number(new Date(data.result.ts + "Z"));
115+
if (ws) await workspaceState.update(`${ws}:${name}:mtime`, mtime > 0 ? mtime : undefined);
116+
log("Success");
124117
} catch (error) {
125118
const errorStr = stringifyError(error);
126119
log(errorStr == "" ? "ERROR" : errorStr);
@@ -146,6 +139,7 @@ export async function exportList(files: string[], workspaceFolder: string, names
146139
const { atelier, folder, addCategory, map } = config("export", workspaceFolder);
147140
const root = wsFolderUri.fsPath + (folder.length ? path.sep + folder : "");
148141
outputChannel.show(true);
142+
const rateLimiter = new RateLimiter(50);
149143
return vscode.window.withProgress(
150144
{
151145
title: `Exporting ${files.length == 1 ? files[0] : files.length + " documents"}`,
@@ -154,8 +148,8 @@ export async function exportList(files: string[], workspaceFolder: string, names
154148
},
155149
() =>
156150
Promise.allSettled<void>(
157-
files.map(
158-
throttleRequests((file: string) =>
151+
files.map((file) =>
152+
rateLimiter.call(() =>
159153
exportFile(wsFolderUri, namespace, file, getFileName(root, file, atelier, addCategory, map))
160154
)
161155
)

src/extension.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import {
101101
cspApps,
102102
otherDocExts,
103103
getWsServerConnection,
104+
isClassOrRtn,
104105
addWsServerRootFolderData,
105106
} from "./utils";
106107
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
@@ -1220,7 +1221,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12201221
return Promise.all(
12211222
e.files
12221223
.filter(notIsfs)
1223-
.filter((uri) => ["cls", "inc", "int", "mac"].includes(uri.path.split(".").pop().toLowerCase()))
1224+
.filter(isClassOrRtn)
12241225
.map(async (uri) => {
12251226
// Determine the file name
12261227
const workspace = workspaceFolderOfUri(uri);

src/providers/DocumentContentProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AtelierAPI } from "../api";
55

66
import { getFileName } from "../commands/export";
77
import { config, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA, OBJECTSCRIPT_FILE_SCHEMA } from "../extension";
8-
import { currentWorkspaceFolder, notIsfs, uriOfWorkspaceFolder } from "../utils";
8+
import { currentWorkspaceFolder, isClassOrRtn, notIsfs, uriOfWorkspaceFolder } from "../utils";
99
import { getUrisForDocument } from "../utils/documentIndex";
1010

1111
export function compareConns(
@@ -52,7 +52,7 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
5252
if (!notIsfs(wsFolder.uri)) return;
5353
const conf = vscode.workspace.getConfiguration("objectscript.export", wsFolder);
5454
const confFolder = conf.get("folder", "");
55-
if (["cls", "mac", "int", "inc"].includes(name.split(".").pop().toLowerCase())) {
55+
if (isClassOrRtn(name)) {
5656
// Use the document index to find the local URI
5757
const uris = getUrisForDocument(name, wsFolder);
5858
switch (uris.length) {

src/providers/FileSystemProvider/TextSearchProvider.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { makeRe } from "minimatch";
33
import { AsyncSearchRequest, SearchResult, SearchMatch } from "../../api/atelier";
44
import { AtelierAPI } from "../../api";
55
import { DocumentContentProvider } from "../DocumentContentProvider";
6-
import { handleError, notNull, outputChannel, throttleRequests } from "../../utils";
6+
import { handleError, notNull, outputChannel, RateLimiter } from "../../utils";
77
import { config } from "../../extension";
88
import { fileSpecFromURI } from "../../utils/FileProviderUtil";
99

@@ -280,6 +280,7 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
280280
const api = new AtelierAPI(options.folder);
281281
const params = new URLSearchParams(options.folder.query);
282282
const decoder = new TextDecoder();
283+
const rateLimiter = new RateLimiter(50);
283284
let counter = 0;
284285
if (!api.enabled) {
285286
return {
@@ -470,7 +471,7 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
470471
return api.verifiedCancel(id, false);
471472
}
472473
// Process matches
473-
filePromises.push(...pollResp.result.map(throttleRequests(reportMatchesForFile)));
474+
filePromises.push(...pollResp.result.map((file) => rateLimiter.call(() => reportMatchesForFile(file))));
474475
if (pollResp.retryafter) {
475476
await new Promise((resolve) => {
476477
setTimeout(resolve, 50);
@@ -524,8 +525,8 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
524525
requestGroups.push(group);
525526
}
526527
searchPromise = Promise.allSettled(
527-
requestGroups.map(
528-
throttleRequests((group: string[]) =>
528+
requestGroups.map((group) =>
529+
rateLimiter.call(() =>
529530
api
530531
.actionSearch({
531532
query: pattern,
@@ -628,8 +629,8 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
628629
return;
629630
}
630631
const resultsPromise = Promise.allSettled(
631-
files.map(
632-
throttleRequests(async (file: SearchResult): Promise<void> => {
632+
files.map((file) =>
633+
rateLimiter.call(() => {
633634
if (token.isCancellationRequested) {
634635
return;
635636
}

0 commit comments

Comments
 (0)