path -> ide part 243243

This commit is contained in:
Dallin Romney 2024-12-10 20:34:21 -08:00
parent 2225d0d702
commit ddfcefa036
8 changed files with 28 additions and 49 deletions

View file

@ -6,25 +6,25 @@ describe("shouldChunk", () => {
test("should chunk a typescript file", () => {
const filePath = path.join("directory", "file.ts");
const fileContent = generateString(10000);
expect(shouldChunk(path.sep, filePath, fileContent)).toBe(true);
expect(shouldChunk(filePath, fileContent)).toBe(true);
});
test("should not chunk a large typescript file", () => {
const filePath = path.join("directory", "file.ts");
const fileContent = generateString(1500000);
expect(shouldChunk(path.sep, filePath, fileContent)).toBe(false);
expect(shouldChunk(filePath, fileContent)).toBe(false);
});
test("should not chunk an empty file", () => {
const filePath = path.join("directory", "file.ts");
const fileContent = generateString(0);
expect(shouldChunk(path.sep, filePath, fileContent)).toBe(false);
expect(shouldChunk(filePath, fileContent)).toBe(false);
});
test("should not chunk a file without extension", () => {
const filePath = path.join("directory", "with.dot", "filename");
const fileContent = generateString(10000);
expect(shouldChunk(path.sep, filePath, fileContent)).toBe(false);
expect(shouldChunk(filePath, fileContent)).toBe(false);
});
});

View file

@ -3,7 +3,7 @@ import { countTokensAsync } from "../../llm/countTokens.js";
import { extractMinimalStackTraceInfo } from "../../util/extractMinimalStackTraceInfo.js";
import { Telemetry } from "../../util/posthog.js";
import { supportedLanguages } from "../../util/treeSitter.js";
import { getUriPathBasename } from "../../util/uri.js";
import { getUriFileExtension, getUriPathBasename } from "../../util/uri.js";
import { basicChunker } from "./basic.js";
import { codeChunker } from "./code.js";
@ -16,25 +16,23 @@ export type ChunkDocumentParam = {
};
async function* chunkDocumentWithoutId(
filepath: string,
fileUri: string,
contents: string,
maxChunkSize: number,
): AsyncGenerator<ChunkWithoutID> {
if (contents.trim() === "") {
return;
}
const segs = filepath.split(".");
const ext = segs[segs.length - 1];
if (ext in supportedLanguages) {
const extension = getUriFileExtension(fileUri);
if (extension in supportedLanguages) {
try {
for await (const chunk of codeChunker(filepath, contents, maxChunkSize)) {
for await (const chunk of codeChunker(fileUri, contents, maxChunkSize)) {
yield chunk;
}
return;
} catch (e: any) {
Telemetry.capture("code_chunker_error", {
fileExtension: ext,
void Telemetry.capture("code_chunker_error", {
fileExtension: extension,
stack: extractMinimalStackTraceInfo(e.stack),
});
// falls back to basicChunker

View file

@ -23,9 +23,6 @@ export class RecentlyEditedTracker {
constructor() {
vscode.workspace.onDidChangeTextDocument((event) => {
if (event.document.uri.scheme !== "file") {
return;
}
event.contentChanges.forEach((change) => {
const editedRange = {
uri: event.document.uri,
@ -123,7 +120,7 @@ export class RecentlyEditedTracker {
return this.recentlyEditedRanges.map((entry) => {
return {
...entry,
filepath: entry.uri.fsPath,
filepath: entry.uri.toString(),
};
});
}
@ -140,7 +137,7 @@ export class RecentlyEditedTracker {
const lines = contents.split("\n");
return {
filepath: entry.uri.fsPath,
filepath: entry.uri.toString(),
contents,
range: {
start: { line: 0, character: 0 },

View file

@ -32,7 +32,6 @@ import { VerticalDiffManager } from "./diff/vertical/manager";
import EditDecorationManager from "./quickEdit/EditDecorationManager";
import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick";
import { Battery } from "./util/battery";
import { getFullyQualifiedPath } from "./util/util";
import { VsCodeIde } from "./VsCodeIde";
import type { VsCodeWebviewProtocol } from "./webviewProtocol";
@ -231,7 +230,7 @@ async function processDiff(
diffManager: DiffManager,
ide: VsCodeIde,
verticalDiffManager: VerticalDiffManager,
newFilepath?: string | vscode.Uri,
newFilepath?: vscode.Uri,
streamId?: string,
) {
captureCommandTelemetry(`${action}Diff`);
@ -241,7 +240,7 @@ async function processDiff(
if (fullPath instanceof vscode.Uri) {
fullPath = fullPath.fsPath;
} else if (fullPath) {
fullPath = getFullyQualifiedPath(ide, fullPath);
fullPath = resolveF(ide, fullPath);
} else {
const curFile = await ide.getCurrentFile();
fullPath = curFile?.path;

View file

@ -16,7 +16,6 @@ import {
CORE_TO_WEBVIEW_PASS_THROUGH,
WEBVIEW_TO_CORE_PASS_THROUGH,
} from "core/protocol/passThrough";
import { getBasename } from "core/util";
import { InProcessMessenger, Message } from "core/protocol/messenger";
import * as vscode from "vscode";
@ -27,10 +26,10 @@ import {
getControlPlaneSessionInfo,
WorkOsAuthProvider,
} from "../stubs/WorkOsAuthProvider";
import { getFullyQualifiedPath } from "../util/util";
import { getExtensionUri } from "../util/vscode";
import { VsCodeIde } from "../VsCodeIde";
import { VsCodeWebviewProtocol } from "../webviewProtocol";
import { getUriPathBasename } from "core/util/uri";
/**
* A shared messenger class between Core and Webview
@ -246,7 +245,7 @@ export class VsCodeMessenger {
const [instant, diffLines] = await applyCodeBlock(
editor.document.getText(),
data.text,
getBasename(editor.document.fileName),
getUriPathBasename(editor.document.uri.toString()),
llm,
fastLlm,
);

View file

@ -17,7 +17,6 @@ import { getModelQuickPickVal } from "./ModelSelectionQuickPick";
// @ts-ignore - error finding typings
// @ts-ignore
/**
* Used to track what action to take after a user interacts
* with the initial Quick Pick
@ -133,11 +132,11 @@ export class QuickEdit {
}
const hasChanges = !!this.verticalDiffManager.getHandlerForFile(
editor.document.uri.fsPath,
editor.document.uri.toString(),
);
if (hasChanges) {
this.openAcceptRejectMenu("", editor.document.uri.fsPath);
this.openAcceptRejectMenu("", editor.document.uri.toString());
} else {
await this.initiateNewQuickPick(editor, params);
}
@ -185,7 +184,7 @@ export class QuickEdit {
});
if (prompt) {
await this.handleUserPrompt(prompt, editor.document.uri.fsPath);
await this.handleUserPrompt(prompt, editor.document.uri.toString());
}
}

View file

@ -10,6 +10,9 @@ import { testWorkspacePath } from "../runner/runTestOnVSCodeHost";
const util = require("node:util");
const asyncExec = util.promisify(require("node:child_process").exec);
/*
TODO check uri => path assumptions, will only work in some environments.
*/
describe("IDE Utils", () => {
const utils = new VsCodeIdeUtils();
const testPyPath = path.join(testWorkspacePath, "test.py");
@ -17,22 +20,16 @@ describe("IDE Utils", () => {
test("getWorkspaceDirectories", async () => {
const [dir] = utils.getWorkspaceDirectories();
assert(dir.endsWith("test-workspace"));
assert(dir.toString().endsWith("test-workspace"));
});
test("fileExists", async () => {
const exists2 = await utils.fileExists(
path.join(testWorkspacePath, "test.py"),
vscode.Uri.file(path.join(testWorkspacePath, "test.py")),
);
assert(exists2);
});
test("getAbsolutePath", async () => {
const groundTruth = path.join(testWorkspacePath, "test.py");
assert(utils.getAbsolutePath("test.py") === groundTruth);
assert(utils.getAbsolutePath(groundTruth) === groundTruth);
});
test("getOpenFiles", async () => {
let openFiles = utils.getOpenFiles();
assert(openFiles.length === 0);
@ -43,7 +40,7 @@ describe("IDE Utils", () => {
});
openFiles = utils.getOpenFiles();
assert(openFiles.length === 1);
assert(openFiles[0] === testPyPath);
assert(openFiles[0].fsPath === testPyPath);
document = await vscode.workspace.openTextDocument(testJsPath);
await vscode.window.showTextDocument(document, {
@ -51,8 +48,8 @@ describe("IDE Utils", () => {
});
openFiles = utils.getOpenFiles();
assert(openFiles.length === 2);
assert(openFiles.includes(testPyPath));
assert(openFiles.includes(testJsPath));
assert(openFiles.find((f) => f.fsPath === testPyPath));
assert(openFiles.find((f) => f.fsPath === testJsPath));
});
test("getUniqueId", async () => {

View file

@ -124,13 +124,3 @@ export function getExtensionVersion(): string {
const extension = vscode.extensions.getExtension("continue.continue");
return extension?.packageJSON.version || "0.1.0";
}
export function getFullyQualifiedPath(ide: VsCodeIde, filepath: string) {
if (ide.ideUtils.path.isAbsolute(filepath)) {return filepath;}
const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
return ide.ideUtils.path.join(workspaceFolders[0].uri.fsPath, filepath);
}
}