Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: improve copilot debounce logic (#2249)

Myles Scolnick176c1dd2e704
diff --git a/frontend/src/core/codemirror/copilot/language-server.ts b/frontend/src/core/codemirror/copilot/language-server.ts
index dd85728868..a0611032b4 100644
--- a/frontend/src/core/codemirror/copilot/language-server.ts
+++ b/frontend/src/core/codemirror/copilot/language-server.ts
@@ -137,21 +137,12 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
params: CopilotGetCompletionsParams,
version: number,
): Promise<CopilotGetCompletionsResult> {
- // Start a loading indicator
- setGitHubCopilotLoadingVersion(version);
const response = await this._request("getCompletions", {
doc: {
...params.doc,
version: version,
},
});
- // Stop the loading indicator (only if the version hasn't changed)
- clearGitHubCopilotLoadingVersion(version);
-
- // If the document version has changed since the request was made, return an empty response
- if (version !== this.documentVersion) {
- return { completions: [] };
- }
return response;
}
@@ -159,9 +150,10 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
// Even though the copilot extension has a debounce,
// there are multiple requests sent at the same time
// when multiple Codemirror instances are mounted at the same time.
+ // So we only need to debounce around 10ms.
private debouncedGetCompletionInternal = debounce(
this.getCompletionInternal.bind(this),
- 300,
+ 10,
);
async getCompletion(
@@ -178,7 +170,17 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
return { completions: [] };
}
+ // Start a loading indicator
+ setGitHubCopilotLoadingVersion(version);
const response = await this.debouncedGetCompletionInternal(params, version);
+ // Stop the loading indicator (only if the version hasn't changed)
+ clearGitHubCopilotLoadingVersion(version);
+
+ // If the document version has changed since the request was made, return an empty response
+ if (version !== this.documentVersion) {
+ return { completions: [] };
+ }
+
return response || { completions: [] };
}
}