rename verticalPerLineDiff to verticalDiff
This commit is contained in:
parent
6e5c475754
commit
14f936d629
10 changed files with 28 additions and 125 deletions
|
|
@ -25,7 +25,7 @@ import {
|
|||
} from "./autocomplete/statusBar";
|
||||
import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider";
|
||||
import { DiffManager } from "./diff/horizontal";
|
||||
import { VerticalPerLineDiffManager } from "./diff/verticalPerLine/manager";
|
||||
import { VerticalDiffManager } from "./diff/vertical/manager";
|
||||
import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick";
|
||||
import { Battery } from "./util/battery";
|
||||
import { EXTENSION_NAME } from "./util/constants";
|
||||
|
|
@ -172,7 +172,7 @@ const commandsMap: (
|
|||
sidebar: ContinueGUIWebviewViewProvider,
|
||||
configHandler: ConfigHandler,
|
||||
diffManager: DiffManager,
|
||||
verticalDiffManager: VerticalPerLineDiffManager,
|
||||
verticalDiffManager: VerticalDiffManager,
|
||||
continueServerClientPromise: Promise<ContinueServerClient>,
|
||||
battery: Battery,
|
||||
quickEdit: QuickEdit,
|
||||
|
|
@ -713,7 +713,7 @@ export function registerAllCommands(
|
|||
sidebar: ContinueGUIWebviewViewProvider,
|
||||
configHandler: ConfigHandler,
|
||||
diffManager: DiffManager,
|
||||
verticalDiffManager: VerticalPerLineDiffManager,
|
||||
verticalDiffManager: VerticalDiffManager,
|
||||
continueServerClientPromise: Promise<ContinueServerClient>,
|
||||
battery: Battery,
|
||||
quickEdit: QuickEdit,
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import {
|
|||
} from "./decorations";
|
||||
import type { VerticalDiffCodeLens } from "./manager";
|
||||
|
||||
export interface VerticalPerLineDiffHandlerOptions {
|
||||
export interface VerticalDiffHandlerOptions {
|
||||
input?: string;
|
||||
instant?: boolean;
|
||||
}
|
||||
|
||||
export class VerticalPerLineDiffHandler implements vscode.Disposable {
|
||||
export class VerticalDiffHandler implements vscode.Disposable {
|
||||
private editor: vscode.TextEditor;
|
||||
private startLine: number;
|
||||
private endLine: number;
|
||||
|
|
@ -29,7 +29,7 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable {
|
|||
|
||||
private newLinesAdded = 0;
|
||||
|
||||
public options: VerticalPerLineDiffHandlerOptions;
|
||||
public options: VerticalDiffHandlerOptions;
|
||||
|
||||
constructor(
|
||||
startLine: number,
|
||||
|
|
@ -44,7 +44,7 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable {
|
|||
accept: boolean,
|
||||
) => void,
|
||||
private readonly refreshCodeLens: () => void,
|
||||
options: VerticalPerLineDiffHandlerOptions,
|
||||
options: VerticalDiffHandlerOptions,
|
||||
) {
|
||||
this.currentLineIndex = startLine;
|
||||
this.startLine = startLine;
|
||||
|
|
@ -5,10 +5,7 @@ import { getMarkdownLanguageTagForFile } from "core/util";
|
|||
import { DiffLine } from "core";
|
||||
import { streamDiffLines } from "core/edit/streamDiffLines";
|
||||
import * as vscode from "vscode";
|
||||
import {
|
||||
VerticalPerLineDiffHandler,
|
||||
VerticalPerLineDiffHandlerOptions,
|
||||
} from "./handler";
|
||||
import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler";
|
||||
|
||||
export interface VerticalDiffCodeLens {
|
||||
start: number;
|
||||
|
|
@ -16,11 +13,10 @@ export interface VerticalDiffCodeLens {
|
|||
numGreen: number;
|
||||
}
|
||||
|
||||
export class VerticalPerLineDiffManager {
|
||||
export class VerticalDiffManager {
|
||||
public refreshCodeLens: () => void = () => {};
|
||||
|
||||
private filepathToHandler: Map<string, VerticalPerLineDiffHandler> =
|
||||
new Map();
|
||||
private filepathToHandler: Map<string, VerticalDiffHandler> = new Map();
|
||||
|
||||
filepathToCodeLens: Map<string, VerticalDiffCodeLens[]> = new Map();
|
||||
|
||||
|
|
@ -30,11 +26,11 @@ export class VerticalPerLineDiffManager {
|
|||
this.userChangeListener = undefined;
|
||||
}
|
||||
|
||||
createVerticalPerLineDiffHandler(
|
||||
createVerticalDiffHandler(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number,
|
||||
options: VerticalPerLineDiffHandlerOptions,
|
||||
options: VerticalDiffHandlerOptions,
|
||||
) {
|
||||
if (this.filepathToHandler.has(filepath)) {
|
||||
this.filepathToHandler.get(filepath)?.clear(false);
|
||||
|
|
@ -42,7 +38,7 @@ export class VerticalPerLineDiffManager {
|
|||
}
|
||||
const editor = vscode.window.activeTextEditor; // TODO
|
||||
if (editor && editor.document.uri.fsPath === filepath) {
|
||||
const handler = new VerticalPerLineDiffHandler(
|
||||
const handler = new VerticalDiffHandler(
|
||||
startLine,
|
||||
endLine,
|
||||
editor,
|
||||
|
|
@ -92,7 +88,7 @@ export class VerticalPerLineDiffManager {
|
|||
|
||||
private handleDocumentChange(
|
||||
event: vscode.TextDocumentChangeEvent,
|
||||
handler: VerticalPerLineDiffHandler,
|
||||
handler: VerticalDiffHandler,
|
||||
) {
|
||||
// Loop through each change in the event
|
||||
event.contentChanges.forEach((change) => {
|
||||
|
|
@ -203,7 +199,7 @@ export class VerticalPerLineDiffManager {
|
|||
});
|
||||
|
||||
// Create new handler with determined start/end
|
||||
const diffHandler = this.createVerticalPerLineDiffHandler(
|
||||
const diffHandler = this.createVerticalDiffHandler(
|
||||
filepath,
|
||||
startLine,
|
||||
endLine,
|
||||
|
|
@ -339,7 +335,7 @@ export class VerticalPerLineDiffManager {
|
|||
});
|
||||
|
||||
// Create new handler with determined start/end
|
||||
const diffHandler = this.createVerticalPerLineDiffHandler(
|
||||
const diffHandler = this.createVerticalDiffHandler(
|
||||
filepath,
|
||||
startLine,
|
||||
endLine,
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
import { matchLine } from "core/diff/util";
|
||||
|
||||
interface DiffBlock {
|
||||
startLine: number;
|
||||
endLine: number;
|
||||
replacement: string[];
|
||||
}
|
||||
|
||||
interface LineUpdate {
|
||||
content: string;
|
||||
line: number;
|
||||
replace: boolean;
|
||||
}
|
||||
|
||||
type DiffEvent = LineUpdate | DiffBlock;
|
||||
|
||||
/**
|
||||
* Returns a stream of characters, but with "undefined" inserted into the stream whenever there is a new line
|
||||
*/
|
||||
async function* streamWithLineBreaks(
|
||||
completionStream: AsyncGenerator<string>,
|
||||
): AsyncGenerator<string | undefined> {
|
||||
for await (const chunk of completionStream) {
|
||||
if (chunk.includes("\n")) {
|
||||
const lines = chunk.split("\n");
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
yield lines[i];
|
||||
if (i < lines.length - 1) {
|
||||
yield undefined;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
yield chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function* streamDiffEvents(
|
||||
completionStream: AsyncGenerator<string>,
|
||||
oldCode: string,
|
||||
): AsyncGenerator<DiffEvent> {
|
||||
const remainingLines = oldCode.split("\n");
|
||||
let i = 0;
|
||||
let oldLine = remainingLines.shift();
|
||||
let newLine = "";
|
||||
let alreadyReplacedCurrentLine = false;
|
||||
|
||||
for await (const chunk of streamWithLineBreaks(completionStream)) {
|
||||
if (chunk === undefined) {
|
||||
// Decide whether there is a match
|
||||
const matchIndex = matchLine(newLine, remainingLines);
|
||||
// Delete all of the lines in the middle
|
||||
// TODO
|
||||
|
||||
// Start a new line
|
||||
oldLine = remainingLines.shift();
|
||||
newLine = "";
|
||||
alreadyReplacedCurrentLine = false;
|
||||
i++;
|
||||
} else {
|
||||
// Continue current line
|
||||
newLine += chunk;
|
||||
|
||||
if (oldLine?.startsWith(newLine)) {
|
||||
// Match, do nothing
|
||||
} else {
|
||||
// Difference, send the update
|
||||
// This also handles when we are past all of the oldLines
|
||||
if (alreadyReplacedCurrentLine) {
|
||||
yield {
|
||||
content: chunk,
|
||||
line: i,
|
||||
replace: false,
|
||||
};
|
||||
} else {
|
||||
yield {
|
||||
content: newLine,
|
||||
line: i,
|
||||
replace: true,
|
||||
};
|
||||
alreadyReplacedCurrentLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// But you also want to stream between the diff blocks.
|
||||
// So...not only do you want to stream DiffBlocks
|
||||
// Next is stream lines: {line: string, type: "match" | ""}
|
||||
|
|
@ -16,7 +16,7 @@ import {
|
|||
import { registerAllCommands } from "../commands";
|
||||
import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
|
||||
import { DiffManager } from "../diff/horizontal";
|
||||
import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import { registerAllCodeLensProviders } from "../lang-server/codeLens";
|
||||
import { QuickEdit } from "../quickEdit/QuickEditQuickPick";
|
||||
import { setupRemoteConfigSync } from "../stubs/activation";
|
||||
|
|
@ -41,7 +41,7 @@ export class VsCodeExtension {
|
|||
private sidebar: ContinueGUIWebviewViewProvider;
|
||||
private windowId: string;
|
||||
private diffManager: DiffManager;
|
||||
private verticalDiffManager: VerticalPerLineDiffManager;
|
||||
private verticalDiffManager: VerticalDiffManager;
|
||||
webviewProtocolPromise: Promise<VsCodeWebviewProtocol>;
|
||||
private core: Core;
|
||||
private battery: Battery;
|
||||
|
|
@ -66,7 +66,7 @@ export class VsCodeExtension {
|
|||
|
||||
// Dependencies of core
|
||||
let resolveVerticalDiffManager: any = undefined;
|
||||
const verticalDiffManagerPromise = new Promise<VerticalPerLineDiffManager>(
|
||||
const verticalDiffManagerPromise = new Promise<VerticalDiffManager>(
|
||||
(resolve) => {
|
||||
resolveVerticalDiffManager = resolve;
|
||||
},
|
||||
|
|
@ -124,9 +124,7 @@ export class VsCodeExtension {
|
|||
resolveConfigHandler?.(this.configHandler);
|
||||
|
||||
this.configHandler.reloadConfig();
|
||||
this.verticalDiffManager = new VerticalPerLineDiffManager(
|
||||
this.configHandler,
|
||||
);
|
||||
this.verticalDiffManager = new VerticalDiffManager(this.configHandler);
|
||||
resolveVerticalDiffManager?.(this.verticalDiffManager);
|
||||
this.tabAutocompleteModel = new TabAutocompleteModel(this.configHandler);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ILLM } from "core";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock";
|
||||
import {
|
||||
FromCoreProtocol,
|
||||
|
|
@ -19,7 +19,7 @@ import { getConfigJsonPath } from "core/util/paths";
|
|||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import * as vscode from "vscode";
|
||||
import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import {
|
||||
getControlPlaneSessionInfo,
|
||||
WorkOsAuthProvider,
|
||||
|
|
@ -27,7 +27,6 @@ import {
|
|||
import { getExtensionUri } from "../util/vscode";
|
||||
import { VsCodeIde } from "../VsCodeIde";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
|
||||
/**
|
||||
* A shared messenger class between Core and Webview
|
||||
|
|
@ -76,7 +75,7 @@ export class VsCodeMessenger {
|
|||
>,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
private readonly ide: VsCodeIde,
|
||||
private readonly verticalDiffManagerPromise: Promise<VerticalPerLineDiffManager>,
|
||||
private readonly verticalDiffManagerPromise: Promise<VerticalDiffManager>,
|
||||
private readonly configHandlerPromise: Promise<ConfigHandler>,
|
||||
private readonly workOsAuthProvider: WorkOsAuthProvider,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as vscode from "vscode";
|
||||
import { VerticalDiffCodeLens } from "../../../diff/verticalPerLine/manager";
|
||||
import { VerticalDiffCodeLens } from "../../../diff/vertical/manager";
|
||||
import { getAltOrOption, getMetaKeyLabel } from "../../../util/util";
|
||||
|
||||
export class VerticalPerLineCodeLensProvider
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ContinueConfig } from "core";
|
||||
import * as vscode from "vscode";
|
||||
import { DiffManager } from "../../diff/horizontal";
|
||||
import { VerticalDiffCodeLens } from "../../diff/verticalPerLine/manager";
|
||||
import { VerticalDiffCodeLens } from "../../diff/vertical/manager";
|
||||
import * as providers from "./providers";
|
||||
import {
|
||||
getQuickActionsConfig,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { IDE } from "core";
|
|||
import { walkDir } from "core/indexing/walkDir";
|
||||
import { Telemetry } from "core/util/posthog";
|
||||
import * as vscode from "vscode";
|
||||
import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
import { getContextProviderQuickPickVal } from "./ContextProvidersQuickPick";
|
||||
import { appendToHistory, getHistoryQuickPickVal } from "./HistoryQuickPick";
|
||||
|
|
@ -12,8 +12,8 @@ import { getModelQuickPickVal } from "./ModelSelectionQuickPick";
|
|||
// @ts-ignore - error finding typings
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
// @ts-ignore
|
||||
import MiniSearch from "minisearch";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
import MiniSearch from "minisearch";
|
||||
|
||||
/**
|
||||
* Used to track what action to take after a user interacts
|
||||
|
|
@ -86,7 +86,7 @@ export class QuickEdit {
|
|||
private _curModelTitle?: string;
|
||||
|
||||
constructor(
|
||||
private readonly verticalDiffManager: VerticalPerLineDiffManager,
|
||||
private readonly verticalDiffManager: VerticalDiffManager,
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
private readonly ide: IDE,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue