Skip to content

More client-side tweaks #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
isClassOrRtn,
addWsServerRootFolderData,
getWsFolder,
exportedUris,
} from "./utils";
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
Expand Down Expand Up @@ -1253,8 +1254,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => {
return Promise.all(
e.files
.filter(notIsfs)
.filter(isClassOrRtn)
// Only attempt to adjust the names of classes and routines that are
// not server-side files and were not created due to an export
.filter((f) => notIsfs(f) && isClassOrRtn(f) && !exportedUris.has(f.toString()))
.map(async (uri) => {
// Determine the file name
const workspace = workspaceFolderOfUri(uri);
Expand Down
35 changes: 18 additions & 17 deletions src/utils/documentIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const wsFolderIndex: Map<string, WSFolderIndex> = new Map();
const textDecoder = new TextDecoder("utf-8", { fatal: true });

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

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

// Compile right away if this document is in the active text editor
// and there are no other documents in the queue. This is needed
// to avoid noticeable latency when a user is editing a client-side
// file, saves it, and the auto-compile kicks in.
if (docs.length == 1 && vscode.window.activeTextEditor?.document.uri.toString() == doc.uri.toString()) {
compile([...docs]);
docs.length = 0;
return;
}

// Set a new timeout to call the function after the specified delay
timeout = setTimeout(() => {
compile([...docs]);
const docsCopy = [...docs];
docs.length = 0;
compile(docsCopy);
}, debounceDelay);
};
}
Expand All @@ -118,7 +109,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {

// Set a new timeout to call the function after the specified delay
timeout = setTimeout(() => {
api.deleteDocs([...docs]).then((data) => {
const docsCopy = [...docs];
docs.length = 0;
api.deleteDocs(docsCopy).then((data) => {
let failed = 0;
for (const doc of data.result) {
if (doc.status != "" && !doc.status.includes("#16005:")) {
Expand All @@ -142,7 +135,6 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
);
}
});
docs.length = 0;
}, debounceDelay);
};
}
Expand Down Expand Up @@ -227,8 +219,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
const api = new AtelierAPI(uri);
const conf = vscode.workspace.getConfiguration("objectscript", wsFolder);
const syncLocalChanges: string = conf.get("syncLocalChanges");
const sync: boolean =
api.active && (syncLocalChanges == "all" || (syncLocalChanges == "vscodeOnly" && touchedByVSCode.has(uriString)));
const vscodeChange = touchedByVSCode.has(uriString);
const sync = api.active && (syncLocalChanges == "all" || (syncLocalChanges == "vscodeOnly" && vscodeChange));
touchedByVSCode.delete(uriString);
let change: WSFolderIndexChange = {};
if (isClassOrRtn(uri)) {
Expand All @@ -241,7 +233,16 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
// Create or update the document on the server
importFile(change.addedOrChanged)
.then(() => {
if (conf.get("compileOnSave")) debouncedCompile(change.addedOrChanged);
if (conf.get("compileOnSave")) {
// Compile right away if this document is in the active text editor.
// This is needed to avoid noticeable latency when a user is editing
// a client-side file, saves it, and the auto-compile kicks in.
if (vscodeChange && vscode.window.activeTextEditor?.document.uri.toString() == uriString) {
compile([change.addedOrChanged]);
} else {
debouncedCompile(change.addedOrChanged);
}
}
})
// importFile handles any server errors
.catch(() => {});
Expand Down