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: cache completion item to avoid jitter (#6946)

Myles Scolnick1c7ffd1d7a76
diff --git a/frontend/src/core/codemirror/lsp/notebook-lsp.ts b/frontend/src/core/codemirror/lsp/notebook-lsp.ts
index 86377f9f31..a24a1fcae9 100644
--- a/frontend/src/core/codemirror/lsp/notebook-lsp.ts
+++ b/frontend/src/core/codemirror/lsp/notebook-lsp.ts
@@ -102,6 +102,14 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
private static readonly SEEN_CELL_DOCUMENT_URIS = new Set<CellDocumentUri>();
+ /**
+ * Cache of completion items to avoid jitter while typing in the same completion item
+ */
+ private readonly completionItemCache = new LRUCache<
+ string,
+ Promise<LSP.CompletionItem>
+ >(10);
+
constructor(
client: ILanguageServerClient,
initialSettings: Record<string, unknown>,
@@ -428,10 +436,19 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
};
}
- completionItemResolve(
+ async completionItemResolve(
params: LSP.CompletionItem,
): Promise<LSP.CompletionItem> {
- return this.client.completionItemResolve(params);
+ // Used cached result to avoid jitter while typing in the same completion item
+ const key = JSON.stringify(params);
+ const cached = this.completionItemCache.get(key);
+ if (cached) {
+ return cached;
+ }
+
+ const resolved = this.client.completionItemResolve(params);
+ this.completionItemCache.set(key, resolved);
+ return resolved;
}
async textDocumentPrepareRename(