Skip to content

Commit

Permalink
perf(typescript): try to insert new requests as needed before complet…
Browse files Browse the repository at this point in the history
…ing all CDN file requests
  • Loading branch information
johnsoncodehk committed Jul 2, 2024
1 parent 8ec3487 commit 723b7c3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/typescript/lib/plugins/semantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,16 +997,35 @@ export function create(
async function isCancellationRequestedWhileSync(token: CancellationToken) {
if (sys.sync) {
let oldSysVersion: number | undefined;
let newSysVersion = await sys.sync();
let newSysVersion = sys.version;
do {
oldSysVersion = newSysVersion;
languageService.getProgram(); // trigger sync
newSysVersion = await sys.sync();
languageService.getProgram(); // trigger file requests
newSysVersion = await aggressiveSync(sys.sync);
} while (newSysVersion !== oldSysVersion && !token.isCancellationRequested);
}
return token.isCancellationRequested;
}

async function aggressiveSync(fn: () => Promise<number>) {
const promise = fn();
let newVersion: number | undefined;
let syncing = true;
promise.then(version => {
newVersion = version;
syncing = false;
});
while (syncing) {
languageService.getProgram(); // trigger file requests when sending requests
await Promise.race([promise, sleep(10)]);
}
return newVersion;
}

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

function getVirtualScriptByUri(uri: URI): {
fileName: string;
code: VirtualCode;
Expand Down

0 comments on commit 723b7c3

Please sign in to comment.