refactor: initialize usingFullFileDiff once
This commit is contained in:
parent
a49e8cbbd5
commit
bdcfa85df1
6 changed files with 57 additions and 35 deletions
|
|
@ -603,7 +603,7 @@ export class Core {
|
|||
const outcome = await this.nextEditProvider.provideInlineCompletionItems(
|
||||
msg.data,
|
||||
undefined,
|
||||
{ withChain: false, fullFileDiff: true },
|
||||
{ withChain: false, usingFullFileDiff: true },
|
||||
);
|
||||
return outcome ? [outcome.completion, outcome.originalEditableRange] : [];
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ export class PrefetchQueue {
|
|||
private prefetchLimit: number;
|
||||
private abortController: AbortController;
|
||||
|
||||
private usingFullFileDiff: boolean = true;
|
||||
|
||||
private constructor(prefetchLimit: number = 3) {
|
||||
this.prefetchLimit = prefetchLimit;
|
||||
this.abortController = new AbortController();
|
||||
|
|
@ -28,6 +30,10 @@ export class PrefetchQueue {
|
|||
return PrefetchQueue.instance;
|
||||
}
|
||||
|
||||
initialize(usingFullFileDiff: boolean) {
|
||||
this.usingFullFileDiff = usingFullFileDiff;
|
||||
}
|
||||
|
||||
// Queue management methods
|
||||
enqueueUnprocessed(location: RangeInFile): void {
|
||||
this.unprocessedQueue.push(location);
|
||||
|
|
@ -61,7 +67,7 @@ export class PrefetchQueue {
|
|||
ctx,
|
||||
location,
|
||||
this.abortController.signal,
|
||||
true,
|
||||
this.usingFullFileDiff,
|
||||
);
|
||||
|
||||
if (!outcome) continue;
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ export class NextEditProvider {
|
|||
token: AbortSignal | undefined,
|
||||
opts?: {
|
||||
withChain: boolean;
|
||||
fullFileDiff: boolean;
|
||||
usingFullFileDiff: boolean;
|
||||
},
|
||||
): Promise<NextEditOutcome | undefined> {
|
||||
try {
|
||||
|
|
@ -316,11 +316,11 @@ export class NextEditProvider {
|
|||
this.ide.getWorkspaceDirs(),
|
||||
]);
|
||||
|
||||
const editableRegionStartLine = opts?.fullFileDiff
|
||||
const editableRegionStartLine = opts?.usingFullFileDiff
|
||||
? 0
|
||||
: Math.max(helper.pos.line - NEXT_EDIT_EDITABLE_REGION_TOP_MARGIN, 0);
|
||||
|
||||
const editableRegionEndLine = opts?.fullFileDiff
|
||||
const editableRegionEndLine = opts?.usingFullFileDiff
|
||||
? helper.fileLines.length - 1
|
||||
: Math.min(
|
||||
helper.pos.line + NEXT_EDIT_EDITABLE_REGION_BOTTOM_MARGIN,
|
||||
|
|
@ -465,7 +465,7 @@ export class NextEditProvider {
|
|||
|
||||
// console.log("metadata:", msg.content, prompts[0]);
|
||||
|
||||
if (opts?.fullFileDiff === false || !opts?.fullFileDiff) {
|
||||
if (opts?.usingFullFileDiff === false || !opts?.usingFullFileDiff) {
|
||||
const currCursorPos = helper.pos;
|
||||
|
||||
const editableRegionStartLine = Math.max(
|
||||
|
|
@ -749,7 +749,7 @@ export class NextEditProvider {
|
|||
},
|
||||
nextEditLocation: RangeInFile,
|
||||
token: AbortSignal | undefined,
|
||||
fullFileDiff: boolean,
|
||||
usingFullFileDiff: boolean,
|
||||
) {
|
||||
try {
|
||||
const previousOutcome = this.getPreviousCompletion();
|
||||
|
|
@ -769,7 +769,7 @@ export class NextEditProvider {
|
|||
|
||||
return await this.provideInlineCompletionItems(input, token, {
|
||||
withChain: true,
|
||||
fullFileDiff,
|
||||
usingFullFileDiff,
|
||||
});
|
||||
} catch (e: any) {
|
||||
this.onError(e);
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ export class SelectionChangeManager {
|
|||
private static instance: SelectionChangeManager;
|
||||
private listeners: HandlerRegistration[] = [];
|
||||
private ide: VsCodeIde | null = null;
|
||||
private usingFullFileDiff: boolean = true;
|
||||
|
||||
// Event bus-related attributes.
|
||||
private eventQueue: vscode.TextEditorSelectionChangeEvent[] = [];
|
||||
|
|
@ -137,8 +138,9 @@ export class SelectionChangeManager {
|
|||
return SelectionChangeManager.instance;
|
||||
}
|
||||
|
||||
public initialize(ide: VsCodeIde): void {
|
||||
public initialize(ide: VsCodeIde, usingFullFileDiff: boolean): void {
|
||||
this.ide = ide;
|
||||
this.usingFullFileDiff = usingFullFileDiff;
|
||||
|
||||
// After handling all other listeners, this will delete the chain.
|
||||
this.registerListener(
|
||||
|
|
@ -323,20 +325,22 @@ export class SelectionChangeManager {
|
|||
);
|
||||
await NextEditProvider.getInstance().deleteChain();
|
||||
|
||||
const nextEditableRegions =
|
||||
// (await getNextEditableRegion(EditableRegionStrategy.Static, {
|
||||
// cursorPosition: e.selections[0].anchor,
|
||||
if (!this.usingFullFileDiff) {
|
||||
const nextEditableRegions =
|
||||
(await getNextEditableRegion(EditableRegionStrategy.Static, {
|
||||
cursorPosition: e.selections[0].anchor,
|
||||
filepath: localPathOrUriToPath(e.textEditor.document.uri.toString()),
|
||||
ide: this.ide,
|
||||
})) ?? [];
|
||||
// (await getNextEditableRegion(EditableRegionStrategy.Sliding, {
|
||||
// filepath: localPathOrUriToPath(e.textEditor.document.uri.toString()),
|
||||
// ide: this.ide,
|
||||
// fileLines: e.textEditor.document.getText().split("\n"),
|
||||
// })) ?? [];
|
||||
(await getNextEditableRegion(EditableRegionStrategy.Sliding, {
|
||||
filepath: localPathOrUriToPath(e.textEditor.document.uri.toString()),
|
||||
fileLines: e.textEditor.document.getText().split("\n"),
|
||||
})) ?? [];
|
||||
|
||||
nextEditableRegions.forEach((region) => {
|
||||
PrefetchQueue.getInstance().enqueueUnprocessed(region);
|
||||
});
|
||||
nextEditableRegions.forEach((region) => {
|
||||
PrefetchQueue.getInstance().enqueueUnprocessed(region);
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ export class ContinueCompletionProvider
|
|||
public recentlyEditedTracker: RecentlyEditedTracker;
|
||||
|
||||
private isNextEditActive: boolean = false;
|
||||
private usingFullFileDiff: boolean = true;
|
||||
|
||||
public activateNextEdit() {
|
||||
this.isNextEditActive = true;
|
||||
|
|
@ -83,7 +84,9 @@ export class ContinueCompletionProvider
|
|||
private readonly configHandler: ConfigHandler,
|
||||
private readonly ide: VsCodeIde,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
usingFullFileDiff: boolean,
|
||||
) {
|
||||
this.usingFullFileDiff = usingFullFileDiff;
|
||||
this.recentlyEditedTracker = new RecentlyEditedTracker(ide.ideUtils);
|
||||
|
||||
async function getAutocompleteModel() {
|
||||
|
|
@ -115,6 +118,7 @@ export class ContinueCompletionProvider
|
|||
|
||||
this.jumpManager = JumpManager.getInstance();
|
||||
this.prefetchQueue = PrefetchQueue.getInstance();
|
||||
this.prefetchQueue.initialize(this.usingFullFileDiff);
|
||||
|
||||
this.recentlyVisitedRanges = new RecentlyVisitedRangesService(ide);
|
||||
}
|
||||
|
|
@ -291,12 +295,14 @@ export class ContinueCompletionProvider
|
|||
outcome = this.prefetchQueue.dequeueProcessed()?.outcome;
|
||||
|
||||
// Fill in the spot after dequeuing.
|
||||
// this.prefetchQueue.process({
|
||||
// ...ctx,
|
||||
// recentlyVisitedRanges: this.recentlyVisitedRanges.getSnippets(),
|
||||
// recentlyEditedRanges:
|
||||
// await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
// });
|
||||
if (!this.usingFullFileDiff) {
|
||||
this.prefetchQueue.process({
|
||||
...ctx,
|
||||
recentlyVisitedRanges: this.recentlyVisitedRanges.getSnippets(),
|
||||
recentlyEditedRanges:
|
||||
await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (chainExists) {
|
||||
// Case 3: Accepting next edit outcome (chain exists, jump is not taken).
|
||||
|
|
@ -310,12 +316,14 @@ export class ContinueCompletionProvider
|
|||
if (!nextItemInQueue) continue;
|
||||
|
||||
// Fill in the spot after dequeuing.
|
||||
// this.prefetchQueue.process({
|
||||
// ...ctx,
|
||||
// recentlyVisitedRanges: this.recentlyVisitedRanges.getSnippets(),
|
||||
// recentlyEditedRanges:
|
||||
// await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
// });
|
||||
if (!this.usingFullFileDiff) {
|
||||
this.prefetchQueue.process({
|
||||
...ctx,
|
||||
recentlyVisitedRanges: this.recentlyVisitedRanges.getSnippets(),
|
||||
recentlyEditedRanges:
|
||||
await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
});
|
||||
}
|
||||
|
||||
const nextLocation = nextItemInQueue.location;
|
||||
outcome = nextItemInQueue.outcome;
|
||||
|
|
@ -370,12 +378,14 @@ export class ContinueCompletionProvider
|
|||
outcome = await this.nextEditProvider.provideInlineCompletionItems(
|
||||
input,
|
||||
signal,
|
||||
{ withChain: false, fullFileDiff: true },
|
||||
{ withChain: false, usingFullFileDiff: this.usingFullFileDiff },
|
||||
);
|
||||
|
||||
// Start prefetching next edits.
|
||||
// NOTE: this might be better off not awaited.
|
||||
// this.prefetchQueue.process(ctx);
|
||||
if (!this.usingFullFileDiff) {
|
||||
this.prefetchQueue.process(ctx);
|
||||
}
|
||||
|
||||
// If initial outcome is null, suggest a jump instead.
|
||||
// Calling this method again will call it with
|
||||
|
|
|
|||
|
|
@ -101,8 +101,9 @@ export class VsCodeExtension {
|
|||
this.extensionContext = context;
|
||||
this.windowId = uuidv4();
|
||||
|
||||
const usingFullFileDiff = true;
|
||||
const selectionManager = SelectionChangeManager.getInstance();
|
||||
selectionManager.initialize(this.ide);
|
||||
selectionManager.initialize(this.ide, usingFullFileDiff);
|
||||
|
||||
selectionManager.registerListener(
|
||||
"typing",
|
||||
|
|
@ -254,6 +255,7 @@ export class VsCodeExtension {
|
|||
this.configHandler,
|
||||
this.ide,
|
||||
this.sidebar.webviewProtocol,
|
||||
usingFullFileDiff,
|
||||
);
|
||||
context.subscriptions.push(
|
||||
vscode.languages.registerInlineCompletionItemProvider(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue