Skip to content

Commit 61ced17

Browse files
authored
More client-side tweaks (#1571)
1 parent e244202 commit 61ced17

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import {
106106
isClassOrRtn,
107107
addWsServerRootFolderData,
108108
getWsFolder,
109+
exportedUris,
109110
} from "./utils";
110111
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
111112
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
@@ -1253,8 +1254,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12531254
vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => {
12541255
return Promise.all(
12551256
e.files
1256-
.filter(notIsfs)
1257-
.filter(isClassOrRtn)
1257+
// Only attempt to adjust the names of classes and routines that are
1258+
// not server-side files and were not created due to an export
1259+
.filter((f) => notIsfs(f) && isClassOrRtn(f) && !exportedUris.has(f.toString()))
12581260
.map(async (uri) => {
12591261
// Determine the file name
12601262
const workspace = workspaceFolderOfUri(uri);

src/utils/documentIndex.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const wsFolderIndex: Map<string, WSFolderIndex> = new Map();
3939
const textDecoder = new TextDecoder("utf-8", { fatal: true });
4040

4141
/** The number of milliseconds that we should wait before sending a compile or delete request */
42-
const debounceDelay = 500;
42+
const debounceDelay = 1000;
4343

4444
/**
4545
* Create an object describing the file in `uri`.
@@ -86,20 +86,11 @@ function generateCompileFn(): (doc: CurrentTextFile | CurrentBinaryFile) => void
8686
// Clear the previous timeout to reset the debounce timer
8787
clearTimeout(timeout);
8888

89-
// Compile right away if this document is in the active text editor
90-
// and there are no other documents in the queue. This is needed
91-
// to avoid noticeable latency when a user is editing a client-side
92-
// file, saves it, and the auto-compile kicks in.
93-
if (docs.length == 1 && vscode.window.activeTextEditor?.document.uri.toString() == doc.uri.toString()) {
94-
compile([...docs]);
95-
docs.length = 0;
96-
return;
97-
}
98-
9989
// Set a new timeout to call the function after the specified delay
10090
timeout = setTimeout(() => {
101-
compile([...docs]);
91+
const docsCopy = [...docs];
10292
docs.length = 0;
93+
compile(docsCopy);
10394
}, debounceDelay);
10495
};
10596
}
@@ -118,7 +109,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
118109

119110
// Set a new timeout to call the function after the specified delay
120111
timeout = setTimeout(() => {
121-
api.deleteDocs([...docs]).then((data) => {
112+
const docsCopy = [...docs];
113+
docs.length = 0;
114+
api.deleteDocs(docsCopy).then((data) => {
122115
let failed = 0;
123116
for (const doc of data.result) {
124117
if (doc.status != "" && !doc.status.includes("#16005:")) {
@@ -142,7 +135,6 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
142135
);
143136
}
144137
});
145-
docs.length = 0;
146138
}, debounceDelay);
147139
};
148140
}
@@ -227,8 +219,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
227219
const api = new AtelierAPI(uri);
228220
const conf = vscode.workspace.getConfiguration("objectscript", wsFolder);
229221
const syncLocalChanges: string = conf.get("syncLocalChanges");
230-
const sync: boolean =
231-
api.active && (syncLocalChanges == "all" || (syncLocalChanges == "vscodeOnly" && touchedByVSCode.has(uriString)));
222+
const vscodeChange = touchedByVSCode.has(uriString);
223+
const sync = api.active && (syncLocalChanges == "all" || (syncLocalChanges == "vscodeOnly" && vscodeChange));
232224
touchedByVSCode.delete(uriString);
233225
let change: WSFolderIndexChange = {};
234226
if (isClassOrRtn(uri)) {
@@ -241,7 +233,16 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
241233
// Create or update the document on the server
242234
importFile(change.addedOrChanged)
243235
.then(() => {
244-
if (conf.get("compileOnSave")) debouncedCompile(change.addedOrChanged);
236+
if (conf.get("compileOnSave")) {
237+
// Compile right away if this document is in the active text editor.
238+
// This is needed to avoid noticeable latency when a user is editing
239+
// a client-side file, saves it, and the auto-compile kicks in.
240+
if (vscodeChange && vscode.window.activeTextEditor?.document.uri.toString() == uriString) {
241+
compile([change.addedOrChanged]);
242+
} else {
243+
debouncedCompile(change.addedOrChanged);
244+
}
245+
}
245246
})
246247
// importFile handles any server errors
247248
.catch(() => {});

0 commit comments

Comments
 (0)