diff --git a/.continue/prompts/core-util-test.prompt b/.continue/prompts/core-util-test.prompt index 19202ddee..6cc7351a2 100644 --- a/.continue/prompts/core-util-test.prompt +++ b/.continue/prompts/core-util-test.prompt @@ -1,21 +1,27 @@ name: Write Core Utility Test description: Generate unit tests for core utilities --- -Write jest tests for the provided code. Use best practices. Be clear and consise. +Write jest tests for the provided code. +Use jest version ^29 (e.g. jest 29.7.0) + +Use best practices. Be clear and consise. Aim for 100% code coverage where reasonable. Multiple tests can be written, split up tests for best clarity and readability. Only use typescript, and if the file/code is not typescript, warn the user. Use given types to generate mock data if needed. -Additional types can be imported from @core/gui/src/components/mainInput/types.d.ts +Additional types can be imported from @core/index.d.ts If any needed type declaration is still not found, warn the user. -Existing test fixtures can be found in: -@core/test/util/fixtures.ts +Existing test fixtures can be found in @core/test/fixtures.ts - import and use `testIde` for any IDE type needs - import and use `testControlPlaneClient` for any ControlPlaneClient needs - import and use `testConfigHandler` for any ConfigHandler needs - import and use `ideSettingsPromise` for any IdeSettings needs +Do NOT write tests for `core/test/util/fixtures.ts` or `core/index.d.ts`, only use them as helpers for testing other files. If no other files are attached, just warn the user. + // This note is for if using edit mode to encourage it to create new files -The tests are to be put in a new file with the same filepath but with a .test.ts extension rather than a .ts extension \ No newline at end of file +The tests are to be put in a new file with the same filepath but with a .test.ts extension rather than a .ts extension +Avoid casting functions to the jest.Mock type. Instead, use `jest.mocked(fn)` +Use double quotes (or backticks if needed) for strings, and observe eslint import order standards \ No newline at end of file diff --git a/core/autocomplete/context/root-path-context/test/testUtils.ts b/core/autocomplete/context/root-path-context/test/testUtils.ts index 7a5c22aba..207b1d6d4 100644 --- a/core/autocomplete/context/root-path-context/test/testUtils.ts +++ b/core/autocomplete/context/root-path-context/test/testUtils.ts @@ -4,7 +4,7 @@ import path from "path"; import Parser from "web-tree-sitter"; import { Position } from "../../../.."; -import { testIde } from "../../../../test/util/fixtures"; +import { testIde } from "../../../../test/fixtures"; import { getAst, getTreePathAtCursor } from "../../../util/ast"; import { ImportDefinitionsService } from "../../ImportDefinitionsService"; import { RootPathContextService } from "../RootPathContextService"; diff --git a/core/autocomplete/filtering/test/filter.test.ts b/core/autocomplete/filtering/test/filter.test.ts index e6c07b951..594e061ad 100644 --- a/core/autocomplete/filtering/test/filter.test.ts +++ b/core/autocomplete/filtering/test/filter.test.ts @@ -1,4 +1,4 @@ -import { setUpTestDir, tearDownTestDir } from "../../../test/util/testDir"; +import { setUpTestDir, tearDownTestDir } from "../../../test/testDir"; import { TEST_CASES_WITH_DIFF, TEST_CASES_WITHOUT_DIFF } from "./testCases"; import { diff --git a/core/autocomplete/filtering/test/util.ts b/core/autocomplete/filtering/test/util.ts index 8adaa101a..a052aace2 100644 --- a/core/autocomplete/filtering/test/util.ts +++ b/core/autocomplete/filtering/test/util.ts @@ -2,7 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import Mock from "../../../llm/llms/Mock"; -import { testConfigHandler, testIde } from "../../../test/util/fixtures"; +import { testConfigHandler, testIde } from "../../../test/fixtures"; import { CompletionProvider } from "../../CompletionProvider"; import { AutocompleteInput } from "../../util/types"; diff --git a/core/config/ConfigHandler.test.ts b/core/config/ConfigHandler.test.ts index 26de42ec7..e7d90f492 100644 --- a/core/config/ConfigHandler.test.ts +++ b/core/config/ConfigHandler.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; import path from "node:path"; -import { testConfigHandler } from "../test/util/fixtures"; -import { TEST_DIR } from "../test/util/testDir"; +import { testConfigHandler } from "../test/fixtures"; +import { TEST_DIR } from "../test/testDir"; import { getConfigTsPath } from "../util/paths"; import { defaultConfig } from "./default"; diff --git a/core/test/context/providers/index.skip.ts b/core/context/providers/_context-providers.test.ts similarity index 83% rename from core/test/context/providers/index.skip.ts rename to core/context/providers/_context-providers.test.ts index 1d4e9f1b1..7e0fdbd73 100644 --- a/core/test/context/providers/index.skip.ts +++ b/core/context/providers/_context-providers.test.ts @@ -4,12 +4,12 @@ import { ContextProviderExtras, ContextProviderWithParams, IContextProvider, -} from "../../.."; -import { ConfigHandler } from "../../../config/ConfigHandler"; -import { contextProviderClassFromName } from "../../../context/providers"; -import { ControlPlaneClient } from "../../../control-plane/client"; -import FileSystemIde from "../../../util/filesystem"; -import { TEST_DIR } from "../../util/testDir"; +} from "../.."; +import { ConfigHandler } from "../../config/ConfigHandler"; +import { contextProviderClassFromName } from "."; +import { ControlPlaneClient } from "../../control-plane/client"; +import FileSystemIde from "../../util/filesystem"; +import { TEST_DIR } from "../../test/testDir"; const CONTEXT_PROVIDERS_TO_TEST: ContextProviderWithParams[] = [ { name: "diff", params: {} }, diff --git a/core/index.d.ts b/core/index.d.ts index 81ddd2039..06fbd7275 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -195,10 +195,12 @@ export interface CustomContextProvider { description?: string; renderInlineAs?: string; type?: ContextProviderType; + getContextItems( query: string, extras: ContextProviderExtras, ): Promise; + loadSubmenuItems?: ( args: LoadSubmenuItemsArgs, ) => Promise; @@ -275,10 +277,12 @@ export interface Range { start: Position; end: Position; } + export interface Position { line: number; character: number; } + export interface FileEdit { filepath: string; range: Range; @@ -479,6 +483,7 @@ export interface LLMOptions { // IBM watsonx Options deploymentId?: string; } + type RequireAtLeastOne = Pick< T, Exclude @@ -535,6 +540,7 @@ export class Thread { } export type IdeType = "vscode" | "jetbrains"; + export interface IdeInfo { ideType: IdeType; name: string; @@ -570,42 +576,68 @@ export interface IdeSettings { export interface IDE { getIdeInfo(): Promise; + getIdeSettings(): Promise; + getDiff(includeUnstaged: boolean): Promise; + getClipboardContent(): Promise<{ text: string; copiedAt: string }>; + isTelemetryEnabled(): Promise; + getUniqueId(): Promise; + getTerminalContents(): Promise; + getDebugLocals(threadIndex: number): Promise; + getTopLevelCallStackSources( threadIndex: number, stackDepth: number, ): Promise; + getAvailableThreads(): Promise; + listFolders(): Promise; + getWorkspaceDirs(): Promise; + getWorkspaceConfigs(): Promise; + fileExists(filepath: string): Promise; + writeFile(path: string, contents: string): Promise; + showVirtualFile(title: string, contents: string): Promise; + getContinueDir(): Promise; + openFile(path: string): Promise; + openUrl(url: string): Promise; + runCommand(command: string): Promise; + saveFile(filepath: string): Promise; + readFile(filepath: string): Promise; + readRangeInFile(filepath: string, range: Range): Promise; + showLines( filepath: string, startLine: number, endLine: number, ): Promise; + showDiff( filepath: string, newContents: string, stepIndex: number, ): Promise; + getOpenFiles(): Promise; + getCurrentFile(): Promise< | undefined | { @@ -614,21 +646,33 @@ export interface IDE { contents: string; } >; + getPinnedFiles(): Promise; + getSearchResults(query: string): Promise; + subprocess(command: string, cwd?: string): Promise<[string, string]>; + getProblems(filepath?: string | undefined): Promise; + getBranch(dir: string): Promise; + getTags(artifactId: string): Promise; + getRepoName(dir: string): Promise; + showToast( type: ToastType, message: string, ...otherParams: any[] ): Promise; + getGitRootPath(dir: string): Promise; + listDir(dir: string): Promise<[string, FileType][]>; + getLastModified(files: string[]): Promise<{ [path: string]: number }>; + getGitHubAuthToken(args: GetGhTokenArgs): Promise; // LSP @@ -636,6 +680,7 @@ export interface IDE { // Callbacks onDidChangeActiveTextEditor(callback: (filepath: string) => void): void; + pathSep(): Promise; } @@ -1035,6 +1080,7 @@ export interface EmbeddingsProvider { id: string; providerName: EmbeddingsProviderName; maxChunkSize: number; + embed(chunks: string[]): Promise; } @@ -1053,6 +1099,7 @@ export interface RerankerDescription { export interface Reranker { name: string; + rerank(query: string, chunks: Chunk[]): Promise; } diff --git a/core/indexing/CodeSnippetsIndex.test.ts b/core/indexing/CodeSnippetsIndex.test.ts index 97d086d23..814927725 100644 --- a/core/indexing/CodeSnippetsIndex.test.ts +++ b/core/indexing/CodeSnippetsIndex.test.ts @@ -1,11 +1,11 @@ import { jest } from "@jest/globals"; -import { testIde } from "../test/util/fixtures"; +import { testIde } from "../test/fixtures"; import { insertMockChunks, mockPathAndCacheKey, updateIndexAndAwaitGenerator, -} from "../test/util/indexing"; +} from "./test/indexing"; import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex"; import { DatabaseConnection, SqliteDb } from "./refreshIndex"; diff --git a/core/indexing/CodebaseIndexer.test.ts b/core/indexing/CodebaseIndexer.test.ts index ee2f108f7..950e23ffd 100644 --- a/core/indexing/CodebaseIndexer.test.ts +++ b/core/indexing/CodebaseIndexer.test.ts @@ -5,13 +5,13 @@ import path from "node:path"; import { jest } from "@jest/globals"; import { ContinueServerClient } from "../continueServer/stubs/client.js"; -import { testConfigHandler, testIde } from "../test/util/fixtures.js"; +import { testConfigHandler, testIde } from "../test/fixtures.js"; import { addToTestDir, setUpTestDir, tearDownTestDir, TEST_DIR, -} from "../test/util/testDir.js"; +} from "../test/testDir.js"; import { getIndexSqlitePath } from "../util/paths.js"; import { CodebaseIndexer, PauseToken } from "./CodebaseIndexer.js"; @@ -76,8 +76,8 @@ describe("CodebaseIndexer", () => { setUpTestDir(); execSync("git init", { cwd: TEST_DIR }); - execSync("git config user.email \"test@example.com\"", { cwd: TEST_DIR }); - execSync("git config user.name \"Test\"", { cwd: TEST_DIR }); + execSync('git config user.email "test@example.com"', { cwd: TEST_DIR }); + execSync('git config user.name "Test"', { cwd: TEST_DIR }); }); afterAll(async () => { @@ -100,9 +100,7 @@ describe("CodebaseIndexer", () => { async function refreshIndexFiles(files: string[]) { const updates = []; - for await (const update of codebaseIndexer.refreshFiles( - files, - )) { + for await (const update of codebaseIndexer.refreshFiles(files)) { updates.push(update); } return updates; diff --git a/core/indexing/FullTextSearchCodebaseIndex.test.ts b/core/indexing/FullTextSearchCodebaseIndex.test.ts index d46e47fd4..3aefafaaa 100644 --- a/core/indexing/FullTextSearchCodebaseIndex.test.ts +++ b/core/indexing/FullTextSearchCodebaseIndex.test.ts @@ -4,7 +4,7 @@ import { insertMockChunks, mockPathAndCacheKey, updateIndexAndAwaitGenerator, -} from "../test/util/indexing"; +} from "./test/indexing"; import { FullTextSearchCodebaseIndex } from "./FullTextSearchCodebaseIndex"; import { DatabaseConnection, SqliteDb } from "./refreshIndex"; diff --git a/core/indexing/LanceDbIndex.test.ts b/core/indexing/LanceDbIndex.test.ts index f0c711e93..1d15117fd 100644 --- a/core/indexing/LanceDbIndex.test.ts +++ b/core/indexing/LanceDbIndex.test.ts @@ -1,13 +1,13 @@ import { jest } from "@jest/globals"; import lance from "vectordb"; -import { testConfigHandler, testIde } from "../test/util/fixtures"; +import { testConfigHandler, testIde } from "../test/fixtures"; import { mockPathAndCacheKey, mockTag, testContinueServerClient, updateIndexAndAwaitGenerator, -} from "../test/util/indexing"; +} from "./test/indexing"; import { getLanceDbPath } from "../util/paths"; import { LanceDbIndex } from "./LanceDbIndex"; diff --git a/core/indexing/chunk/ChunkCodebaseIndex.test.ts b/core/indexing/chunk/ChunkCodebaseIndex.test.ts index c2f95d560..3f7904991 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.test.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.test.ts @@ -1,14 +1,14 @@ import { jest } from "@jest/globals"; -import { testIde } from "../../test/util/fixtures"; +import { testIde } from "../../test/fixtures"; import { mockFileContents, mockFilename, mockPathAndCacheKey, testContinueServerClient, updateIndexAndAwaitGenerator, -} from "../../test/util/indexing"; -import { addToTestDir } from "../../test/util/testDir"; +} from "../test/indexing"; +import { addToTestDir } from "../../test/testDir"; import { DatabaseConnection, SqliteDb } from "../refreshIndex"; import { IndexResultType } from "../types"; diff --git a/core/indexing/docs/DocsCrawler.skip.ts b/core/indexing/docs/DocsCrawler.skip.ts index 57d712fed..97226c296 100644 --- a/core/indexing/docs/DocsCrawler.skip.ts +++ b/core/indexing/docs/DocsCrawler.skip.ts @@ -3,7 +3,7 @@ import os from "os"; import { jest } from "@jest/globals"; import { ContinueConfig } from "../.."; -import { testConfigHandler } from "../../test/util/fixtures"; +import { testConfigHandler } from "../../test/fixtures"; import FileSystemIde from "../../util/filesystem"; import DocsCrawler, { ChromiumInstaller, type PageData } from "./DocsCrawler"; diff --git a/core/test/util/indexing.ts b/core/indexing/test/indexing.ts similarity index 84% rename from core/test/util/indexing.ts rename to core/indexing/test/indexing.ts index 16137236a..413c37e75 100644 --- a/core/test/util/indexing.ts +++ b/core/indexing/test/indexing.ts @@ -2,19 +2,12 @@ import { jest } from "@jest/globals"; import { IndexTag } from "../.."; import { IContinueServerClient } from "../../continueServer/interface"; -import { ChunkCodebaseIndex } from "../../indexing/chunk/ChunkCodebaseIndex"; -import { tagToString } from "../../indexing/refreshIndex"; -import { - CodebaseIndex, - PathAndCacheKey, - RefreshIndexResults, -} from "../../indexing/types"; - -import { testIde } from "./fixtures"; -import { addToTestDir, TEST_DIR } from "./testDir"; - - +import { ChunkCodebaseIndex } from "../chunk/ChunkCodebaseIndex"; +import { tagToString } from "../refreshIndex"; +import { CodebaseIndex, PathAndCacheKey, RefreshIndexResults } from "../types"; +import { testIde } from "../../test/fixtures"; +import { addToTestDir, TEST_DIR } from "../../test/testDir"; export const mockFilename = "test.py"; export const mockPathAndCacheKey = { diff --git a/core/indexing/walkDir.test.ts b/core/indexing/walkDir.test.ts index 748e958e9..25ffdfc37 100644 --- a/core/indexing/walkDir.test.ts +++ b/core/indexing/walkDir.test.ts @@ -6,7 +6,7 @@ import { setUpTestDir, tearDownTestDir, addToTestDir, -} from "../test/util/testDir"; +} from "../test/testDir"; import FileSystemIde from "../util/filesystem"; const ide = new FileSystemIde(TEST_DIR); diff --git a/core/jest.config.js b/core/jest.config.js index b92d03e5e..d58b0b510 100644 --- a/core/jest.config.js +++ b/core/jest.config.js @@ -8,8 +8,8 @@ export default { moduleNameMapper: { "^(\\.{1,2}/.*)\\.js$": "$1", "^uuid$": "uuid", // https://stackoverflow.com/a/73626360 - '^@azure/(.*)$': '/node_modules/@azure/$1', - '^mssql$': '/node_modules/mssql' + "^@azure/(.*)$": "/node_modules/@azure/$1", + "^mssql$": "/node_modules/mssql", }, extensionsToTreatAsEsm: [".ts"], preset: "ts-jest/presets/default-esm", @@ -19,6 +19,8 @@ export default { __dirname: path.dirname(fileURLToPath(import.meta.url)), __filename: path.resolve(fileURLToPath(import.meta.url)), }, + globalSetup: "/jest.global-setup.ts", setupFilesAfterEnv: ["/jest.setup-after-env.ts"], + maxWorkers: 1 // equivalent to CLI --runInBand }; diff --git a/core/jest.setup-after-env.ts b/core/jest.setup-after-env.ts index b5fbacc11..53f94ecea 100644 --- a/core/jest.setup-after-env.ts +++ b/core/jest.setup-after-env.ts @@ -1,4 +1,4 @@ -// https://github.com/mswjs/msw/issues/1576#issuecomment-1482643055 +import fs from "fs"; import { TextDecoder, TextEncoder } from "util"; import { jest } from "@jest/globals"; @@ -10,23 +10,21 @@ if (process.env.DEBUG === "jest") { const globalThis = global as any; +globalThis.jest = jest; + +// https://github.com/mswjs/msw/issues/1576#issuecomment-1482643055 globalThis.fetch = fetch; globalThis.Request = Request; globalThis.Response = Response; globalThis.TextEncoder = TextEncoder; globalThis.TextDecoder = TextDecoder; -// Trying to delete this when for some reason SQLite is still in use causes tests to fail -// globalThis.beforeAll(() => { -// // We can ignore TS warnings here since we set this explicitly in `./jest.global-setup.ts` +// TODO - currently causing tests to fail because sqlite is still running for some reason +// const clearTestDirectory = () => { // if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR!)) { // fs.rmSync(process.env.CONTINUE_GLOBAL_DIR!, { recursive: true }); // } -// }); +// }; -// globalThis.afterAll(() => { -// // We can ignore TS warnings here since we set this explicitly in `./jest.global-setup.ts` -// if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR!)) { -// fs.rmSync(process.env.CONTINUE_GLOBAL_DIR!, { recursive: true }); -// } -// }); +// globalThis.beforeAll(clearTestDirectory); +// globalThis.afterAll(clearTestDirectory); diff --git a/core/test/llm.test.ts b/core/llm/llm.test.ts similarity index 95% rename from core/test/llm.test.ts rename to core/llm/llm.test.ts index cf42e128a..cb2218d1d 100644 --- a/core/test/llm.test.ts +++ b/core/llm/llm.test.ts @@ -1,10 +1,8 @@ import * as dotenv from "dotenv"; -import { CompletionOptions } from "../"; -import { BaseLLM } from "../llm/"; -import OpenAI from "../llm/llms/OpenAI"; - -// jest.setTimeout(100_000); +import { CompletionOptions } from ".."; +import { BaseLLM } from "."; +import OpenAI from "./llms/OpenAI"; dotenv.config(); diff --git a/core/package-lock.json b/core/package-lock.json index 58762590f..41aeca5cb 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -7882,9 +7882,9 @@ } }, "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", "engines": { "node": ">=12" }, diff --git a/core/package.json b/core/package.json index 78d7ecf65..b02671dba 100644 --- a/core/package.json +++ b/core/package.json @@ -3,7 +3,8 @@ "version": "1.0.13", "description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js", "scripts": { - "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --runInBand", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", + "test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage && open ./coverage/lcov-report/index.html", "tsc:check": "tsc -p ./ --noEmit", "build:npm": "tsc -p ./tsconfig.npm.json", "lint": "eslint . --ext ts", diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index cd79bcd21..4cadecbf4 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -43,7 +43,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { insertAtCursor: [{ text: string }, void]; copyText: [{ text: string }, void]; "jetbrains/editorInsetHeight": [{ height: number }, void]; - "jetbrains/isOSREnabled": [undefined, void]; + "jetbrains/isOSREnabled": [undefined, boolean]; "vscode/openMoveRightMarkdown": [undefined, void]; setGitHubAuthToken: [{ token: string }, void]; acceptDiff: [{ filepath: string; streamId?: string }, void]; diff --git a/core/test/.gitignore b/core/test/.gitignore deleted file mode 100644 index 227f3fc4f..000000000 --- a/core/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -scratch.test.ts \ No newline at end of file diff --git a/core/test/editme.py b/core/test/editme.py deleted file mode 100644 index c6077fb3b..000000000 --- a/core/test/editme.py +++ /dev/null @@ -1,2 +0,0 @@ -def average(nums: list) -> float: - pass diff --git a/core/test/util/fixtures.ts b/core/test/fixtures.ts similarity index 68% rename from core/test/util/fixtures.ts rename to core/test/fixtures.ts index e0aa06d14..add71d029 100644 --- a/core/test/util/fixtures.ts +++ b/core/test/fixtures.ts @@ -1,6 +1,6 @@ -import { ConfigHandler } from "../../config/ConfigHandler"; -import { ControlPlaneClient } from "../../control-plane/client"; -import FileSystemIde from "../../util/filesystem"; +import { ConfigHandler } from "../config/ConfigHandler"; +import { ControlPlaneClient } from "../control-plane/client"; +import FileSystemIde from "../util/filesystem"; import { TEST_DIR } from "./testDir"; diff --git a/core/test/util/testDir.ts b/core/test/testDir.ts similarity index 92% rename from core/test/util/testDir.ts rename to core/test/testDir.ts index 62cbbb02c..0eae7ad0b 100644 --- a/core/test/util/testDir.ts +++ b/core/test/testDir.ts @@ -3,7 +3,7 @@ import os from "os"; import path from "path"; // Want this outside of the git repository so we can change branches in tests -export const TEST_DIR = path.join(os.tmpdir(), "testDir"); +export const TEST_DIR = path.join(os.tmpdir(), "testWorkspaceDir"); export function setUpTestDir() { if (fs.existsSync(TEST_DIR)) { diff --git a/core/test/_testEnv.test.ts b/core/test/testEnv.test.ts similarity index 100% rename from core/test/_testEnv.test.ts rename to core/test/testEnv.test.ts diff --git a/core/test/util/dedentAndGetCommonWhitespace.test.ts b/core/test/util/dedentAndGetCommonWhitespace.test.ts deleted file mode 100644 index 5f3c6a4be..000000000 --- a/core/test/util/dedentAndGetCommonWhitespace.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -// File generated by Continue -import { dedentAndGetCommonWhitespace } from "../../util"; - -describe("dedentAndGetCommonWhitespace", () => { - let originalString: string; - - beforeEach(() => { - // Setup any global variables or states if needed - originalString = " line1\n line2\n line3"; - }); - - afterEach(() => { - // Tear down any changes to global variables or states if needed - originalString = ""; - }); - - test("should dedent and return common whitespace for a simple case", () => { - const input = " line1\n line2\n line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["line1\nline2\nline3", " "]); - }); - - test("should handle empty string", () => { - const input = ""; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["", ""]); - }); - - test("should handle string with only whitespace", () => { - const input = " "; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["", ""]); - }); - - test("should handle string with mixed whitespace and content", () => { - const input = " line1\n line2\n line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual([" line1\nline2\n line3", " "]); - }); - - test("should handle string with no common leading whitespace", () => { - const input = "line1\n line2\n line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual([input, ""]); - }); - - test("should handle string with empty lines", () => { - const input = " line1\n\n line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["line1\n\nline3", " "]); - }); - - test("should handle string with only empty lines", () => { - const input = "\n\n"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["\n\n", ""]); - }); - - test("should handle string with tabs as whitespace", () => { - const input = "\tline1\n\tline2\n\tline3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["line1\nline2\nline3", "\t"]); - }); - - test("should handle string with mixed tabs and spaces", () => { - const input = "\t line1\n\t line2\n\t line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual(["line1\nline2\nline3", "\t "]); - }); - - test("should handle string with different leading whitespace lengths", () => { - const input = " line1\n line2\n line3"; - const output = dedentAndGetCommonWhitespace(input); - expect(output).toEqual([" line1\nline2\n line3", " "]); - }); -}); diff --git a/core/test/util/getLastNPathParts.test.ts b/core/test/util/getLastNPathParts.test.ts deleted file mode 100644 index ba72b4520..000000000 --- a/core/test/util/getLastNPathParts.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -// File generated by Continue -import { getLastNPathParts } from "../../util"; - -describe("getLastNPathParts", () => { - const SEP_REGEX = /[\\/]+/; - - beforeAll(() => { - // Setup code if needed - }); - - afterAll(() => { - // Teardown code if needed - }); - - test("returns the last N parts of a filepath with forward slashes", () => { - const filepath = "home/user/documents/project/file.txt"; - expect(getLastNPathParts(filepath, 2)).toBe("project/file.txt"); - }); - - test("returns the last N parts of a filepath with backward slashes", () => { - const filepath = "C:\\home\\user\\documents\\project\\file.txt"; - expect(getLastNPathParts(filepath, 3)).toBe("documents/project/file.txt"); - }); - - test("returns the last part if N is 1", () => { - const filepath = "/home/user/documents/project/file.txt"; - expect(getLastNPathParts(filepath, 1)).toBe("file.txt"); - }); - - test("returns the entire path if N is greater than the number of parts", () => { - const filepath = "home/user/documents/project/file.txt"; - expect(getLastNPathParts(filepath, 10)).toBe( - "home/user/documents/project/file.txt", - ); - }); - - test("returns an empty string if N is 0", () => { - const filepath = "home/user/documents/project/file.txt"; - expect(getLastNPathParts(filepath, 0)).toBe(""); - }); - - test("handles paths with mixed forward and backward slashes", () => { - const filepath = "home\\user/documents\\project/file.txt"; - expect(getLastNPathParts(filepath, 3)).toBe("documents/project/file.txt"); - }); - - test("handles edge case with empty filepath", () => { - const filepath = ""; - expect(getLastNPathParts(filepath, 2)).toBe(""); - }); -}); diff --git a/core/test/util/lcs.test.ts b/core/test/util/lcs.test.ts deleted file mode 100644 index da10cdf90..000000000 --- a/core/test/util/lcs.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -// This file is generated by Continue -import { longestCommonSubsequence } from "../../util/lcs"; - -describe("longestCommonSubsequence", () => { - beforeAll(() => { - // Setup if needed - }); - - afterAll(() => { - // Teardown if needed - }); - - test("should return the longest common subsequence for non-empty strings", () => { - expect(longestCommonSubsequence("abcde", "ace")).toBe("ace"); - expect(longestCommonSubsequence("abc", "abc")).toBe("abc"); - expect(longestCommonSubsequence("abc", "def")).toBe(""); - }); - - test("should handle cases where one or both strings are empty", () => { - expect(longestCommonSubsequence("", "abc")).toBe(""); - expect(longestCommonSubsequence("abc", "")).toBe(""); - expect(longestCommonSubsequence("", "")).toBe(""); - }); - - test("should handle cases with no common subsequence", () => { - expect(longestCommonSubsequence("abc", "def")).toBe(""); - expect(longestCommonSubsequence("xyz", "abc")).toBe(""); - }); - - test("should handle cases with special characters", () => { - expect(longestCommonSubsequence("a!@#b$c", "!@#$")).toBe("!@#$"); - expect(longestCommonSubsequence("a!@#b$c", "xyz")).toBe(""); - }); - - test("should handle long strings efficiently", () => { - const str1 = "a".repeat(1000) + "b".repeat(1000); - const str2 = "a".repeat(1000) + "c".repeat(1000); - expect(longestCommonSubsequence(str1, str2)).toBe("a".repeat(1000)); - }); -}); diff --git a/core/test/util/merge.test.ts b/core/test/util/merge.test.ts deleted file mode 100644 index cf7ba99d5..000000000 --- a/core/test/util/merge.test.ts +++ /dev/null @@ -1,100 +0,0 @@ -// File generated by Continue -import { mergeJson } from "../../util/merge"; - -describe("mergeJson", () => { - it("should merge two simple JSON objects", () => { - const first = { a: 1, b: 2 }; - const second = { b: 3, c: 4 }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: 1, b: 3, c: 4 }); - }); - - it("should overwrite values when mergeBehavior is \"overwrite\"", () => { - const first = { a: 1, b: 2 }; - const second = { b: 3, c: 4 }; - const result = mergeJson(first, second, "overwrite"); - expect(result).toEqual({ a: 1, b: 3, c: 4 }); - }); - - it("should merge nested objects", () => { - const first = { a: { b: 1 } }; - const second = { a: { c: 2 } }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: { b: 1, c: 2 } }); - }); - - it("should merge arrays without mergeKeys", () => { - const first = { a: [1, 2] }; - const second = { a: [3, 4] }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: [1, 2, 3, 4] }); - }); - - it("should merge arrays with mergeKeys", () => { - const first = { - a: [ - { id: 1, value: "first" }, - { id: 2, value: "second" }, - ], - }; - const second = { - a: [ - { id: 2, value: "updated" }, - { id: 3, value: "third" }, - ], - }; - const mergeKeys = { - a: (item1: any, item2: any) => item1.id === item2.id, - }; - const result = mergeJson(first, second, undefined, mergeKeys); - expect(result).toEqual({ - a: [ - { id: 1, value: "first" }, - { id: 2, value: "updated" }, - { id: 3, value: "third" }, - ], - }); - }); - - it("should handle non-object values correctly", () => { - const first = { a: 1, b: "string", c: true }; - const second = { a: 2, b: "new string", c: false }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: 2, b: "new string", c: false }); - }); - - it("should handle null and undefined values correctly", () => { - const first = { a: 1, b: null }; - const second = { b: 2, c: undefined }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: 1, b: 2, c: undefined }); - }); - - it("should handle empty objects", () => { - const first = {}; - const second = { a: 1 }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: 1 }); - }); - - it("should handle empty second object", () => { - const first = { a: 1 }; - const second = {}; - const result = mergeJson(first, second); - expect(result).toEqual({ a: 1 }); - }); - - it("should handle errors gracefully", () => { - const first = { a: 1 }; - const second = { b: () => {} }; // Functions are not serializable in JSON - const result = mergeJson(first, second); - expect(result).toEqual({ a: 1, b: expect.any(Function) }); - }); - - it("should merge deeply nested objects", () => { - const first = { a: { b: { c: 1 } } }; - const second = { a: { b: { d: 2 } } }; - const result = mergeJson(first, second); - expect(result).toEqual({ a: { b: { c: 1, d: 2 } } }); - }); -}); diff --git a/core/test/util/ranges/getRangeInString.test.ts b/core/test/util/ranges/getRangeInString.test.ts deleted file mode 100644 index e0a4df67a..000000000 --- a/core/test/util/ranges/getRangeInString.test.ts +++ /dev/null @@ -1,105 +0,0 @@ -// This file is generated by Continue - -import { getRangeInString } from "../../../util/ranges"; - -describe.skip("getRangeInString", () => { - let content: string; - - beforeEach(() => { - content = `Line 1 -Line 2 -Line 3 -Line 4 -Line 5`; - }); - - afterEach(() => { - content = ""; - }); - - test("should return substring within the same line", () => { - const range = { - start: { line: 1, character: 0 }, - end: { line: 1, character: 4 }, - }; - expect(getRangeInString(content, range)).toBe("Line"); - }); - - test("should return substring spanning multiple lines", () => { - const range = { - start: { line: 1, character: 2 }, - end: { line: 3, character: 3 }, - }; - const expected = `ne 2 -Line 3 -Line 4`; - expect(getRangeInString(content, range)).toBe(expected); - }); - - test("should handle range that starts and ends at the same character", () => { - const range = { - start: { line: 2, character: 0 }, - end: { line: 2, character: 0 }, - }; - expect(getRangeInString(content, range)).toBe("L"); - }); - - test("should handle range that spans entire content", () => { - const range = { - start: { line: 0, character: 0 }, - end: { line: 4, character: 5 }, - }; - expect(getRangeInString(content, range)).toBe(content); - }); - - test("should handle range that spans to the end of the last line", () => { - const range = { - start: { line: 3, character: 2 }, - end: { line: 4, character: 5 }, - }; - const expected = `ne 4 -Line 5`; - expect(getRangeInString(content, range)).toBe(expected); - }); - - test("should handle empty content", () => { - content = ""; - const range = { - start: { line: 0, character: 0 }, - end: { line: 0, character: 0 }, - }; - expect(getRangeInString(content, range)).toBe(""); - }); - - test("should handle invalid range (start line > end line)", () => { - const range = { - start: { line: 3, character: 0 }, - end: { line: 2, character: 0 }, - }; - expect(getRangeInString(content, range)).toBe(""); - }); - - test("should handle invalid range (start character > end character on same line)", () => { - const range = { - start: { line: 1, character: 5 }, - end: { line: 1, character: 2 }, - }; - expect(getRangeInString(content, range)).toBe(""); - }); - - test("should handle range that starts and ends at the same line but different characters", () => { - const range = { - start: { line: 1, character: 2 }, - end: { line: 1, character: 6 }, - }; - expect(getRangeInString(content, range)).toBe("ne 2"); - }); - - test("should handle range that starts and ends at the same line and same characters", () => { - const range = { - start: { line: 1, character: 2 }, - end: { line: 1, character: 2 }, - }; - expect(getRangeInString(content, range)).toBe("n"); - }); -}); diff --git a/core/test/util/ranges/intersection.test.ts b/core/test/util/ranges/intersection.test.ts deleted file mode 100644 index 397dbc1a8..000000000 --- a/core/test/util/ranges/intersection.test.ts +++ /dev/null @@ -1,123 +0,0 @@ -// This file is generated by Continue - -import { intersection } from "../../../util/ranges"; - -interface Position { - line: number; - character: number; -} - -interface Range { - start: Position; - end: Position; -} - -describe("intersection", () => { - let rangeA: Range; - let rangeB: Range; - - beforeEach(() => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 3, character: 5 }, - }; - - rangeB = { - start: { line: 2, character: 2 }, - end: { line: 4, character: 0 }, - }; - }); - - test("returns correct intersection for overlapping ranges", () => { - const result = intersection(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 2, character: 2 }, - end: { line: 3, character: 5 }, - }); - }); - - test("returns null for non-overlapping ranges", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 2, character: 0 }, - }; - - rangeB = { - start: { line: 3, character: 0 }, - end: { line: 4, character: 0 }, - }; - - const result = intersection(rangeA, rangeB); - expect(result).toBeNull(); - }); - - // TODO - test.skip("returns correct intersection for single line overlap", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 1, character: 5 }, - }; - - rangeB = { - start: { line: 1, character: 3 }, - end: { line: 2, character: 0 }, - }; - - const result = intersection(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 1, character: 3 }, - end: { line: 1, character: 5 }, - }); - }); - - test("returns null for single line non-overlapping ranges", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 1, character: 2 }, - }; - - rangeB = { - start: { line: 1, character: 3 }, - end: { line: 1, character: 5 }, - }; - - const result = intersection(rangeA, rangeB); - expect(result).toBeNull(); - }); - - test("returns correct intersection when one range is fully within another", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 4, character: 5 }, - }; - - rangeB = { - start: { line: 2, character: 2 }, - end: { line: 3, character: 3 }, - }; - - const result = intersection(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 2, character: 2 }, - end: { line: 3, character: 3 }, - }); - }); - - test("returns correct intersection when ranges touch at the edge", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 2, character: 0 }, - }; - - rangeB = { - start: { line: 2, character: 0 }, - end: { line: 3, character: 0 }, - }; - - const result = intersection(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 2, character: 0 }, - end: { line: 2, character: 0 }, - }); - }); -}); diff --git a/core/test/util/ranges/maxMinPosition.test.ts b/core/test/util/ranges/maxMinPosition.test.ts deleted file mode 100644 index 0468df1cd..000000000 --- a/core/test/util/ranges/maxMinPosition.test.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { maxPosition, minPosition } from "../../../util/ranges"; - -// This file is generated by Continue -interface Position { - line: number; - character: number; -} - -describe("Position comparison functions", () => { - let pos1: Position; - let pos2: Position; - let pos3: Position; - let pos4: Position; - - beforeAll(() => { - // Setup: Initializing positions - pos1 = { line: 1, character: 5 }; - pos2 = { line: 2, character: 3 }; - pos3 = { line: 1, character: 7 }; - pos4 = { line: 2, character: 3 }; // Same as pos2 to test equality - }); - - describe("maxPosition", () => { - it("should return the position with the greater line number", () => { - expect(maxPosition(pos1, pos2)).toEqual(pos2); - }); - - it("should return the position with the greater character number when lines are equal", () => { - expect(maxPosition(pos1, pos3)).toEqual(pos3); - }); - - it("should return the first position when both positions are equal", () => { - expect(maxPosition(pos2, pos4)).toEqual(pos2); - }); - - it("should handle positions with negative line numbers", () => { - const posNegative = { line: -1, character: 0 }; - expect(maxPosition(posNegative, pos1)).toEqual(pos1); - }); - - it("should handle positions with negative character numbers", () => { - const posNegativeChar = { line: 1, character: -1 }; - expect(maxPosition(posNegativeChar, pos1)).toEqual(pos1); - }); - }); - - describe("minPosition", () => { - it("should return the position with the lesser line number", () => { - expect(minPosition(pos1, pos2)).toEqual(pos1); - }); - - it("should return the position with the lesser character number when lines are equal", () => { - expect(minPosition(pos1, pos3)).toEqual(pos1); - }); - - it("should return the first position when both positions are equal", () => { - expect(minPosition(pos2, pos4)).toEqual(pos2); - }); - - it("should handle positions with negative line numbers", () => { - const posNegative = { line: -1, character: 0 }; - expect(minPosition(posNegative, pos1)).toEqual(posNegative); - }); - - it("should handle positions with negative character numbers", () => { - const posNegativeChar = { line: 1, character: -1 }; - expect(minPosition(posNegativeChar, pos1)).toEqual(posNegativeChar); - }); - }); -}); diff --git a/core/test/util/ranges/union.test.ts b/core/test/util/ranges/union.test.ts deleted file mode 100644 index 9d06a97b4..000000000 --- a/core/test/util/ranges/union.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { union } from "../../../util/ranges"; - -// This file is generated by Continue -interface Position { - line: number; - character: number; -} - -interface Range { - start: Position; - end: Position; -} - -describe("union", () => { - let rangeA: Range; - let rangeB: Range; - - beforeEach(() => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 3, character: 5 }, - }; - - rangeB = { - start: { line: 2, character: 3 }, - end: { line: 4, character: 2 }, - }; - }); - - test("should return the union of two overlapping ranges", () => { - const result = union(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 1, character: 0 }, - end: { line: 4, character: 2 }, - }); - }); - - test("should return the union when ranges are identical", () => { - const result = union(rangeA, rangeA); - expect(result).toEqual(rangeA); - }); - - test("should return the union when ranges do not overlap but are adjacent", () => { - rangeB = { - start: { line: 3, character: 5 }, - end: { line: 4, character: 2 }, - }; - const result = union(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 1, character: 0 }, - end: { line: 4, character: 2 }, - }); - }); - - test("should return the union when one range is completely within the other", () => { - rangeB = { - start: { line: 2, character: 1 }, - end: { line: 2, character: 4 }, - }; - const result = union(rangeA, rangeB); - expect(result).toEqual(rangeA); - }); - - test("should return the union when ranges do not overlap and are not adjacent", () => { - rangeB = { - start: { line: 4, character: 3 }, - end: { line: 5, character: 1 }, - }; - const result = union(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 1, character: 0 }, - end: { line: 5, character: 1 }, - }); - }); - - // TODO - test.skip("should handle edge case where start and end lines are the same", () => { - rangeA = { - start: { line: 1, character: 0 }, - end: { line: 1, character: 5 }, - }; - rangeB = { - start: { line: 1, character: 3 }, - end: { line: 1, character: 7 }, - }; - const result = union(rangeA, rangeB); - expect(result).toEqual({ - start: { line: 1, character: 0 }, - end: { line: 1, character: 7 }, - }); - }); -}); diff --git a/core/util/chatDescriber.ts b/core/util/chatDescriber.ts index b52fd7696..d4c7413ae 100644 --- a/core/util/chatDescriber.ts +++ b/core/util/chatDescriber.ts @@ -1,24 +1,10 @@ import { ILLM, LLMFullCompletionOptions } from ".."; -import { removeQuotesAndEscapes } from "."; +import { removeQuotesAndEscapes, removeCodeBlocksAndTrim } from "."; import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; import type { IMessenger } from "./messenger"; -/** - * Removes code blocks from a message. - * - * Return modified message text. - */ -function removeCodeBlocksAndTrim(msgText: string): string { - const codeBlockRegex = /```[\s\S]*?```/g; - - // Remove code blocks from the message text - const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, ""); - - return textWithoutCodeBlocks.trim(); -} - export class ChatDescriber { static prompt: string | undefined = "Given the following... please reply with a short summary that is 4-12 words in length, you should summarize what the user is asking for OR what the user is trying to accomplish. You should only respond with the summary, no additional text or explanation, you don't need ending punctuation.\n\n"; diff --git a/core/test/util/history.test.ts b/core/util/history.test.ts similarity index 96% rename from core/test/util/history.test.ts rename to core/util/history.test.ts index 270e81248..048087564 100644 --- a/core/test/util/history.test.ts +++ b/core/util/history.test.ts @@ -1,8 +1,8 @@ import { v4 as uuidv4 } from "uuid"; -import { Session } from "../.."; -import historyManager from "../../util/history"; -import { getSessionFilePath } from "../../util/paths"; +import { Session } from ".."; +import historyManager from "./history"; +import { getSessionFilePath } from "./paths"; const sessionId = uuidv4(); const testSession: Session = { diff --git a/core/util/index.ts b/core/util/index.ts index 7f46278f9..9a896baff 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -328,3 +328,17 @@ export function dedent(strings: TemplateStringsArray, ...values: any[]) { return lines.join("\n"); } + +/** + * Removes code blocks from a message. + * + * Return modified message text. + */ +export function removeCodeBlocksAndTrim(text: string): string { + const codeBlockRegex = /```[\s\S]*?```/g; + + // Remove code blocks from the message text + const textWithoutCodeBlocks = text.replace(codeBlockRegex, ""); + + return textWithoutCodeBlocks.trim(); +} diff --git a/core/util/tts.ts b/core/util/tts.ts index efae302c2..1fd41607c 100644 --- a/core/util/tts.ts +++ b/core/util/tts.ts @@ -1,6 +1,8 @@ import { exec, ChildProcess } from "child_process"; import os from "node:os"; +import { removeCodeBlocksAndTrim } from "."; + import type { IMessenger } from "./messenger"; import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; @@ -8,27 +10,13 @@ import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; // a zombie after executing .kill() const ttsKillTimeout: number = 5000; -/** - * Removes code blocks from a message. - * - * Return modified message text. - */ -function removeCodeBlocks(msgText: string): string { - const codeBlockRegex = /```[\s\S]*?```/g; - - // Remove code blocks from the message text - const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, ""); - - return textWithoutCodeBlocks.trim(); -} - /** * Cleans a message text to safely be used in 'exec' context on host. * * Return modified message text. */ -function sanitizeMessageForTTS(message: string): string { - message = removeCodeBlocks(message); +export function sanitizeMessageForTTS(message: string): string { + message = removeCodeBlocksAndTrim(message); // Remove or replace problematic characters message = message diff --git a/core/util/withExponentialBackoff.ts b/core/util/withExponentialBackoff.ts index efe9d95c1..84b301b26 100644 --- a/core/util/withExponentialBackoff.ts +++ b/core/util/withExponentialBackoff.ts @@ -2,7 +2,7 @@ interface APIError extends Error { response?: Response; } -const RETRY_AFTER_HEADER = "Retry-After"; +export const RETRY_AFTER_HEADER = "Retry-After"; const withExponentialBackoff = async ( apiCall: () => Promise, @@ -18,8 +18,12 @@ const withExponentialBackoff = async ( (error as APIError).response?.status === 429 && attempt < maxRetries - 1 ) { - const retryAfter = (error as APIError).response?.headers.get(RETRY_AFTER_HEADER); - const delay = retryAfter ? parseInt(retryAfter, 10) : initialDelaySeconds * 2 ** attempt; + const retryAfter = (error as APIError).response?.headers.get( + RETRY_AFTER_HEADER, + ); + const delay = retryAfter + ? parseInt(retryAfter, 10) + : initialDelaySeconds * 2 ** attempt; console.log( `Hit rate limit. Retrying in ${delay} seconds (attempt ${ attempt + 1 diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 7651ecc8f..991cbb41a 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -138,7 +138,7 @@ class ContinueBrowser(val project: Project, url: String) { } "jetbrains/isOSREnabled" -> { - sendToWebview( "jetbrains/isOSREnabled", isOSREnabled) + respond(isOSREnabled) } "onLoad" -> { @@ -268,7 +268,9 @@ class ContinueBrowser(val project: Project, url: String) { val jsCode = buildJavaScript(jsonData) try { - this.browser.executeJavaScriptAsync(jsCode) + this.browser.executeJavaScriptAsync(jsCode).onError { + println("Failed to execute jsCode error: ${it.message}") + } } catch (error: IllegalStateException) { println("Webview not initialized yet $error") } diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 9ac0c6f53..20f94f30a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -112,7 +112,7 @@ "comment-json": "^4.2.3", "dbinfoz": "^0.14.0", "diff": "^7.0.0", - "dotenv": "^16.4.5", + "dotenv": "^16.4.7", "fastest-levenshtein": "^1.0.16", "follow-redirects": "^1.15.5", "google-auth-library": "^9.14.2", diff --git a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts index 610d262fc..f98b09f93 100644 --- a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts +++ b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts @@ -22,9 +22,7 @@ export class ContinueGUIWebviewViewProvider private updateDebugLogsStatus() { const settings = vscode.workspace.getConfiguration(EXTENSION_NAME); this.enableDebugLogs = settings.get("enableDebugLogs", false); - if (this.enableDebugLogs) { - this.outputChannel.show(true); - } else { + if (!this.enableDebugLogs) { this.outputChannel.hide(); } } @@ -35,9 +33,7 @@ export class ContinueGUIWebviewViewProvider if (event.affectsConfiguration("continue.enableDebugLogs")) { const settings = vscode.workspace.getConfiguration(EXTENSION_NAME); const enableDebugLogs = settings.get("enableDebugLogs", false); - if (enableDebugLogs) { - this.outputChannel.show(true); - } else { + if (!enableDebugLogs) { this.outputChannel.hide(); } } diff --git a/gui/package-lock.json b/gui/package-lock.json index 91410e6df..af3d5cafa 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -121,7 +121,7 @@ "comment-json": "^4.2.3", "dbinfoz": "^0.14.0", "diff": "^7.0.0", - "dotenv": "^16.4.5", + "dotenv": "^16.4.7", "fastest-levenshtein": "^1.0.16", "follow-redirects": "^1.15.5", "google-auth-library": "^9.14.2", diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx index 3f4ef372d..cac18f4e1 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx @@ -5,7 +5,7 @@ import CodeToEditListItem from "./CodeToEditListItem"; import type { CodeToEdit, RangeInFileWithContents } from "core"; import AddFileButton from "./AddFileButton"; import AddFileCombobox from "./AddFileCombobox"; -import { XMarkIcon } from "@heroicons/react/24/outline"; +import { PlusIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { useAppSelector } from "../../redux/hooks"; import { addCodeToEdit, @@ -61,7 +61,7 @@ export default function CodeToEditCard() { setShowAddFileCombobox(true)} /> - {codeToEdit.length > 0 && ( + {codeToEdit.length > 0 ? (
    {codeToEdit.map((code, i) => ( ))}
+ ) : ( + !showAddFileCombobox && ( +
setShowAddFileCombobox(true)} + > + + Add a file to get started +
+ ) )} {showAddFileCombobox && ( diff --git a/gui/src/components/PageHeader.tsx b/gui/src/components/PageHeader.tsx new file mode 100644 index 000000000..a0de733d0 --- /dev/null +++ b/gui/src/components/PageHeader.tsx @@ -0,0 +1,20 @@ +import { ArrowLeftIcon } from "@heroicons/react/24/outline"; + +export interface PageHeaderProps { + onClick: () => void; + title: string; +} + +export default function PageHeader({ onClick, title }: PageHeaderProps) { + return ( +
+
+ + {title} +
+
+ ); +} diff --git a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx index 7fbbf07c6..472a3d3f7 100644 --- a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx +++ b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx @@ -8,9 +8,11 @@ import { selectIsSingleRangeEditOrInsertion } from "../../redux/slices/sessionSl export interface AcceptRejectAllButtonsProps { pendingApplyStates: ApplyState[]; - onAcceptOrReject?: () => void; + onAcceptOrReject?: (outcome: AcceptOrRejectOutcome) => void; } +export type AcceptOrRejectOutcome = "acceptDiff" | "rejectDiff"; + export default function AcceptRejectAllButtons({ pendingApplyStates, onAcceptOrReject, @@ -18,7 +20,7 @@ export default function AcceptRejectAllButtons({ const ideMessenger = useContext(IdeMessengerContext); const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEditOrInsertion); - async function handleAcceptOrReject(status: "acceptDiff" | "rejectDiff") { + async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { for (const { filepath, streamId } of pendingApplyStates) { ideMessenger.post(status, { filepath, @@ -27,9 +29,10 @@ export default function AcceptRejectAllButtons({ } if (onAcceptOrReject) { - onAcceptOrReject(); + onAcceptOrReject(status); } } + return (