Skip to content

Commit 3a3559a

Browse files
authored
Add command to flush NES caches (#280)
1 parent 009586b commit 3a3559a

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,11 @@
20502050
"title": "%github.copilot.command.collectDiagnostics%",
20512051
"category": "Developer"
20522052
},
2053+
{
2054+
"command": "github.copilot.debug.inlineEdit.clearCache",
2055+
"title": "%github.copilot.command.inlineEdit.clearCache%",
2056+
"category": "Developer"
2057+
},
20532058
{
20542059
"command": "github.copilot.debug.generateSTest",
20552060
"title": "%github.copilot.command.generateSTest%",
@@ -3850,4 +3855,4 @@
38503855
"string_decoder": "npm:[email protected]",
38513856
"node-gyp": "npm:[email protected]"
38523857
}
3853-
}
3858+
}

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"github.copilot.config.useProjectTemplates": "Use relevant GitHub projects as starter projects when using `/new`",
181181
"github.copilot.chat.attachSelection": "Add Selection to Chat",
182182
"github.copilot.command.collectDiagnostics": "GitHub Copilot Chat Diagnostics",
183+
"github.copilot.command.inlineEdit.clearCache": "GitHub Copilot Chat Clear Next Edit Cache",
183184
"github.copilot.command.showNotebookLog": "Show Chat Log Notebook",
184185
"github.copilot.resetAutomaticCommandExecutionPrompt": "Reset Automatic Command Execution Prompt",
185186
"github.copilot.command.generateSTest": "Generate STest From Last Chat Request",

src/extension/inlineEdits/common/rejectionCollector.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export class RejectionCollector extends Disposable {
6767
this._tracer.trace(`Checking rejection, ${isRejected ? 'rejected' : 'not rejected'}: ${e}`);
6868
return isRejected;
6969
}
70+
71+
public clear() {
72+
this._garbageCollector.clear();
73+
}
7074
}
7175

7276
class DocumentRejectionTracker {
@@ -147,10 +151,14 @@ class LRUGarbageCollector implements IDisposable {
147151
}
148152
}
149153

150-
dispose(): void {
154+
public clear(): void {
151155
for (const d of this._disposables) {
152156
d.dispose();
153157
}
154158
this._disposables = [];
155159
}
160+
161+
public dispose(): void {
162+
this.clear();
163+
}
156164
}

src/extension/inlineEdits/node/nextEditCache.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export class NextEditCache extends Disposable {
121121
docCache.evictedCachedEdit(cachedEdit);
122122
}
123123
}
124+
125+
public clear() {
126+
this._documentCaches.forEach(cache => cache.clear());
127+
this._sharedCache.clear();
128+
}
124129
}
125130

126131
class DocumentEditCache {
@@ -158,6 +163,10 @@ class DocumentEditCache {
158163
}
159164
}
160165

166+
public clear() {
167+
this._trackedCachedEdits.length = 0;
168+
}
169+
161170
public setKthNextEdit(documentContents: StringText, editWindow: OffsetRange | undefined, nextEdit: StringReplacement, nextEdits: StringReplacement[] | undefined, userEditSince: StringEdit | undefined, subsequentN: number, source: NextEditFetchRequest): CachedEdit {
162171
const key = this._getKey(documentContents.value);
163172
const cachedEdit: CachedEdit = { docId: this.docId, edit: nextEdit, edits: nextEdits, detailedEdits: [], userEditSince, subsequentN, source, documentBeforeEdit: documentContents, editWindow, cacheTime: Date.now() };

src/extension/inlineEdits/node/nextEditProvider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ export class NextEditProvider extends Disposable implements INextEditProvider<Ne
664664
}
665665
this._snippyService.handlePostInsertion(docId.toUri(), suggestion.result.documentBeforeEdits, suggestion.result.edit);
666666
}
667+
668+
public clearCache() {
669+
this._nextEditCache.clear();
670+
this._recentlyShownCache.clear();
671+
this._rejectionCollector.clear();
672+
}
667673
}
668674

669675
function assertDefined<T>(value: T | undefined): T {
@@ -704,6 +710,10 @@ class RecentlyShownCache {
704710
}
705711
}
706712

713+
clear() {
714+
this._cache.clear();
715+
}
716+
707717
private _key(docId: DocumentId, documentContent: StringText) {
708718
return docId.uri + ';' + documentContent.value;
709719
}

src/extension/inlineEdits/vscode-node/inlineEditProviderFeature.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ export class InlineEditProviderFeature extends Disposable implements IExtensionC
148148
reader.store.add(commands.registerCommand(learnMoreCommandId, () => {
149149
this._envService.openExternal(URI.parse(learnMoreLink));
150150
}));
151+
152+
reader.store.add(commands.registerCommand(clearCacheCommandId, () => {
153+
model.nextEditProvider.clearCache();
154+
}));
151155
}));
152156

153157
this._register(autorun(reader => {
@@ -165,3 +169,5 @@ export class InlineEditProviderFeature extends Disposable implements IExtensionC
165169
export const learnMoreCommandId = 'github.copilot.debug.inlineEdit.learnMore';
166170

167171
export const learnMoreLink = 'https://aka.ms/vscode-nes';
172+
173+
const clearCacheCommandId = 'github.copilot.debug.inlineEdit.clearCache';

0 commit comments

Comments
 (0)