From 666d37ff522b579aee03f55bba9063768305cef5 Mon Sep 17 00:00:00 2001 From: vodkaslime <646329483@qq.com> Date: Fri, 12 May 2023 23:10:57 +0800 Subject: [PATCH] small fix for completion cache (#130) --- clients/vscode/src/CompletionCache.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/clients/vscode/src/CompletionCache.ts b/clients/vscode/src/CompletionCache.ts index 027875f..d23df49 100644 --- a/clients/vscode/src/CompletionCache.ts +++ b/clients/vscode/src/CompletionCache.ts @@ -14,25 +14,23 @@ export type CompletionCacheEntry = { }; export class CompletionCache { - public static cacheSize = 10; + public static capacity = 10; private cache = new LinkedList(); constructor() {} - private evict() { - while (this.cache.length > CompletionCache.cacheSize) { - this.cache.removeTail(); - } - } - - private pop(entry: CompletionCacheEntry) { + private refresh(entry: CompletionCacheEntry) { this.cache.remove(entry); this.cache.prepend(entry); } public add(entry: CompletionCacheEntry) { - this.evict(); this.cache.prepend(entry); + + while (this.cache.length > CompletionCache.capacity) { + this.cache.removeTail(); + } + } public findCompatible(documentId: any, text: string, cursor: number): CompletionResponse | null { @@ -63,7 +61,7 @@ export class CompletionCache { } } if (hit) { - this.pop(hit.entry); + this.refresh(hit.entry); return { id: hit.entry.completion.id, created: hit.entry.completion.created,