diff --git a/.changes/header.tpl.md b/.changes/header.tpl.md index df8faa7b2..811d6f896 100644 --- a/.changes/header.tpl.md +++ b/.changes/header.tpl.md @@ -1,4 +1,3 @@ -# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), diff --git a/.changie.yaml b/.changie.yaml index de6d6890d..7a11e254d 100644 --- a/.changie.yaml +++ b/.changie.yaml @@ -33,7 +33,3 @@ projects: - label: extensions/vscode key: extensions/vscode changelog: extensions/vscode/CHANGELOG.md - - - label: docs - key: docs - changelog: docs/CHANGELOG.md # for releasing documents independently diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 5c2e27957..348fe493d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -21,15 +21,23 @@ body: attributes: label: Relevant environment info description: | + Feel free to omit any info that is not relevant to your issue. + - **OS**: e.g. macOS 14.2.1 - **Continue**: e.g. v0.9.4 - **IDE**: e.g. VSCode 1.85.1 - Include also your LLM Model if it is relevant to your issue - **Model**: e.g. Ollama v0.1.19 + - The contents of your config.json file (e.g. `~/.continue/config.json` on macOS) value: | - OS: - Continue: - IDE: + - Model: + - config.json: + ```json + + ``` render: Markdown validations: required: false diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4bb4e6de4..d7f772efb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,3 +6,7 @@ - [ ] The base branch of this PR is `dev`, rather than `main` - [ ] The relevant docs, if any, have been updated or created + +## Screenshots + +If your updates include visual changes, please share screenshots below. diff --git a/.github/workflows/ts-check.yaml b/.github/workflows/ts-check.yaml index 1b069db35..193988990 100644 --- a/.github/workflows/ts-check.yaml +++ b/.github/workflows/ts-check.yaml @@ -72,19 +72,19 @@ jobs: - name: tsc core run: | cd core - npx tsc + npx tsc --noEmit - name: tsc extensions/vscode run: | cd extensions/vscode - npx tsc + npx tsc --noEmit - name: tsc binary run: | cd binary - npx tsc + npx tsc --noEmit - name: tsc gui run: | cd gui - npx tsc + npx tsc --noEmit diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e1fa3e1b3..3850dd66b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -12,7 +12,9 @@ // To bundle the code the same way we do for publishing "vscode-extension:esbuild", // Start the React app that is used in the extension - "gui:dev" + "gui:dev", + // Start the docs site, without opening the browser + "docs:start" ], "group": { "kind": "build", @@ -159,7 +161,7 @@ "label": "docs:start", "type": "shell", "command": "npm", - "args": ["run", "start"], + "args": ["run", "start", "--", "--no-open"], "problemMatcher": [], "options": { "cwd": "docs" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b468f11f6..60d6200b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,21 +2,33 @@ ## Table of Contents +- [Contributing to Continue](#contributing-to-continue) + - [Table of Contents](#table-of-contents) - [❤️ Ways to Contribute](#️-ways-to-contribute) - [👋 Continue Contribution Ideas](#-continue-contribution-ideas) - [🐛 Report Bugs](#-report-bugs) - [✨ Suggest Enhancements](#-suggest-enhancements) - [📖 Updating / Improving Documentation](#-updating--improving-documentation) + - [Running the Documentation Server Locally](#running-the-documentation-server-locally) + - [Method 1: NPM Script](#method-1-npm-script) + - [Method 2: VS Code Task](#method-2-vs-code-task) - [🧑‍💻 Contributing Code](#-contributing-code) - [Environment Setup](#environment-setup) + - [Pre-requisites](#pre-requisites) + - [Fork the Continue Repository with All Branches](#fork-the-continue-repository-with-all-branches) + - [VS Code](#vs-code) + - [Debugging](#debugging) + - [JetBrains](#jetbrains) + - [Debugging](#debugging-1) + - [Formatting](#formatting) - [Writing Slash Commands](#writing-slash-commands) - [Writing Context Providers](#writing-context-providers) - [Adding an LLM Provider](#adding-an-llm-provider) - [Adding Models](#adding-models) - [Adding Pre-indexed Documentation](#adding-pre-indexed-documentation) -- [📐 Continue Architecture](#-continue-architecture) - - [Continue VS Code Extension](#continue-vs-code-extension) - - [Continue JetBrains Extension](#continue-jetbrains-extension) + - [📐 Continue Architecture](#-continue-architecture) + - [Continue VS Code Extension](#continue-vs-code-extension) + - [Continue JetBrains Extension](#continue-jetbrains-extension) # ❤️ Ways to Contribute @@ -50,9 +62,32 @@ Continue is quickly adding features, and we'd love to hear which are the most im Continue is continuously improving, but a feature isn't complete until it is reflected in the documentation! If you see something out-of-date or missing, you can help by clicking "Edit this page" at the bottom of any page on [docs.continue.dev](https://docs.continue.dev). +### Running the Documentation Server Locally + +You can run the documentation server locally using either of the following methods: + +#### Method 1: NPM Script + +1. Open your terminal and navigate to the root directory of the project. + +2. Run the following command to start the documentation server: + ```bash + npm run start --prefix docs + ``` + +#### Method 2: VS Code Task + +1. Open VS Code in the root directory of the project. + +2. Open the VS Code command pallet (`cmd/ctrl+shift+p`) and select `Tasks: Run Task`. + +3. Look for the `docs:start` task and select it. + +This will start a local server and you can see the documentation rendered in your default browser, typically accessible at `http://localhost:3000`. + ## 🧑‍💻 Contributing Code -> Please make PRs to the `preview` branch. We use this to first test changes in a pre-release version of the extension. +> Please make PRs to the `dev` branch. We use this to first test changes in a pre-release version of the extension. ### Environment Setup @@ -70,9 +105,9 @@ nvm use 2. Clone your forked repository to your local machine. Use: `git clone https://github.com/YOUR_USERNAME/continue.git` -3. Navigate to the cloned directory and switch to the **preview** branch. Execute: `git checkout preview`, then create your feature/fix branch from there, like so: `git checkout -b 123-my-feature-branch` +3. Navigate to the cloned directory and switch to the **dev** branch. Execute: `git checkout dev`, then create your feature/fix branch from there, like so: `git checkout -b 123-my-feature-branch` -4. When you're ready to submit your changes, send your pull request specifically to the **preview** branch. +4. When you're ready to submit your changes, send your pull request specifically to the **dev** branch. #### VS Code diff --git a/binary/src/IpcIde.ts b/binary/src/IpcIde.ts index 2be3bd354..ee2649c36 100644 --- a/binary/src/IpcIde.ts +++ b/binary/src/IpcIde.ts @@ -3,6 +3,6 @@ import { MessageIde } from "core/util/messageIde"; export class IpcIde extends MessageIde { constructor(messenger: TODO) { - super(messenger.request.bind(messenger)); + super(messenger.request.bind(messenger), messenger.on.bind(messenger)); } } diff --git a/core/autocomplete/ImportDefinitionsService.ts b/core/autocomplete/ImportDefinitionsService.ts new file mode 100644 index 000000000..19287bf81 --- /dev/null +++ b/core/autocomplete/ImportDefinitionsService.ts @@ -0,0 +1,81 @@ +import { IDE } from ".."; +import { RangeInFileWithContents } from "../commands/util"; +import { PrecalculatedLruCache } from "../util/LruCache"; +import { + TSQueryType, + getParserForFile, + getQueryForFile, +} from "../util/treeSitter"; + +interface FileInfo { + imports: { [key: string]: RangeInFileWithContents[] }; +} + +export class ImportDefinitionsService { + static N = 10; + + private cache: PrecalculatedLruCache = + new PrecalculatedLruCache( + this._getFileInfo.bind(this), + ImportDefinitionsService.N, + ); + + constructor(private readonly ide: IDE) { + ide.onDidChangeActiveTextEditor((filepath) => { + this.cache.initKey(filepath); + }); + } + + get(filepath: string): FileInfo | undefined { + return this.cache.get(filepath); + } + + private async _getFileInfo(filepath: string): Promise { + const parser = await getParserForFile(filepath); + if (!parser) { + return { + imports: {}, + }; + } + const ast = parser.parse(await this.ide.readFile(filepath), undefined, { + includedRanges: [ + { + startIndex: 0, + endIndex: 10_000, + startPosition: { row: 0, column: 0 }, + endPosition: { row: 100, column: 0 }, + }, + ], + }); + const query = await getQueryForFile(filepath, TSQueryType.Imports); + if (!query) { + return { + imports: {}, + }; + } + + const matches = query?.matches(ast.rootNode); + + const fileInfo: FileInfo = { + imports: {}, + }; + for (const match of matches) { + const startPosition = match.captures[0].node.startPosition; + const defs = await this.ide.gotoDefinition({ + filepath, + position: { + line: startPosition.row, + character: startPosition.column, + }, + }); + fileInfo.imports[match.captures[0].node.text] = await Promise.all( + defs.map(async (def) => ({ + ...def, + contents: await this.ide.readRangeInFile(def.filepath, def.range), + })), + ); + } + + return fileInfo; + } +} diff --git a/core/autocomplete/NearbyDefinitionsService.ts b/core/autocomplete/NearbyDefinitionsService.ts new file mode 100644 index 000000000..79cd0af0a --- /dev/null +++ b/core/autocomplete/NearbyDefinitionsService.ts @@ -0,0 +1,45 @@ +import { IDE, Location } from ".."; +import { LANGUAGES } from "./languages"; +import { getSymbolsForSnippet } from "./ranking"; + +interface FileInfo { + filepath: string; +} + +export class NearbyDefinitionsService { + static N = 10; + + constructor(private readonly ide: IDE) {} + + async getDefinitionsForLine(filepath: string, line: number) { + const lineContent = await this.ide.readRangeInFile(filepath, { + start: { + line, + character: 0, + }, + end: { + line: line + 1, + character: 0, + }, + }); + + // Remove keywords + const lang = LANGUAGES[filepath.split(".").slice(-1)[0]]; + const symbols = Array.from(getSymbolsForSnippet(lineContent)) + .filter((s) => s.length > 0) + .filter((s) => !(lang && lang?.stopWords?.includes(s))); + + return Promise.all( + symbols.map((s) => { + const character = lineContent.indexOf(s); + const pos: Location = { + filepath, + position: { + line, + character, + }, + }; + }), + ); + } +} diff --git a/core/autocomplete/completionProvider.ts b/core/autocomplete/completionProvider.ts index 873515bf5..de235aca5 100644 --- a/core/autocomplete/completionProvider.ts +++ b/core/autocomplete/completionProvider.ts @@ -1,5 +1,6 @@ import Handlebars from "handlebars"; import ignore from "ignore"; +import OpenAI from "openai"; import path from "path"; import { v4 as uuidv4 } from "uuid"; import { RangeInFileWithContents } from "../commands/util.js"; @@ -14,7 +15,6 @@ import { Range, TabAutocompleteOptions, } from "../index.js"; -import OpenAI from "../llm/llms/OpenAI.js"; import { logDevData } from "../util/devdata.js"; import { getBasename, getLastNPathParts } from "../util/index.js"; import { @@ -23,6 +23,7 @@ import { } from "../util/parameters.js"; import { Telemetry } from "../util/posthog.js"; import { getRangeInString } from "../util/ranges.js"; +import { ImportDefinitionsService } from "./ImportDefinitionsService.js"; import { BracketMatchingService } from "./brackets.js"; import AutocompleteLruCache from "./cache.js"; import { @@ -138,342 +139,6 @@ export type GetLspDefinitionsFunction = ( lang: AutocompleteLanguageInfo, ) => Promise; -export async function getTabCompletion( - token: AbortSignal, - options: TabAutocompleteOptions, - llm: ILLM, - ide: IDE, - generatorReuseManager: GeneratorReuseManager, - input: AutocompleteInput, - getDefinitionsFromLsp: GetLspDefinitionsFunction, - bracketMatchingService: BracketMatchingService, -): Promise { - const startTime = Date.now(); - - const { - filepath, - pos, - recentlyEditedFiles, - recentlyEditedRanges, - clipboardText, - manuallyPassFileContents, - manuallyPassPrefix, - } = input; - const fileContents = - manuallyPassFileContents ?? (await ide.readFile(filepath)); - const fileLines = fileContents.split("\n"); - - // Filter - const lang = languageForFilepath(filepath); - const line = fileLines[pos.line] ?? ""; - for (const endOfLine of lang.endOfLine) { - if (line.endsWith(endOfLine) && pos.character >= line.length) { - return undefined; - } - } - - // Model - if (!llm) { - return; - } - if (llm instanceof OpenAI) { - llm.useLegacyCompletionsEndpoint = true; - } else if ( - llm.providerName === "free-trial" && - llm.model !== TRIAL_FIM_MODEL - ) { - llm.model = TRIAL_FIM_MODEL; - } - - if ( - !shownGptClaudeWarning && - nonAutocompleteModels.some((model) => llm.model.includes(model)) && - !llm.model.includes("deepseek") - ) { - shownGptClaudeWarning = true; - throw new Error( - `Warning: ${llm.model} is not trained for tab-autocomplete, and will result in low-quality suggestions. See the docs to learn more about why: https://docs.continue.dev/walkthroughs/tab-autocomplete#i-want-better-completions-should-i-use-gpt-4`, - ); - } - - // Prompt - let fullPrefix = - getRangeInString(fileContents, { - start: { line: 0, character: 0 }, - end: input.selectedCompletionInfo?.range.start ?? pos, - }) + (input.selectedCompletionInfo?.text ?? ""); - - if (input.injectDetails) { - const lines = fullPrefix.split("\n"); - fullPrefix = `${lines.slice(0, -1).join("\n")}\n${ - lang.singleLineComment - } ${input.injectDetails.split("\n").join(`\n${lang.singleLineComment} `)}\n${ - lines[lines.length - 1] - }`; - } - - const fullSuffix = getRangeInString(fileContents, { - start: pos, - end: { line: fileLines.length - 1, character: Number.MAX_SAFE_INTEGER }, - }); - - // First non-whitespace line below the cursor - let lineBelowCursor = ""; - let i = 1; - while ( - lineBelowCursor.trim() === "" && - pos.line + i <= fileLines.length - 1 - ) { - lineBelowCursor = fileLines[Math.min(pos.line + i, fileLines.length - 1)]; - i++; - } - - let extrasSnippets = options.useOtherFiles - ? ((await Promise.race([ - getDefinitionsFromLsp( - filepath, - fullPrefix + fullSuffix, - fullPrefix.length, - ide, - lang, - ), - new Promise((resolve) => { - setTimeout(() => resolve([]), 100); - }), - ])) as AutocompleteSnippet[]) - : []; - - const workspaceDirs = await ide.getWorkspaceDirs(); - if (options.onlyMyCode) { - extrasSnippets = extrasSnippets.filter((snippet) => { - return workspaceDirs.some((dir) => snippet.filepath.startsWith(dir)); - }); - } - - let { prefix, suffix, completeMultiline, snippets } = - await constructAutocompletePrompt( - filepath, - pos.line, - fullPrefix, - fullSuffix, - clipboardText, - lang, - options, - recentlyEditedRanges, - recentlyEditedFiles, - llm.model, - extrasSnippets, - ); - - // If prefix is manually passed - if (manuallyPassPrefix) { - prefix = manuallyPassPrefix; - suffix = ""; - } - - // Template prompt - const { - template, - completionOptions, - compilePrefixSuffix = undefined, - } = options.template - ? { template: options.template, completionOptions: {} } - : getTemplateForModel(llm.model); - - let prompt: string; - const filename = getBasename(filepath); - const reponame = getBasename(workspaceDirs[0] ?? "myproject"); - - // Some models have prompts that need two passes. This lets us pass the compiled prefix/suffix - // into either the 2nd template to generate a raw string, or to pass prefix, suffix to a FIM endpoint - if (compilePrefixSuffix) { - [prefix, suffix] = compilePrefixSuffix( - prefix, - suffix, - filepath, - reponame, - snippets, - ); - } - - if (typeof template === "string") { - const compiledTemplate = Handlebars.compile(template); - - // Format snippets as comments and prepend to prefix - const formattedSnippets = snippets - .map((snippet) => - formatExternalSnippet(snippet.filepath, snippet.contents, lang), - ) - .join("\n"); - if (formattedSnippets.length > 0) { - prefix = `${formattedSnippets}\n\n${prefix}`; - } else if (prefix.trim().length === 0 && suffix.trim().length === 0) { - // If it's an empty file, include the file name as a comment - prefix = `${lang.singleLineComment} ${getLastNPathParts(filepath, 2)}\n${prefix}`; - } - - prompt = compiledTemplate({ - prefix, - suffix, - filename, - reponame, - }); - } else { - // Let the template function format snippets - prompt = template(prefix, suffix, filepath, reponame, snippets); - } - - // Completion - let completion = ""; - - const cache = await autocompleteCache; - const cachedCompletion = options.useCache - ? await cache.get(prefix) - : undefined; - let cacheHit = false; - if (cachedCompletion) { - // Cache - cacheHit = true; - completion = cachedCompletion; - } else { - const stop = [ - ...(completionOptions?.stop || []), - ...multilineStops, - ...commonStops, - ...(llm.model.toLowerCase().includes("starcoder2") - ? STARCODER2_T_ARTIFACTS - : []), - ...(lang.stopWords ?? []), - ...lang.topLevelKeywords.map((word) => `\n${word}`), - ]; - - let langMultilineDecision = lang.useMultiline?.({ prefix, suffix }); - let multiline: boolean = false; - if (langMultilineDecision) { - multiline = langMultilineDecision; - } else { - multiline = - !input.selectedCompletionInfo && // Only ever single-line if using intellisense selected value - options.multilineCompletions !== "never" && - (options.multilineCompletions === "always" || completeMultiline); - } - - // Try to reuse pending requests if what the user typed matches start of completion - const generator = generatorReuseManager.getGenerator( - prefix, - () => - llm.supportsFim() - ? llm.streamFim(prefix, suffix, { - ...completionOptions, - stop, - }) - : llm.streamComplete(prompt, { - ...completionOptions, - raw: true, - stop, - }), - multiline, - ); - - // Full stop means to stop the LLM's generation, instead of just truncating the displayed completion - const fullStop = () => generatorReuseManager.currentGenerator?.cancel(); - - // LLM - let cancelled = false; - const generatorWithCancellation = async function* () { - for await (const update of generator) { - if (token.aborted) { - cancelled = true; - return; - } - yield update; - } - }; - let charGenerator = generatorWithCancellation(); - charGenerator = noFirstCharNewline(charGenerator); - charGenerator = onlyWhitespaceAfterEndOfLine( - charGenerator, - lang.endOfLine, - fullStop, - ); - charGenerator = bracketMatchingService.stopOnUnmatchedClosingBracket( - charGenerator, - prefix, - suffix, - filepath, - multiline, - ); - - let lineGenerator = streamLines(charGenerator); - lineGenerator = stopAtLines(lineGenerator, fullStop); - lineGenerator = stopAtRepeatingLines(lineGenerator, fullStop); - lineGenerator = avoidPathLine(lineGenerator, lang.singleLineComment); - lineGenerator = skipPrefixes(lineGenerator); - lineGenerator = noTopLevelKeywordsMidline( - lineGenerator, - lang.topLevelKeywords, - fullStop, - ); - - for (const lineFilter of lang.lineFilters ?? []) { - lineGenerator = lineFilter({ lines: lineGenerator, fullStop }); - } - - lineGenerator = streamWithNewLines(lineGenerator); - - const finalGenerator = stopAtSimilarLine( - lineGenerator, - lineBelowCursor, - fullStop, - ); - - try { - for await (const update of finalGenerator) { - completion += update; - } - } catch (e: any) { - if (ERRORS_TO_IGNORE.some((err) => e.includes(err))) { - return undefined; - } - throw e; - } - - if (cancelled) { - return undefined; - } - - const processedCompletion = postprocessCompletion({ - completion, - prefix, - suffix, - llm, - }); - - if (!processedCompletion) { - return undefined; - } - completion = processedCompletion; - } - - const time = Date.now() - startTime; - return { - time, - completion, - prefix, - suffix, - prompt, - modelProvider: llm.providerName, - modelName: llm.model, - completionOptions, - cacheHit, - filepath: input.filepath, - completionId: input.completionId, - gitRepo: await ide.getRepoName(input.filepath), - uniqueId: await ide.getUniqueId(), - ...options, - }; -} - export class CompletionProvider { private static debounceTimeout: NodeJS.Timeout | undefined = undefined; private static debouncing = false; @@ -489,12 +154,15 @@ export class CompletionProvider { this.generatorReuseManager = new GeneratorReuseManager( this.onError.bind(this), ); + this.importDefinitionsService = new ImportDefinitionsService(this.ide); } + private importDefinitionsService: ImportDefinitionsService; private generatorReuseManager: GeneratorReuseManager; private autocompleteCache = AutocompleteLruCache.get(); public errorsShown: Set = new Set(); private bracketMatchingService = new BracketMatchingService(); + // private nearbyDefinitionsService = new NearbyDefinitionsService(); private onError(e: any) { console.warn("Error generating autocompletion: ", e); @@ -654,16 +322,7 @@ export class CompletionProvider { options.maxPromptTokens = 500; } - const outcome = await getTabCompletion( - token, - options, - llm, - this.ide, - this.generatorReuseManager, - input, - this.getDefinitionsFromLsp, - this.bracketMatchingService, - ); + const outcome = await this.getTabCompletion(token, options, llm, input); if (!outcome?.completion) { return undefined; @@ -735,4 +394,339 @@ export class CompletionProvider { displayedAt: now, }; } + + async getTabCompletion( + token: AbortSignal, + options: TabAutocompleteOptions, + llm: ILLM, + input: AutocompleteInput, + ): Promise { + const startTime = Date.now(); + + const { + filepath, + pos, + recentlyEditedFiles, + recentlyEditedRanges, + clipboardText, + manuallyPassFileContents, + manuallyPassPrefix, + } = input; + const fileContents = + manuallyPassFileContents ?? (await this.ide.readFile(filepath)); + const fileLines = fileContents.split("\n"); + + // Filter + const lang = languageForFilepath(filepath); + const line = fileLines[pos.line] ?? ""; + for (const endOfLine of lang.endOfLine) { + if (line.endsWith(endOfLine) && pos.character >= line.length) { + return undefined; + } + } + + // Model + if (!llm) { + return; + } + if (llm instanceof OpenAI) { + llm.useLegacyCompletionsEndpoint = true; + } else if ( + llm.providerName === "free-trial" && + llm.model !== TRIAL_FIM_MODEL + ) { + llm.model = TRIAL_FIM_MODEL; + } + + if ( + !shownGptClaudeWarning && + nonAutocompleteModels.some((model) => llm.model.includes(model)) && + !llm.model.includes("deepseek") && + !llm.model.includes("codestral") + ) { + shownGptClaudeWarning = true; + throw new Error( + `Warning: ${llm.model} is not trained for tab-autocomplete, and will result in low-quality suggestions. See the docs to learn more about why: https://docs.continue.dev/walkthroughs/tab-autocomplete#i-want-better-completions-should-i-use-gpt-4`, + ); + } + + // Prompt + let fullPrefix = + getRangeInString(fileContents, { + start: { line: 0, character: 0 }, + end: input.selectedCompletionInfo?.range.start ?? pos, + }) + (input.selectedCompletionInfo?.text ?? ""); + + if (input.injectDetails) { + const lines = fullPrefix.split("\n"); + fullPrefix = `${lines.slice(0, -1).join("\n")}\n${ + lang.singleLineComment + } ${input.injectDetails.split("\n").join(`\n${lang.singleLineComment} `)}\n${ + lines[lines.length - 1] + }`; + } + + const fullSuffix = getRangeInString(fileContents, { + start: pos, + end: { line: fileLines.length - 1, character: Number.MAX_SAFE_INTEGER }, + }); + + // First non-whitespace line below the cursor + let lineBelowCursor = ""; + let i = 1; + while ( + lineBelowCursor.trim() === "" && + pos.line + i <= fileLines.length - 1 + ) { + lineBelowCursor = fileLines[Math.min(pos.line + i, fileLines.length - 1)]; + i++; + } + + let extrasSnippets = options.useOtherFiles + ? ((await Promise.race([ + this.getDefinitionsFromLsp( + filepath, + fullPrefix + fullSuffix, + fullPrefix.length, + this.ide, + lang, + ), + new Promise((resolve) => { + setTimeout(() => resolve([]), 100); + }), + ])) as AutocompleteSnippet[]) + : []; + + const workspaceDirs = await this.ide.getWorkspaceDirs(); + if (options.onlyMyCode) { + extrasSnippets = extrasSnippets.filter((snippet) => { + return workspaceDirs.some((dir) => snippet.filepath.startsWith(dir)); + }); + } + + let { prefix, suffix, completeMultiline, snippets } = + await constructAutocompletePrompt( + filepath, + pos.line, + fullPrefix, + fullSuffix, + clipboardText, + lang, + options, + recentlyEditedRanges, + recentlyEditedFiles, + llm.model, + extrasSnippets, + this.importDefinitionsService, + ); + + // If prefix is manually passed + if (manuallyPassPrefix) { + prefix = manuallyPassPrefix; + suffix = ""; + } + + // Template prompt + const { + template, + completionOptions, + compilePrefixSuffix = undefined, + } = options.template + ? { template: options.template, completionOptions: {} } + : getTemplateForModel(llm.model); + + let prompt: string; + const filename = getBasename(filepath); + const reponame = getBasename(workspaceDirs[0] ?? "myproject"); + + // Some models have prompts that need two passes. This lets us pass the compiled prefix/suffix + // into either the 2nd template to generate a raw string, or to pass prefix, suffix to a FIM endpoint + if (compilePrefixSuffix) { + [prefix, suffix] = compilePrefixSuffix( + prefix, + suffix, + filepath, + reponame, + snippets, + ); + } + + if (typeof template === "string") { + const compiledTemplate = Handlebars.compile(template); + + // Format snippets as comments and prepend to prefix + const formattedSnippets = snippets + .map((snippet) => + formatExternalSnippet(snippet.filepath, snippet.contents, lang), + ) + .join("\n"); + if (formattedSnippets.length > 0) { + prefix = `${formattedSnippets}\n\n${prefix}`; + } else if (prefix.trim().length === 0 && suffix.trim().length === 0) { + // If it's an empty file, include the file name as a comment + prefix = `${lang.singleLineComment} ${getLastNPathParts(filepath, 2)}\n${prefix}`; + } + + prompt = compiledTemplate({ + prefix, + suffix, + filename, + reponame, + }); + } else { + // Let the template function format snippets + prompt = template(prefix, suffix, filepath, reponame, snippets); + } + + // Completion + let completion = ""; + + const cache = await autocompleteCache; + const cachedCompletion = options.useCache + ? await cache.get(prefix) + : undefined; + let cacheHit = false; + if (cachedCompletion) { + // Cache + cacheHit = true; + completion = cachedCompletion; + } else { + const stop = [ + ...(completionOptions?.stop || []), + ...multilineStops, + ...commonStops, + ...(llm.model.toLowerCase().includes("starcoder2") + ? STARCODER2_T_ARTIFACTS + : []), + ...(lang.stopWords ?? []), + ...lang.topLevelKeywords.map((word) => `\n${word}`), + ]; + + let langMultilineDecision = lang.useMultiline?.({ prefix, suffix }); + let multiline: boolean = false; + if (langMultilineDecision) { + multiline = langMultilineDecision; + } else { + multiline = + !input.selectedCompletionInfo && // Only ever single-line if using intellisense selected value + options.multilineCompletions !== "never" && + (options.multilineCompletions === "always" || completeMultiline); + } + + // Try to reuse pending requests if what the user typed matches start of completion + const generator = this.generatorReuseManager.getGenerator( + prefix, + () => + llm.supportsFim() + ? llm.streamFim(prefix, suffix, { + ...completionOptions, + stop, + }) + : llm.streamComplete(prompt, { + ...completionOptions, + raw: true, + stop, + }), + multiline, + ); + + // Full stop means to stop the LLM's generation, instead of just truncating the displayed completion + const fullStop = () => + this.generatorReuseManager.currentGenerator?.cancel(); + + // LLM + let cancelled = false; + const generatorWithCancellation = async function* () { + for await (const update of generator) { + if (token.aborted) { + cancelled = true; + return; + } + yield update; + } + }; + let charGenerator = generatorWithCancellation(); + charGenerator = noFirstCharNewline(charGenerator); + charGenerator = onlyWhitespaceAfterEndOfLine( + charGenerator, + lang.endOfLine, + fullStop, + ); + charGenerator = this.bracketMatchingService.stopOnUnmatchedClosingBracket( + charGenerator, + prefix, + suffix, + filepath, + multiline, + ); + + let lineGenerator = streamLines(charGenerator); + lineGenerator = stopAtLines(lineGenerator, fullStop); + lineGenerator = stopAtRepeatingLines(lineGenerator, fullStop); + lineGenerator = avoidPathLine(lineGenerator, lang.singleLineComment); + lineGenerator = skipPrefixes(lineGenerator); + lineGenerator = noTopLevelKeywordsMidline( + lineGenerator, + lang.topLevelKeywords, + fullStop, + ); + + for (const lineFilter of lang.lineFilters ?? []) { + lineGenerator = lineFilter({ lines: lineGenerator, fullStop }); + } + + lineGenerator = streamWithNewLines(lineGenerator); + + const finalGenerator = stopAtSimilarLine( + lineGenerator, + lineBelowCursor, + fullStop, + ); + + try { + for await (const update of finalGenerator) { + completion += update; + } + } catch (e: any) { + if (ERRORS_TO_IGNORE.some((err) => e.includes(err))) { + return undefined; + } + throw e; + } + + if (cancelled) { + return undefined; + } + + const processedCompletion = postprocessCompletion({ + completion, + prefix, + suffix, + llm, + }); + + if (!processedCompletion) { + return undefined; + } + completion = processedCompletion; + } + + const time = Date.now() - startTime; + return { + time, + completion, + prefix, + suffix, + prompt, + modelProvider: llm.providerName, + modelName: llm.model, + completionOptions, + cacheHit, + filepath: input.filepath, + completionId: input.completionId, + gitRepo: await this.ide.getRepoName(input.filepath), + uniqueId: await this.ide.getUniqueId(), + ...options, + }; + } } diff --git a/core/autocomplete/constructPrompt.ts b/core/autocomplete/constructPrompt.ts index 6f97e75ac..cf5b07e44 100644 --- a/core/autocomplete/constructPrompt.ts +++ b/core/autocomplete/constructPrompt.ts @@ -7,6 +7,7 @@ import { pruneLinesFromBottom, pruneLinesFromTop, } from "../llm/countTokens.js"; +import { ImportDefinitionsService } from "./ImportDefinitionsService.js"; import { getAst, getTreePathAtCursor } from "./ast.js"; import { AutocompleteLanguageInfo, @@ -15,6 +16,7 @@ import { } from "./languages.js"; import { fillPromptWithSnippets, + getSymbolsForSnippet, rankSnippets, removeRangeFromSnippets, type AutocompleteSnippet, @@ -124,6 +126,7 @@ export async function constructAutocompletePrompt( recentlyEditedFiles: RangeInFileWithContents[], modelName: string, extraSnippets: AutocompleteSnippet[], + importDefinitionsService: ImportDefinitionsService, ): Promise<{ prefix: string; suffix: string; @@ -189,6 +192,29 @@ export async function constructAutocompletePrompt( } } + // Use imports + if (options.useImports) { + const importSnippets = []; + const fileInfo = importDefinitionsService.get(filepath); + if (fileInfo) { + const { imports } = fileInfo; + // Look for imports of any symbols around the current range + const textAroundCursor = + fullPrefix.split("\n").slice(-5).join("\n") + + fullSuffix.split("\n").slice(0, 3).join("\n"); + const symbols = Array.from( + getSymbolsForSnippet(textAroundCursor), + ).filter((symbol) => !language.topLevelKeywords.includes(symbol)); + for (const symbol of symbols) { + const rifs = imports[symbol]; + if (Array.isArray(rifs)) { + importSnippets.push(...rifs); + } + } + } + snippets.push(...importSnippets); + } + // Filter out empty snippets and ones that are already in the prefix/suffix snippets = snippets .map((snippet) => ({ ...snippet })) diff --git a/core/autocomplete/postprocessing.ts b/core/autocomplete/postprocessing.ts index 724c826f2..958c1cdff 100644 --- a/core/autocomplete/postprocessing.ts +++ b/core/autocomplete/postprocessing.ts @@ -97,5 +97,10 @@ export function postprocessCompletion({ completion = completion.slice(1); } + // Qwen often adds an extra space to the start + if (llm.model.toLowerCase().includes("qwen") && completion.startsWith(" ")) { + completion = completion.slice(1); + } + return completion; } diff --git a/core/autocomplete/templates.ts b/core/autocomplete/templates.ts index 46c60ca6b..4de43739a 100644 --- a/core/autocomplete/templates.ts +++ b/core/autocomplete/templates.ts @@ -34,6 +34,8 @@ const stableCodeFimTemplate: AutocompleteTemplate = { "", "<|endoftext|>", "", + "", + "", ], }, }; diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index af64b0933..44ae2c9ed 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -252,7 +252,7 @@ const EditSlashCommand: SlashCommand = { ); // if the above replace fails to find a match, the code will still be present // in the userInput. Replace it with input if available. - if (userInput.includes("\`\`\`") && (input !== "" || !input)) { + if (userInput.includes("```") && (input !== "" || !input)) { userInput = input; } diff --git a/core/config/handler.ts b/core/config/handler.ts index 0fd2c0503..bc340b994 100644 --- a/core/config/handler.ts +++ b/core/config/handler.ts @@ -40,14 +40,16 @@ export class ConfigHandler { this.updateListeners.push(listener); } - reloadConfig() { + async reloadConfig() { this.savedConfig = undefined; this.savedBrowserConfig = undefined; - this.loadConfig().then(() => { - for (const listener of this.updateListeners) { - listener(); - } - }); + this._pendingConfigPromise = undefined; + + await this.loadConfig(); + + for (const listener of this.updateListeners) { + listener(); + } } async getSerializedConfig(): Promise { @@ -58,45 +60,56 @@ export class ConfigHandler { return this.savedBrowserConfig; } + private _pendingConfigPromise?: Promise; async loadConfig(): Promise { if (this.savedConfig) { return this.savedConfig; + } else if (this._pendingConfigPromise) { + return this._pendingConfigPromise; } - let workspaceConfigs: ContinueRcJson[] = []; - try { - workspaceConfigs = await this.ide.getWorkspaceConfigs(); - } catch (e) { - console.warn("Failed to load workspace configs"); - } + this._pendingConfigPromise = new Promise(async (resolve, reject) => { + let workspaceConfigs: ContinueRcJson[] = []; + try { + workspaceConfigs = await this.ide.getWorkspaceConfigs(); + } catch (e) { + console.warn("Failed to load workspace configs"); + } - const ideInfo = await this.ide.getIdeInfo(); - const uniqueId = await this.ide.getUniqueId(); - const ideSettings = await this.ideSettingsPromise; + const ideInfo = await this.ide.getIdeInfo(); + const uniqueId = await this.ide.getUniqueId(); + const ideSettings = await this.ideSettingsPromise; - const newConfig = await loadFullConfigNode( - this.ide, - workspaceConfigs, - ideSettings, - ideInfo.ideType, - uniqueId, - this.writeLog, - ); - newConfig.allowAnonymousTelemetry = - newConfig.allowAnonymousTelemetry && - (await this.ide.isTelemetryEnabled()); + const newConfig = await loadFullConfigNode( + this.ide, + workspaceConfigs, + ideSettings, + ideInfo.ideType, + uniqueId, + this.writeLog, + ); + newConfig.allowAnonymousTelemetry = + newConfig.allowAnonymousTelemetry && + (await this.ide.isTelemetryEnabled()); - // Setup telemetry only after (and if) we know it is enabled - await Telemetry.setup( - newConfig.allowAnonymousTelemetry ?? true, - await this.ide.getUniqueId(), - ideInfo.extensionVersion, - ); + // Setup telemetry only after (and if) we know it is enabled + await Telemetry.setup( + newConfig.allowAnonymousTelemetry ?? true, + await this.ide.getUniqueId(), + ideInfo.extensionVersion, + ); - (newConfig.contextProviders ?? []).push(...this.additionalContextProviders); + (newConfig.contextProviders ?? []).push( + ...this.additionalContextProviders, + ); - this.savedConfig = newConfig; - return newConfig; + this.savedConfig = newConfig; + resolve(newConfig); + }); + + this.savedConfig = await this._pendingConfigPromise; + this._pendingConfigPromise = undefined; + return this.savedConfig; } async llmFromTitle(title?: string): Promise { diff --git a/core/config/onboarding.ts b/core/config/onboarding.ts index 0f3abe3e0..c1062e421 100644 --- a/core/config/onboarding.ts +++ b/core/config/onboarding.ts @@ -2,6 +2,7 @@ import { SerializedContinueConfig } from "../index.js"; import { FREE_TRIAL_MODELS } from "./default.js"; export const TRIAL_FIM_MODEL = "codestral-latest"; +export const ONBOARDING_LOCAL_MODEL_TITLE = "Ollama"; export function setupApiKeysMode( config: SerializedContinueConfig, @@ -23,25 +24,6 @@ export function setupApiKeysMode( }; } -export function setupOptimizedExistingUserMode( - config: SerializedContinueConfig, -): SerializedContinueConfig { - return { - ...config, - tabAutocompleteModel: { - title: "Tab Autocomplete", - provider: "free-trial", - model: TRIAL_FIM_MODEL, - }, - embeddingsProvider: { - provider: "free-trial", - }, - reranker: { - name: "free-trial", - }, - }; -} - export function setupLocalMode( config: SerializedContinueConfig, ): SerializedContinueConfig { @@ -54,7 +36,7 @@ export function setupLocalMode( model: "llama3", }, { - title: "Ollama", + title: ONBOARDING_LOCAL_MODEL_TITLE, provider: "ollama", model: "AUTODETECT", }, @@ -66,7 +48,8 @@ export function setupLocalMode( model: "starcoder2:3b", }, embeddingsProvider: { - provider: "transformers.js", + provider: "ollama", + model: "nomic-embed-text", }, reranker: undefined, }; @@ -107,7 +90,7 @@ export function setupLocalAfterFreeTrial( model: "llama3", }, { - title: "Ollama", + title: ONBOARDING_LOCAL_MODEL_TITLE, provider: "ollama", model: "AUTODETECT", }, diff --git a/core/config/promptFile.ts b/core/config/promptFile.ts index b842577ff..d691fb22a 100644 --- a/core/config/promptFile.ts +++ b/core/config/promptFile.ts @@ -1,3 +1,4 @@ +import Handlebars from "handlebars"; import path from "path"; import * as YAML from "yaml"; import type { IDE, SlashCommand } from ".."; diff --git a/core/context/providers/CodeOutlineContextProvider.ts b/core/context/providers/CodeOutlineContextProvider.ts index 2280bbd92..85781446e 100644 --- a/core/context/providers/CodeOutlineContextProvider.ts +++ b/core/context/providers/CodeOutlineContextProvider.ts @@ -6,8 +6,6 @@ import { import { getBasename } from "../../util/index.js"; import { BaseContextProvider } from "../index.js"; -// import { getOutlines } from "llm-code-highlighter/dist/index.continue"; - class CodeOutlineContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "outline", diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index 19bf88f36..72c47f044 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -1,7 +1,6 @@ import { ContextProviderName } from "../../index.js"; import { BaseContextProvider } from "../index.js"; import CodeContextProvider from "./CodeContextProvider.js"; -// import CodeHighlightsContextProvider from "./CodeHighlightsContextProvider.js"; import CodebaseContextProvider from "./CodebaseContextProvider.js"; import CurrentFileContextProvider from "./CurrentFileContextProvider.js"; import DatabaseContextProvider from "./DatabaseContextProvider.js"; @@ -23,6 +22,13 @@ import SearchContextProvider from "./SearchContextProvider.js"; import TerminalContextProvider from "./TerminalContextProvider.js"; import URLContextProvider from "./URLContextProvider.js"; +/** + * Note: We are currently omitting the following providers due to bugs: + * - `CodeOutlineContextProvider` + * - `CodeHighlightsContextProvider` + * + * See this issue for details: https://github.com/continuedev/continue/issues/1365 + */ const Providers: (typeof BaseContextProvider)[] = [ DiffContextProvider, FileTreeContextProvider, @@ -39,8 +45,6 @@ const Providers: (typeof BaseContextProvider)[] = [ FolderContextProvider, DocsContextProvider, GitLabMergeRequestContextProvider, - // CodeHighlightsContextProvider, - // CodeOutlineContextProvider, JiraIssuesContextProvider, PostgresContextProvider, DatabaseContextProvider, diff --git a/core/core.ts b/core/core.ts index 87af833f5..26c0dc428 100644 --- a/core/core.ts +++ b/core/core.ts @@ -12,9 +12,8 @@ import { setupFreeTrialMode, setupLocalAfterFreeTrial, setupLocalMode, - setupOptimizedExistingUserMode, } from "./config/onboarding.js"; -import { createNewPromptFile } from "./config/promptFile"; +import { createNewPromptFile } from "./config/promptFile.js"; import { addModel, addOpenAIKey, deleteModel } from "./config/util.js"; import { ContinueServerClient } from "./continueServer/stubs/client.js"; import { indexDocs } from "./indexing/docs/index.js"; @@ -221,7 +220,7 @@ export class Core { new TransformersJsEmbeddingsProvider(), )) { } - this.ide.infoPopup(`🎉 Successfully indexed ${msg.data.title}`); + this.ide.infoPopup(`Successfully indexed ${msg.data.title}`); this.messenger.send("refreshSubmenuItems", undefined); }); on("context/loadSubmenuItems", async (msg) => { @@ -364,20 +363,20 @@ export class Core { const model = config.models.find((model) => model.title === msg.data.title) ?? config.models.find((model) => model.title?.startsWith(msg.data.title)); - if (model) { - return model.listModels(); - } else { - if (msg.data.title === "Ollama") { - try { + try { + if (model) { + return model.listModels(); + } else { + if (msg.data.title === "Ollama") { const models = await new Ollama({ model: "" }).listModels(); return models; - } catch (e) { - console.warn(`Error listing Ollama models: ${e}`); + } else { return undefined; } - } else { - return undefined; } + } catch (e) { + console.warn(`Error listing Ollama models: ${e}`); + return undefined; } }); @@ -411,6 +410,13 @@ export class Core { name: slashCommandName, }); + const checkActiveInterval = setInterval(() => { + if (abortedMessageIds.has(msg.messageId)) { + abortedMessageIds.delete(msg.messageId); + clearInterval(checkActiveInterval); + } + }, 100); + for await (const content of slashCommand.run({ input, history, @@ -429,10 +435,15 @@ export class Core { fetch: (url, init) => fetchwithRequestOptions(url, init, config.requestOptions), })) { + if (abortedMessageIds.has(msg.messageId)) { + abortedMessageIds.delete(msg.messageId); + break; + } if (content) { yield { content }; } } + clearInterval(checkActiveInterval); yield { done: true, content: "" }; } on("command/run", (msg) => @@ -490,23 +501,41 @@ export class Core { on("completeOnboarding", (msg) => { const mode = msg.data.mode; + Telemetry.capture("onboardingSelection", { mode, }); - if (mode === "custom" || mode === "localExistingUser") { + + if (mode === "custom") { return; } - editConfigJson( - mode === "local" - ? setupLocalMode - : mode === "freeTrial" - ? setupFreeTrialMode - : mode === "localAfterFreeTrial" - ? setupLocalAfterFreeTrial - : mode === "apiKeys" - ? setupApiKeysMode - : setupOptimizedExistingUserMode, - ); + + let editConfigJsonCallback: Parameters[0]; + + switch (mode) { + case "local": + editConfigJsonCallback = setupLocalMode; + break; + + case "freeTrial": + editConfigJsonCallback = setupFreeTrialMode; + break; + + case "localAfterFreeTrial": + editConfigJsonCallback = setupLocalAfterFreeTrial; + break; + + case "apiKeys": + editConfigJsonCallback = setupApiKeysMode; + break; + + default: + console.error(`Invalid mode: ${mode}`); + editConfigJsonCallback = (config) => config; + } + + editConfigJson(editConfigJsonCallback); + this.configHandler.reloadConfig(); }); @@ -539,7 +568,7 @@ export class Core { on("index/indexingProgressBarInitialized", async (msg) => { // Triggered when progress bar is initialized. // If a non-default state has been stored, update the indexing display to that state - if (this.indexingState.status != "loading") { + if (this.indexingState.status !== "loading") { this.messenger.request("indexProgress", this.indexingState); } }); diff --git a/core/index.d.ts b/core/index.d.ts index 330a5be09..4dc5f48d2 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -208,6 +208,11 @@ export interface RangeInFile { range: Range; } +export interface Location { + filepath: string; + position: Position; +} + export interface FileWithContents { filepath: string; contents: string; @@ -470,6 +475,12 @@ export interface IDE { listDir(dir: string): Promise<[string, FileType][]>; getLastModified(files: string[]): Promise<{ [path: string]: number }>; getGitHubAuthToken(): Promise; + + // LSP + gotoDefinition(location: Location): Promise; + + // Callbacks + onDidChangeActiveTextEditor(callback: (filepath: string) => void): void; } // Slash Commands @@ -768,11 +779,13 @@ export interface TabAutocompleteOptions { useRecentlyEdited: boolean; recentLinePrefixMatchMinLength: number; disableInFiles?: string[]; + useImports?: boolean; } export interface ContinueUIConfig { codeBlockToolbarPosition?: "top" | "bottom"; fontSize?: number; + displayRawMarkdown?: boolean; } interface ContextMenuConfig { @@ -785,6 +798,7 @@ interface ContextMenuConfig { interface ModelRoles { inlineEdit?: string; + applyCodeBlock?: string; } interface ExperimentalConfig { diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 11a6a01bb..d773b1dd3 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -1,5 +1,3 @@ -import fs from "node:fs"; -import path from "node:path"; import type { ChunkWithoutID, ContextItem, @@ -10,9 +8,9 @@ import type { } from "../index.js"; import { getBasename, getLastNPathParts } from "../util/index.js"; import { - getLanguageForFile, + TSQueryType, getParserForFile, - supportedLanguages, + getQueryForFile, } from "../util/treeSitter.js"; import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex.js"; import { @@ -23,6 +21,7 @@ import { } from "./types.js"; export class CodeSnippetsCodebaseIndex implements CodebaseIndex { + relativeExpectedTime: number = 1; artifactId = "codeSnippets"; constructor(private readonly ide: IDE) {} @@ -46,35 +45,16 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { )`); } - private getQuerySource(filepath: string) { - const fullLangName = supportedLanguages[filepath.split(".").pop() ?? ""]; - const sourcePath = path.join( - __dirname, - "..", - "tree-sitter", - "code-snippet-queries", - `tree-sitter-${fullLangName}-tags.scm`, - ); - if (!fs.existsSync(sourcePath)) { - return ""; - } - return fs.readFileSync(sourcePath).toString(); - } - async getSnippetsInFile( filepath: string, contents: string, ): Promise<(ChunkWithoutID & { title: string })[]> { - const lang = await getLanguageForFile(filepath); - if (!lang) { - return []; - } const parser = await getParserForFile(filepath); if (!parser) { return []; } const ast = parser.parse(contents); - const query = lang?.query(this.getQuerySource(filepath)); + const query = await getQueryForFile(filepath, TSQueryType.CodeSnippets); const matches = query?.matches(ast.rootNode); return ( diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts index 4403e54ee..e69a33bba 100644 --- a/core/indexing/FullTextSearch.ts +++ b/core/indexing/FullTextSearch.ts @@ -15,6 +15,7 @@ import { } from "./types.js"; export class FullTextSearchCodebaseIndex implements CodebaseIndex { + relativeExpectedTime: number = 0.2; artifactId = "sqliteFts"; private async _createTables(db: DatabaseConnection) { diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 264241ad2..19567a10c 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -31,6 +31,7 @@ interface LanceDbRow { } export class LanceDbIndex implements CodebaseIndex { + relativeExpectedTime: number = 13; get artifactId(): string { return `vectordb::${this.embeddingsProvider.id}`; } @@ -243,6 +244,9 @@ export class LanceDbIndex implements CodebaseIndex { } } + const progressReservedForTagging = 0.1; + let accumulatedProgress = 0; + let computedRows: LanceDbRow[] = []; for await (const update of this.computeChunks(results.compute)) { if (Array.isArray(update)) { @@ -261,7 +265,12 @@ export class LanceDbIndex implements CodebaseIndex { data.contents, ); - yield { progress, desc, status: "indexing" }; + accumulatedProgress = progress * (1 - progressReservedForTagging); + yield { + progress: accumulatedProgress, + desc, + status: "indexing", + }; } else { await addComputedLanceDbRows(update, computedRows); computedRows = []; @@ -300,13 +309,27 @@ export class LanceDbIndex implements CodebaseIndex { } markComplete([{ path, cacheKey }], IndexResultType.AddTag); + accumulatedProgress += 1 / results.addTag.length / 3; + yield { + progress: accumulatedProgress, + desc: `Indexing ${path}`, + status: "indexing", + }; } // Delete or remove tag - remove from lance table) if (!needToCreateTable) { - for (const { path, cacheKey } of [...results.removeTag, ...results.del]) { + const toDel = [...results.removeTag, ...results.del]; + for (const { path, cacheKey } of toDel) { // This is where the aforementioned lowercase conversion problem shows await table?.delete(`cachekey = '${cacheKey}' AND path = '${path}'`); + + accumulatedProgress += 1 / toDel.length / 3; + yield { + progress: accumulatedProgress, + desc: `Deleting ${path}`, + status: "indexing", + }; } } markComplete(results.removeTag, IndexResultType.RemoveTag); @@ -318,6 +341,12 @@ export class LanceDbIndex implements CodebaseIndex { cacheKey, path, ); + accumulatedProgress += 1 / results.del.length / 3; + yield { + progress: accumulatedProgress, + desc: `Deleting ${path}`, + status: "indexing", + }; } markComplete(results.del, IndexResultType.Delete); diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index df1a5a8da..0b766b663 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -12,6 +12,7 @@ import { import { chunkDocument } from "./chunk.js"; export class ChunkCodebaseIndex implements CodebaseIndex { + relativeExpectedTime: number = 1; static artifactId = "chunks"; artifactId: string = ChunkCodebaseIndex.artifactId; diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index dd9aad332..b63c0a3cc 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -52,9 +52,11 @@ export class CodebaseIndexer { workspaceDirs: string[], abortSignal: AbortSignal, ): AsyncGenerator { + let progress = 0; + if (workspaceDirs.length === 0) { yield { - progress: 0, + progress, desc: "Nothing to index", status: "disabled", }; @@ -64,29 +66,32 @@ export class CodebaseIndexer { const config = await this.configHandler.loadConfig(); if (config.disableIndexing) { yield { - progress: 0, + progress, desc: "Indexing is disabled in config.json", status: "disabled", }; return; } else { yield { - progress: 0, + progress, desc: "Starting indexing", status: "loading", }; } const indexesToBuild = await this.getIndexesToBuild(); - let completedDirs = 0; + const totalRelativeExpectedTime = indexesToBuild.reduce( + (sum, index) => sum + index.relativeExpectedTime, + 0, + ); // Wait until Git Extension has loaded to report progress // so we don't appear stuck at 0% while waiting await this.ide.getRepoName(workspaceDirs[0]); yield { - progress: 0, + progress, desc: "Starting indexing...", status: "loading", }; @@ -99,7 +104,7 @@ export class CodebaseIndexer { const stats = await this.ide.getLastModified(files); const branch = await this.ide.getBranch(directory); const repoName = await this.ide.getRepoName(directory); - let completedIndexes = 0; + let completedRelativeExpectedTime = 0; for (const codebaseIndex of indexesToBuild) { // TODO: IndexTag type should use repoName rather than directory @@ -116,12 +121,10 @@ export class CodebaseIndexer { ); try { - for await (let { progress, desc } of codebaseIndex.update( - tag, - results, - markComplete, - repoName, - )) { + for await (let { + progress: indexProgress, + desc, + } of codebaseIndex.update(tag, results, markComplete, repoName)) { // Handle pausing in this loop because it's the only one really taking time if (abortSignal.aborted) { yield { @@ -134,7 +137,7 @@ export class CodebaseIndexer { if (this.pauseToken.paused) { yield { - progress: completedDirs / workspaceDirs.length, + progress, desc: "Paused", status: "paused", }; @@ -143,19 +146,24 @@ export class CodebaseIndexer { } } + progress = + (completedDirs + + (completedRelativeExpectedTime + + indexProgress * codebaseIndex.relativeExpectedTime) / + totalRelativeExpectedTime) / + workspaceDirs.length; yield { - progress: - (completedDirs + - (completedIndexes + progress) / indexesToBuild.length) / - workspaceDirs.length, + progress, desc, status: "indexing", }; } - completedIndexes++; + + completedRelativeExpectedTime += codebaseIndex.relativeExpectedTime; yield { progress: - (completedDirs + completedIndexes / indexesToBuild.length) / + (completedDirs + + completedRelativeExpectedTime / totalRelativeExpectedTime) / workspaceDirs.length, desc: "Completed indexing " + codebaseIndex.artifactId, status: "indexing", @@ -186,8 +194,9 @@ export class CodebaseIndexer { } completedDirs++; + progress = completedDirs / workspaceDirs.length; yield { - progress: completedDirs / workspaceDirs.length, + progress, desc: "Indexing Complete", status: "done", }; diff --git a/core/indexing/refreshIndex.ts b/core/indexing/refreshIndex.ts index a81f1b3a4..c67379960 100644 --- a/core/indexing/refreshIndex.ts +++ b/core/indexing/refreshIndex.ts @@ -329,6 +329,7 @@ export async function getComputeDeleteAddRemove( } export class GlobalCacheCodeBaseIndex implements CodebaseIndex { + relativeExpectedTime: number = 1; private db: DatabaseConnection; constructor(db: DatabaseConnection) { diff --git a/core/indexing/types.ts b/core/indexing/types.ts index 3e3923e99..d636564bd 100644 --- a/core/indexing/types.ts +++ b/core/indexing/types.ts @@ -14,6 +14,7 @@ export type MarkCompleteCallback = ( export interface CodebaseIndex { artifactId: string; + relativeExpectedTime: number; update( tag: IndexTag, results: RefreshIndexResults, diff --git a/core/llm/llms/Deepseek.ts b/core/llm/llms/Deepseek.ts index 30f51c628..48dc9e61b 100644 --- a/core/llm/llms/Deepseek.ts +++ b/core/llm/llms/Deepseek.ts @@ -12,7 +12,7 @@ class Deepseek extends OpenAI { }, useLegacyCompletionsEndpoint: false, }; - protected maxStopWords: number | undefined = 4; + protected maxStopWords: number | undefined = 16; } export default Deepseek; diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 14382ede9..33d991b81 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -94,13 +94,14 @@ class OpenAI extends BaseLLM { // Jan + Azure OpenAI don't truncate and will throw an error this.maxStopWords !== undefined ? options.stop?.slice(0, this.maxStopWords) - : url.port === "1337" || - url.host === "api.openai.com" || - url.host === "api.groq.com" || - url.host === "api.deepseek.com" || - this.apiType === "azure" - ? options.stop?.slice(0, 4) - : options.stop, + : url.host === "api.deepseek.com" + ? options.stop?.slice(0, 16) + : url.port === "1337" || + url.host === "api.openai.com" || + url.host === "api.groq.com" || + this.apiType === "azure" + ? options.stop?.slice(0, 4) + : options.stop, }; return finalOptions; diff --git a/core/llm/stream.ts b/core/llm/stream.ts index 629337d0d..b51f1fd36 100644 --- a/core/llm/stream.ts +++ b/core/llm/stream.ts @@ -1,6 +1,10 @@ -export async function* streamResponse( - response: Response, -): AsyncGenerator { +async function* toAsyncIterable(nodeReadable: NodeJS.ReadableStream): AsyncGenerator { + for await (const chunk of nodeReadable) { + yield chunk as Uint8Array; + } +} + +export async function* streamResponse(response: Response): AsyncGenerator { if (response.status !== 200) { throw new Error(await response.text()); } @@ -9,9 +13,24 @@ export async function* streamResponse( throw new Error("No response body returned."); } - const stream = (ReadableStream as any).from(response.body); + // Get the major version of Node.js + const nodeMajorVersion = parseInt(process.versions.node.split(".")[0], 10); - yield* stream.pipeThrough(new TextDecoderStream("utf-8")); + if (nodeMajorVersion >= 20) { + // Use the new API for Node 20 and above + const stream = (ReadableStream as any).from(response.body); + for await (const chunk of stream.pipeThrough(new TextDecoderStream("utf-8"))) { + yield chunk; + } + } else { + // Fallback for Node versions below 20 + // Streaming with this method doesn't work as version 20+ does + const decoder = new TextDecoder("utf-8"); + const nodeStream = response.body as unknown as NodeJS.ReadableStream; + for await (const chunk of toAsyncIterable(nodeStream)) { + yield decoder.decode(chunk, { stream: true }); + } + } } function parseDataLine(line: string): any { diff --git a/core/protocol/core.ts b/core/protocol/core.ts index be0f80d55..7ea95eb2c 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -131,9 +131,8 @@ export type ToCoreFromIdeOrWebviewProtocol = { | "apiKeys" | "custom" | "freeTrial" - | "localExistingUser" - | "optimizedExistingUser" - | "localAfterFreeTrial"; + | "localAfterFreeTrial" + | "bestExperience"; }, void, ]; diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index 6cd78a1eb..f6837d9f5 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -5,8 +5,10 @@ import type { IdeInfo, IdeSettings, IndexTag, + Location, Problem, Range, + RangeInFile, Thread, } from ".."; @@ -74,5 +76,7 @@ export type ToIdeFromWebviewOrCoreProtocol = { listDir: [{ dir: string }, [string, FileType][]]; getLastModified: [{ files: string[] }, { [path: string]: number }]; + gotoDefinition: [{ location: Location }, RangeInFile[]]; + getGitHubAuthToken: [undefined, string | undefined]; }; diff --git a/core/protocol/index.ts b/core/protocol/index.ts index 36c73e0b0..ac89c3b42 100644 --- a/core/protocol/index.ts +++ b/core/protocol/index.ts @@ -12,7 +12,10 @@ export type IProtocol = Record; // IDE export type ToIdeProtocol = ToIdeFromWebviewProtocol & ToIdeFromCoreProtocol; -export type FromIdeProtocol = ToWebviewFromIdeProtocol & ToCoreFromIdeProtocol; +export type FromIdeProtocol = ToWebviewFromIdeProtocol & + ToCoreFromIdeProtocol & { + didChangeActiveTextEditor: [{ filepath: string }, void]; + }; // Webview export type ToWebviewProtocol = ToWebviewFromIdeProtocol & diff --git a/core/util/LruCache.ts b/core/util/LruCache.ts new file mode 100644 index 000000000..f6d923fed --- /dev/null +++ b/core/util/LruCache.ts @@ -0,0 +1,30 @@ +export class PrecalculatedLruCache { + private items: [string, V][] = []; + constructor( + private readonly calculateValue: (key: string) => Promise, + private readonly N: number, + ) {} + + async initKey(key: string) { + // Maintain LRU + const index = this.items.findIndex((item) => item[0] === key); + + if (index < 0) { + // Calculate info for new file + const value: V = await this.calculateValue(key); + + this.items.push([key, value]); + if (this.items.length > this.N) { + this.items.shift(); + } + } else { + // Move to end of array, since it was recently used + const [item] = this.items.splice(index, 1); + this.items.push(item); + } + } + + get(key: string): V | undefined { + return this.items.find((item) => item[0] === key)?.[1]; + } +} diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 4f6cd11b4..af3eee1da 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -6,8 +6,10 @@ import { IdeInfo, IdeSettings, IndexTag, + Location, Problem, Range, + RangeInFile, Thread, } from "../index.d.js"; @@ -23,6 +25,13 @@ class FileSystemIde implements IDE { return Promise.resolve(fs.existsSync(filepath)); } + gotoDefinition(location: Location): Promise { + throw new Error("Method not implemented."); + } + onDidChangeActiveTextEditor(callback: (filepath: string) => void): void { + throw new Error("Method not implemented."); + } + async getIdeSettings(): Promise { return { remoteConfigServerUrl: undefined, diff --git a/core/util/messageIde.ts b/core/util/messageIde.ts index 87fb00e23..0d28a2b44 100644 --- a/core/util/messageIde.ts +++ b/core/util/messageIde.ts @@ -5,11 +5,14 @@ import type { IdeInfo, IdeSettings, IndexTag, + Location, Problem, Range, + RangeInFile, Thread, } from "../index.js"; import { ToIdeFromWebviewOrCoreProtocol } from "../protocol/ide.js"; +import { FromIdeProtocol } from "../protocol/index.js"; export class MessageIde implements IDE { constructor( @@ -17,10 +20,21 @@ export class MessageIde implements IDE { messageType: T, data: ToIdeFromWebviewOrCoreProtocol[T][0], ) => Promise, + private readonly on: ( + messageType: T, + callback: (data: FromIdeProtocol[T][0]) => FromIdeProtocol[T][1], + ) => void, ) {} fileExists(filepath: string): Promise { return this.request("fileExists", { filepath }); } + async gotoDefinition(location: Location): Promise { + return this.request("gotoDefinition", { location }); + } + onDidChangeActiveTextEditor(callback: (filepath: string) => void): void { + this.on("didChangeActiveTextEditor", (data) => callback(data.filepath)); + } + getIdeSettings(): Promise { return this.request("getIdeSettings", undefined); } diff --git a/core/util/messenger.ts b/core/util/messenger.ts index fbf54b87b..1d2bde255 100644 --- a/core/util/messenger.ts +++ b/core/util/messenger.ts @@ -134,8 +134,9 @@ export class InProcessMessenger< externalRequest( messageType: T, data: ToProtocol[T][0], + _messageId?: string, ): Promise { - const messageId = uuidv4(); + const messageId = _messageId ?? uuidv4(); const listener = this.myTypeListeners.get(messageType); if (!listener) { throw new Error(`No handler for message type "${String(messageType)}"`); diff --git a/core/util/parameters.ts b/core/util/parameters.ts index 83b77046d..8909af6f4 100644 --- a/core/util/parameters.ts +++ b/core/util/parameters.ts @@ -19,6 +19,7 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = { useRecentlyEdited: true, recentLinePrefixMatchMinLength: 7, disableInFiles: undefined, + useImports: true, }; export const COUNT_COMPLETION_REJECTED_AFTER = 10_000; diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index 967f5d979..95a7a10ce 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -1,4 +1,5 @@ -import * as path from "path"; +import fs from "node:fs"; +import path from "node:path"; import Parser, { Language } from "web-tree-sitter"; export const supportedLanguages: { [key: string]: string } = { @@ -115,3 +116,34 @@ export async function getLanguageForFile( return undefined; } } + +export enum TSQueryType { + CodeSnippets = "code-snippet-queries", + Imports = "import-queries", +} + +export async function getQueryForFile( + filepath: string, + queryType: TSQueryType, +): Promise { + const language = await getLanguageForFile(filepath); + if (!language) { + return undefined; + } + + const fullLangName = supportedLanguages[filepath.split(".").pop() ?? ""]; + const sourcePath = path.join( + __dirname, + "..", + "tree-sitter", + queryType, + `${fullLangName}.scm`, + ); + if (!fs.existsSync(sourcePath)) { + return undefined; + } + const querySource = fs.readFileSync(sourcePath).toString(); + + const query = language.query(querySource); + return query; +} diff --git a/docs/docs/changelog.mdx b/docs/docs/changelog.mdx new file mode 100644 index 000000000..8c3d76af2 --- /dev/null +++ b/docs/docs/changelog.mdx @@ -0,0 +1,30 @@ +--- +title: 📝 Changelog +description: Changelogs for the latest releases of the VSCode and IntelliJ extensions +keywords: [changelog] +hide_table_of_contents: true +--- + +import VSCodeChangelog from "../../extensions/vscode/CHANGELOG.md"; +import IntelliJChangelog from "../../extensions/intellij/CHANGELOG.md"; + +Below are the changelogs for the latest releases of the VSCode and IntelliJ extensions. + +import TOCInline from "@theme/TOCInline"; + + + node.value === "VSCode Changelog" || node.value === "IntelliJ Changelog", + )} +/> + +
+ +## VSCode Changelog + + + +## IntelliJ Changelog + + diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index cbf5b8449..c9f3f144e 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -202,7 +202,12 @@ assignee = currentUser() AND resolution = Unresolved order by updated DESC You can override this query by setting the `issueQuery` parameter. -### Code Outline + + + ### PostgreSQL @@ -312,10 +317,15 @@ interface CustomContextProvider { title: string; displayTitle?: string; description?: string; + renderInlineAs?: string; + type?: ContextProviderType; getContextItems( query: string, extras: ContextProviderExtras, ): Promise; + loadSubmenuItems?: ( + args: LoadSubmenuItemsArgs, + ) => Promise; } ``` @@ -455,6 +465,7 @@ Continue will use [esbuild](https://esbuild.github.io/) to bundle your `config.t - `displayTitle` (optional): The title displayed in the dropdown - `description` (optional): The longer description displayed in the dropdown when hovered - `type` (optional): The type of context provider. Options are "normal", "query", and "submenu". Defaults to "normal". +- `renderInlineAs` (optional): The string that will be rendered inline at the top of the prompt. If no value is provided, the `displayTitle` will be used. An empty string can be provided to prevent rendering the default `displayTitle`. - `getContextItems`: A function that returns the documents to include in the prompt. It should return a list of `ContextItem`s, and is given access to the following arguments: - `extras.fullInput`: A string representing the user's full input to the text box. This can be used for example to generate an embedding to compare against a set of other embedded documents - `extras.embeddingsProvider`: The embeddings provider has an `embed` function that will convert text (such as `fullInput`) to an embedding diff --git a/docs/docs/quickstart.md b/docs/docs/quickstart.md index 7e51c51b0..b94b0eeda 100644 --- a/docs/docs/quickstart.md +++ b/docs/docs/quickstart.md @@ -28,6 +28,6 @@ keywords: [quickstart, start, install, vscode, jetbrains] ![jetbrains-quickstart](/img/jetbrains-quickstart.png) -4. If you have any problems, see the [troubleshooting guide](./troubleshooting.md) or ask for help in [our Discord](https://discord.gg/NWtdYexhMs). +4. If you have any problems, see the [troubleshooting guide](./troubleshooting.md) or ask for help in [our Discord](https://discord.com/invite/EfJEfdFnDQ). > Alternatively, you can install from disk after downloading from the [JetBrains Extension Marketplace](https://plugins.jetbrains.com/plugin/22707-continue-extension). diff --git a/docs/docs/reference/Model Providers/anthropicllm.md b/docs/docs/reference/Model Providers/anthropicllm.md index 62cb5c422..309f29ab2 100644 --- a/docs/docs/reference/Model Providers/anthropicllm.md +++ b/docs/docs/reference/Model Providers/anthropicllm.md @@ -8,7 +8,7 @@ To setup Anthropic, obtain an API key from [here](https://www.anthropic.com/api) { "title": "Anthropic", "provider": "anthropic", - "model": "claude-3-opus-20240229", + "model": "claude-3-5-sonnet-20240620", "apiKey": "YOUR_API_KEY" } ] diff --git a/docs/docs/setup/configuration.md b/docs/docs/setup/configuration.md index bdd925329..5b314c178 100644 --- a/docs/docs/setup/configuration.md +++ b/docs/docs/setup/configuration.md @@ -6,6 +6,85 @@ keywords: [configure, llm, provider] # Configuration +Want a quick and easy setup for Continue? We've got you covered with some sample `config.json` files for different scenarios. Just copy and paste them into your `config.json` by clicking the gear icon at the bottom right of the Continue sidebar. + +## Best Overall Experience + +This setup uses Claude 3.5 Sonnet for chatting, Codestral for autocomplete, and Voyage AI for embeddings and reranking. + +**What You Need:** + +1. Get a Codestral API key from [Mistral AI's La Plateforme](https://console.mistral.ai/codestral) +2. Get an Anthropic API key from [Anthropic Console](https://console.anthropic.com/account/keys) +3. Replace `[CODESTRAL_API_KEY]` and `[ANTHROPIC_API_KEY]` with the keys you got from the above links. + +:::note +This example uses a free trial for embeddings and reranking, forwarding requests via ContinueDev proxy. For direct service, get a Voyage AI API key and update the `provider` and `apiKey` fields. See the [config reference for Voyage AI](../walkthroughs//codebase-embeddings.md#voyage-ai) for details on how to set this up. +::: + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "Claude 3.5 Sonnet", + "provider": "anthropic", + "model": "claude-3-5-sonnet-20240620", + "apiKey": "[ANTHROPIC_API_KEY]" + } + ], + "tabAutocompleteModel": { + "title": "Codestral", + "provider": "mistral", + "model": "codestral-latest", + "apiKey": "[CODESTRAL_API_KEY]" + }, + "embeddingsProvider": { + "provider": "free-trial" + }, + "reranker": { + "name": "free-trial" + } +} +``` + +## Local and Offline Configuration + +This configuration leverages Ollama for all functionalities - chat, autocomplete, and embeddings - ensuring that no code is transmitted outside your machine, allowing Continue to be run even on an air-gapped computer. + +**What You Need:** + +1. Download Ollama from [Ollama's Official Site](https://ollama.ai) +2. Pull the required models: + - For chat: `ollama pull llama3:8b` + - For autocomplete: `ollama pull starcoder2:3b` + - For embeddings: `ollama pull nomic-embed-text` + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "Ollama", + "provider": "ollama", + "model": "AUTODETECT" + } + ], + "tabAutocompleteModel": { + "title": "Starcoder 2 3b", + "provider": "ollama", + "model": "starcoder2:3b" + }, + "embeddingsProvider": { + "provider": "ollama", + "model": "nomic-embed-text" + } +} +``` + +If you require a fully air-gapped setup, you may also want to: + +1. For VS Code, manually download the latest .vsix file from the [Open VSX Registry](https://open-vsx.org/extension/Continue/continue) rather than the VS Code Marketplace and [install it to VS Code](https://code.visualstudio.com/docs/editor/extension-marketplace#_install-from-a-vsix). For JetBrains, manually download the .zip file from the [JetBrains Plugin Repository](https://plugins.jetbrains.com/plugin/22707-continue) and [install it to your IDE](https://www.jetbrains.com/help/idea/managing-plugins.html#install_plugin_from_disk). +2. Open `~/.continue/config.json` and set `"allowAnonymousTelemetry": false`. This will stop Continue from attempting requests to PostHog for [anonymous telemetry](../telemetry.md). + ## Setting up chat models In `config.json`, you'll find the `models` property, a list of the models that you have saved to use with Continue: diff --git a/docs/docs/setup/examples.md b/docs/docs/setup/examples.md deleted file mode 100644 index 47bbaf98c..000000000 --- a/docs/docs/setup/examples.md +++ /dev/null @@ -1,77 +0,0 @@ -# Example configurations - -If you're looking for a quick way to create the perfect Continue setup, we've written a few sample `config.json`s for common situations. You can copy these and paste them into your `config.json` by clicking the gear icon in the bottom right of the Continue sidebar. - -## I just want the best experience possible - -This uses Claude 3 Opus for chat, Codestral for autocomplete, and Voyage AI for embeddings and reranking. - -### Pre-requisites - -1. Obtain a Codestral API key from [Mistral AI's La Plateforme](https://console.mistral.ai/codestral) - -2. Obtain an Anthropic API key from [here](https://console.anthropic.com/account/keys) - -3. Replace `[CODESTRAL_API_KEY]` and `[ANTHROPIC_API_KEY]` with the keys you obtained in the previous steps. - -```json title="~/.continue/config.json" -{ - "models": [ - { - "title": "Claude 3 Opus", - "provider": "anthropic", - "model": "claude-3-opus-20240229", - "apiKey": "[ANTHROPIC_API_KEY]" - } - ], - "tabAutocompleteModel": { - "title": "Codestral", - "provider": "mistral", - "model": "codestral-latest", - "apiKey": "[CODESTRAL_API_KEY]" - }, - "embeddingsProvider": { - "provider": "free-trial" - }, - "reranker": { - "name": "free-trial" - } -} -``` - -## I need to be entirely local + offline - -This uses Ollama for chat, autocomplete, and embeddings, making sure that no code ever leaves your machine. - -### Pre-requisites - -1. [Download Ollama](https://ollama.ai) - -2. Pull the necessary models - - i. For chat: `ollama run llama3:8b` - - ii. For autocomplete: `ollama run starcoder2:3b` - - iii. For embeddings: `ollama run nomic-embed-text` - -```json title="~/.continue/config.json" -{ - "models": [ - { - "title": "Ollama", - "provider": "ollama", - "model": "AUTODETECT" - } - ], - "tabAutocompleteModel": { - "title": "Starcoder 2 3b", - "provider": "ollama", - "model": "starcoder2:3b" - }, - "embeddingsProvider": { - "provider": "ollama", - "model": "nomic-embed-text" - } -} -``` diff --git a/docs/docs/setup/overview.md b/docs/docs/setup/overview.md index 1f038e7fa..922389dc6 100644 --- a/docs/docs/setup/overview.md +++ b/docs/docs/setup/overview.md @@ -8,7 +8,6 @@ You will need to decide which models and providers you use for [chat](select-mod Learn more: +- [Configuration](configuration.md) - [Select providers](select-provider.md) - [Select models](select-model.md) -- [Configuration](configuration.md) -- [Example `config.json`s](examples.md) diff --git a/docs/docs/setup/select-model.md b/docs/docs/setup/select-model.md index f724501d7..a04cfa399 100644 --- a/docs/docs/setup/select-model.md +++ b/docs/docs/setup/select-model.md @@ -32,8 +32,8 @@ _You can also use other open-source chat models by adding them to your `config.j #### Claude 3 from Anthropic -- Unlimited budget: `claude-3-opus-20240229` -- Limited budget: `claude-3-sonnet-20240229` +- Unlimited budget: `claude-3-5-sonnet-20240620` +- Limited budget: `claude-3-5-sonnet-20240620` #### GPT-4o from OpenAI @@ -75,11 +75,10 @@ _You can also use other autocomplete models by adding them to your `config.json` ## Embeddings -You likely want to use an embeddings model that is made to vectorize code. +We recommend the following embeddings models, which are used for codebase retrieval as described [here](../walkthroughs/codebase-embeddings.md#embeddings-providers) ### Open-source models -- `transformers.js` - `nomic-embed-text` ### Commercial models diff --git a/docs/docs/telemetry.md b/docs/docs/telemetry.md index 92c404988..dfce3a6da 100644 --- a/docs/docs/telemetry.md +++ b/docs/docs/telemetry.md @@ -8,18 +8,23 @@ keywords: [telemetry, anonymous, usage info, opt out] ## Overview -Continue collects and reports **anonymous** usage information. This data is essential to understanding how we should improve the product. You can opt out of it at any time. We use [Posthog](https://posthog.com/), an open source platform for product analytics, to collect and store the data. You can review the code [here](https://github.com/continuedev/continue/blob/main/gui/src/hooks/CustomPostHogProvider.tsx), or review our official policy [here](https://continue.dev/privacy). +Continue collects and reports **anonymous** usage information. + +This data is essential to understanding how we should improve the product. You can opt out of it at any time. + +We use [Posthog](https://posthog.com/), an open source platform for product analytics, to collect and store the data. You can review the code [here](https://github.com/continuedev/continue/blob/main/gui/src/hooks/CustomPostHogProvider.tsx), or review our official policy [here](https://continue.dev/privacy). + +## Tracking policy + +All data is anonymous and cleaned of PII before being sent to PostHog. ## What we track -We track - -- whether you accept or reject suggestions (never including the code or the prompt) -- the name of the model and slash command used -- the number of tokens generated -- the name of your OS and IDE - -All data is anonymous and cleaned of PII before being sent to PostHog. +- Whether you accept or reject suggestions (never including the code or the prompt) +- The name of the model and slash command used +- The number of tokens generated +- The name of your OS and IDE +- Pageviews ## How to opt out diff --git a/docs/docs/walkthroughs/codebase-embeddings.md b/docs/docs/walkthroughs/codebase-embeddings.md index dbd102eca..756567bd7 100644 --- a/docs/docs/walkthroughs/codebase-embeddings.md +++ b/docs/docs/walkthroughs/codebase-embeddings.md @@ -1,7 +1,7 @@ --- title: Codebase Retrieval description: Talk to your codebase -keywords: [talk, embeddings, codebase, experimental] +keywords: [talk, embeddings, reranker, codebase, experimental] --- # Codebase retrieval @@ -113,8 +113,9 @@ Voyage AI offers the best embeddings for code with their voyage-code-2 model. Af OpenAI's [embeddings](https://platform.openai.com/docs/guides/embeddings) are high dimensional embeddings that give great performance on both text and code. -Configuration for text-embedding-3-small Model. This is default. -The text-embedding-3-small model offers an outstanding balance between performance and efficiency, suitable for a versatile range of applications. +#### Configuration for the `text-embedding-3-small` model + +This is default. The `text-embedding-3-small` model offers an outstanding balance between performance and efficiency, suitable for a versatile range of applications. ```json title="~/.continue/config.json" { @@ -127,8 +128,9 @@ The text-embedding-3-small model offers an outstanding balance between performan } ``` -Configuration for text-embedding-3-large Model -For those requiring the highest level of embedding detail and precision, the text-embedding-3-large model is the better choice. +#### Configuration for the `text-embedding-3-large` model + +For those requiring the highest level of embedding detail and precision, the `text-embedding-3-large` model is the better choice. ```json title="~/.continue/config.json" { @@ -141,8 +143,9 @@ For those requiring the highest level of embedding detail and precision, the tex } ``` -Legacy Model Configuration -For certain scenarios, you may still find the text-embedding-ada-002 model relevant. Below is the configuration example: +#### Legacy Model Configuration + +For certain scenarios, you may still find the `text-embedding-ada-002` model relevant. Below is the configuration example: ```json title="~/.continue/config.json" { @@ -213,9 +216,9 @@ export function modifyConfig(config: Config): Config { ## Reranking providers -A reranking model improves the accuracy of codebase retrieval by breaking it into two stages. Instead of only using similarity search to go from all possible snippets to the top 10-20, we can instead get the top 100+ from similarity search and then use a more expensive model, the "reranker", to more accurately decide the top 10-20. +The reranker plays a crucial role in refining the results retrieved from your codebase. It processes the initial set of results obtained through embeddings-based retrieval, improving their relevance and accuracy for your queries. -Because reranking requires 100+ simultaneous invocations of a model, there are not currently any local rerankers that Continue supports. However if you are able to use any of the below options, it is strongly recommended, as they are cheap but will drastically improve the quality of codebase retrieval. +Continue offers several reranking options: `cohere`, `voyage`, `llm`, and `free-trial`, which can be configured in `config.json`. ### Voyage AI @@ -266,6 +269,18 @@ If you only have access to a single LLM, then you can use it as a reranker. This The `"modelTitle"` field must match one of the models in your "models" array in config.json. +### Free Trial (Voyage AI) + +Continue offers a free trial of Voyage AI's reranking model. + +```json title="~/.continue/config.json" +{ + "reranker": { + "name": "free-trial" + } +} +``` + ## Customizing which files are indexed Continue respects `.gitignore` files in order to determine which files should not be indexed. If you'd like to exclude additional files, you can add them to a `.continueignore` file, which follows the exact same rules as `.gitignore`. diff --git a/docs/docs/walkthroughs/prompt-files.md b/docs/docs/walkthroughs/prompt-files.md index 90faff0d4..bb5c0f68f 100644 --- a/docs/docs/walkthroughs/prompt-files.md +++ b/docs/docs/walkthroughs/prompt-files.md @@ -4,11 +4,11 @@ Prompt (`.prompt`) files are an easy way to build and share LLM prompts with oth ## How to create a prompt file -Below is a quick example of setting up a prompt file to write unit tests:s +Below is a quick example of setting up a prompt file to write unit tests using Jest. -1. Create a folder called `.prompts` at the top level of your workspace -2. Add a file called `test.prompt` to this folder -3. Write the following contents to `test.prompt` and save +1. Create a folder called `.prompts/` at the top level of your workspace. +2. Add a file called `test.prompt` to this folder. The name of this file will be the name of the slash command you will use to generate your prompt. +3. Write the following contents to `test.prompt` and save. ``` temperature: 0.5 diff --git a/docs/sidebars.js b/docs/sidebars.js index 4b5cd0f6b..ab007865d 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -24,10 +24,9 @@ const sidebars = { collapsed: true, items: [ "setup/overview", + "setup/configuration", "setup/select-provider", "setup/select-model", - "setup/configuration", - "setup/examples", ], }, { @@ -47,13 +46,10 @@ const sidebars = { collapsible: true, collapsed: true, items: [ - // "walkthroughs/codellama", "walkthroughs/set-up-codestral", - "walkthroughs/running-continue-without-internet", "walkthroughs/codebase-embeddings", "walkthroughs/tab-autocomplete", "walkthroughs/prompt-files", - // "walkthroughs/config-file-migration", ], }, "development-data", @@ -71,6 +67,7 @@ const sidebars = { }, ], }, + "changelog", ], }; diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 08332c242..87ed17d52 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1999,7 +1999,7 @@ "type": "string" }, "model": { - "enum": ["rerank-lite-1"] + "enum": ["rerank-lite-1", "rerank-1"] } }, "required": ["apiKey"] @@ -2103,6 +2103,11 @@ }, "fontSize": { "type": "number" + }, + "displayRawMarkdown": { + "type": "boolean", + "description": "If set to true, we will display the model output as raw markdown.", + "default": false } } }, diff --git a/extensions/intellij/CHANGELOG.md b/extensions/intellij/CHANGELOG.md index e014cbbc4..7117d9693 100644 --- a/extensions/intellij/CHANGELOG.md +++ b/extensions/intellij/CHANGELOG.md @@ -1,38 +1,52 @@ -# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). - ## 0.0.42 - 2024-04-12 + ### Added -* Inline cmd/ctrl+I in JetBrains + +- Inline cmd/ctrl+I in JetBrains + ### Fixed -* Fixed character encoding error causing display issues -* Fixed error causing input to constantly demand focus -* Fixed automatic reloading of config.json + +- Fixed character encoding error causing display issues +- Fixed error causing input to constantly demand focus +- Fixed automatic reloading of config.json ## 0.0.38 - 2024-03-15 + ### Added -* Remote config server support -* Autocomplete support in JetBrains + +- Remote config server support +- Autocomplete support in JetBrains ## 0.0.34 - 2024-03-03 + ### Added -* diff context provider + +- diff context provider + ### Changed -* Allow LLM servers to handle templating + +- Allow LLM servers to handle templating + ### Fixed -* Fix a few context providers / slash commands -* Fixed issues preventing proper extension startup + +- Fix a few context providers / slash commands +- Fixed issues preventing proper extension startup ## v0.0.26 - 2023-12-28 + ### Added -* auto-reloading of config on save + +- auto-reloading of config on save + ### Fixed -* Fixed /edit bug for versions without Python server + +- Fixed /edit bug for versions without Python server ## v0.0.25 - 2023-12-25 diff --git a/extensions/intellij/README.md b/extensions/intellij/README.md index 532013fe5..9e5a95432 100644 --- a/extensions/intellij/README.md +++ b/extensions/intellij/README.md @@ -1,6 +1,6 @@ -![readme](../../media/readme.png) +![readme](media/readme.png)

Continue

@@ -14,25 +14,25 @@ ## Easily understand code sections -![understand](../../docs/static/img/understand.gif) +![understand](docs/static/img/understand.gif) `cmd+J` (MacOS) / `ctrl+J` (Windows) ## Tab to autocomplete code suggestions -![autocomplete](../../docs/static/img/autocomplete.gif) +![autocomplete](docs/static/img/autocomplete.gif) `tab` (MacOS) / `tab` (Windows) ## Refactor functions where you are coding -![inline](../../docs/static/img/inline.gif) +![inline](docs/static/img/inline.gif) `cmd+I` (MacOS) / `ctrl+I` (Windows) ## Quickly use documentation as context -![docs](../../docs/static/img/docs.gif) +![docs](docs/static/img/docs.gif) `@docs` (MacOS) / `@docs` (Windows) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/Diffs.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/Diffs.kt index a059a6ae4..9f2597fde 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/Diffs.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/Diffs.kt @@ -37,7 +37,7 @@ fun getDiffDirectory(): File { return diffDir } fun escapeFilepath(filepath: String): String { - return filepath.replace("/", "_f_").replace("\\", "_b_") + return filepath.replace("/", "_f_").replace("\\", "_b_").replace(":", "_c_") } interface DiffInfo { diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 08332c242..87ed17d52 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -1999,7 +1999,7 @@ "type": "string" }, "model": { - "enum": ["rerank-lite-1"] + "enum": ["rerank-lite-1", "rerank-1"] } }, "required": ["apiKey"] @@ -2103,6 +2103,11 @@ }, "fontSize": { "type": "number" + }, + "displayRawMarkdown": { + "type": "boolean", + "description": "If set to true, we will display the model output as raw markdown.", + "default": false } } }, diff --git a/extensions/vscode/.continueignore b/extensions/vscode/.continueignore index 18420af9d..7fd2a214a 100644 --- a/extensions/vscode/.continueignore +++ b/extensions/vscode/.continueignore @@ -1,3 +1,3 @@ media **/*.tmLanguage -textmate-syntaxes +textmate-syntaxes \ No newline at end of file diff --git a/extensions/vscode/CHANGELOG.md b/extensions/vscode/CHANGELOG.md index 4597028ab..98b75db52 100644 --- a/extensions/vscode/CHANGELOG.md +++ b/extensions/vscode/CHANGELOG.md @@ -1,44 +1,58 @@ -# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). - Pre-release Changes + ### Added -* Support for Gemini 1.5 Pro + +- Support for Gemini 1.5 Pro ## 0.8.24 - 2024-04-12 + ### Added -* Support for improved retrieval models (Voyage embeddings/reranking) -* New @code context provider -* Personal usage analytics + +- Support for improved retrieval models (Voyage embeddings/reranking) +- New @code context provider +- Personal usage analytics ## 0.8.15 - 2024-03-05 + ### Added -* Tab-autocomplete in beta + +- Tab-autocomplete in beta ## 0.8.14 - 2024-03-03 + ### Added -* Image support -* Full-text search index for retrieval -* Docs context provider -* CodeLlama-70b support + +- Image support +- Full-text search index for retrieval +- Docs context provider +- CodeLlama-70b support + ### Changed -* config.ts only runs in NodeJS, not browser + +- config.ts only runs in NodeJS, not browser + ### Fixed -* Fixed proxy setting in config.json + +- Fixed proxy setting in config.json ## v0.8.2 - 2024-01-23 + ### Added -* Add codellama and gemini to free trial, using new server -* Local codebase syncing and embeddings using LanceDB -* Improved VS Code theme matching + +- Add codellama and gemini to free trial, using new server +- Local codebase syncing and embeddings using LanceDB +- Improved VS Code theme matching + ### Changed -* Updates to packaging to download native modules for current platform (lancedb, sqlite, onnxruntime, tree-sitter wasms) -* Context providers now run from the extension side (in Node.js instead of browser javascript) + +- Updates to packaging to download native modules for current platform (lancedb, sqlite, onnxruntime, tree-sitter wasms) +- Context providers now run from the extension side (in Node.js instead of browser javascript) ## v0.8.1 - 2024-01-08 diff --git a/extensions/vscode/CONTRIBUTING.md b/extensions/vscode/CONTRIBUTING.md index ddeca6bcb..5cfbf3cb1 100644 --- a/extensions/vscode/CONTRIBUTING.md +++ b/extensions/vscode/CONTRIBUTING.md @@ -7,11 +7,11 @@ This is the Continue VS Code Extension. Its primary jobs are # How to run the extension -See [Environment Setup](../CONTRIBUTING.md#environment-setup) +See [Environment Setup](../../CONTRIBUTING.md#environment-setup) # How to run and debug tests -After following the setup in [Environment Setup](../CONTRIBUTING.md#environment-setup) you can run the `Extension (VSCode)` launch configuration in VS Code. +After following the setup in [Environment Setup](../../CONTRIBUTING.md#environment-setup) you can run the `Extension (VSCode)` launch configuration in VS Code. ## Notes diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 08332c242..87ed17d52 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -1999,7 +1999,7 @@ "type": "string" }, "model": { - "enum": ["rerank-lite-1"] + "enum": ["rerank-lite-1", "rerank-1"] } }, "required": ["apiKey"] @@ -2103,6 +2103,11 @@ }, "fontSize": { "type": "number" + }, + "displayRawMarkdown": { + "type": "boolean", + "description": "If set to true, we will display the model output as raw markdown.", + "default": false } } }, diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index a3689da84..94a55e7c9 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -2247,7 +2247,8 @@ }, "model": { "enum": [ - "rerank-lite-1" + "rerank-lite-1", + "rerank-1" ] } }, @@ -2361,6 +2362,11 @@ }, "fontSize": { "type": "number" + }, + "displayRawMarkdown": { + "type": "boolean", + "description": "If set to true, we will display the model output as raw markdown.", + "default": false } } }, diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index d5a8b0c0d..71ff48e4e 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -470,7 +470,7 @@ const exe = os === "win32" ? ".exe" : ""; // Validate the all of the necessary files are present validateFilesPresent([ // Queries used to create the index for @code context provider - "tree-sitter/code-snippet-queries/tree-sitter-c_sharp-tags.scm", + "tree-sitter/code-snippet-queries/c_sharp.scm", // Queries used for @outline and @highlights context providers "tag-qry/tree-sitter-c_sharp-tags.scm", diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index b19788b5a..d6d073c7d 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -10,6 +10,7 @@ import { VsCodeContinueApi } from "./api"; import { setupInlineTips } from "./inlineTips"; let resolveVsCodeExtension = (_: VsCodeExtension): void => {}; + export const vscodeExtensionPromise: Promise = new Promise( (resolve) => (resolveVsCodeExtension = resolve), ); @@ -32,6 +33,8 @@ export async function activateExtension(context: vscode.ExtensionContext) { path.join(getExtensionUri().fsPath, "media", "welcome.md"), ), ); + + vscode.commands.executeCommand("continue.focusContinueInput"); }); // Load Continue configuration diff --git a/extensions/vscode/src/autocomplete/lsp.ts b/extensions/vscode/src/autocomplete/lsp.ts index 02441e965..8ac365826 100644 --- a/extensions/vscode/src/autocomplete/lsp.ts +++ b/extensions/vscode/src/autocomplete/lsp.ts @@ -32,7 +32,9 @@ function gotoInputKey(input: GotoInput) { const MAX_CACHE_SIZE = 50; const gotoCache = new Map(); -async function executeGotoProvider(input: GotoInput): Promise { +export async function executeGotoProvider( + input: GotoInput, +): Promise { const cacheKey = gotoInputKey(input); const cached = gotoCache.get(cacheKey); if (cached) { diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 7abec170a..29c9b86c8 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -24,6 +24,9 @@ import { VerticalPerLineDiffManager } from "./diff/verticalPerLine/manager"; import { Battery } from "./util/battery"; import { getPlatform } from "./util/util"; import type { VsCodeWebviewProtocol } from "./webviewProtocol"; +import { Telemetry } from "core/util/posthog"; + +let fullScreenPanel: vscode.WebviewPanel | undefined; function getFullScreenTab() { const tabs = vscode.window.tabGroups.all.flatMap((tabGroup) => tabGroup.tabs); @@ -222,8 +225,13 @@ const commandsMap: ( } }, "continue.focusContinueInput": async () => { - if (!getFullScreenTab()) { + const fullScreenTab = getFullScreenTab(); + if (!fullScreenTab) { + // focus sidebar vscode.commands.executeCommand("continue.continueGUIView.focus"); + } else { + // focus fullscreen + fullScreenPanel?.reveal(); } sidebar.webviewProtocol?.request("focusContinueInput", undefined); await addHighlightedCodeToContext(false, sidebar.webviewProtocol); @@ -468,24 +476,14 @@ const commandsMap: ( return; } - if (fullScreenTab) { + if (fullScreenTab && fullScreenPanel) { //Full screen open, but not focused - focus it - // Focus the tab - const openOptions = { - preserveFocus: true, - preview: fullScreenTab.isPreview, - viewColumn: fullScreenTab.group.viewColumn, - }; - - vscode.commands.executeCommand( - "vscode.open", - (fullScreenTab.input as any).uri, - openOptions, - ); + fullScreenPanel.reveal(); return; } //Full screen not open - open it + Telemetry.capture("openFullScreen", {}); // Close the sidebar.webviews // vscode.commands.executeCommand("workbench.action.closeSidebar"); @@ -497,7 +495,11 @@ const commandsMap: ( "continue.continueGUIView", "Continue", vscode.ViewColumn.One, + { + retainContextWhenHidden: true, + }, ); + fullScreenPanel = panel; //Add content to the panel panel.webview.html = sidebar.getSidebarContent( diff --git a/extensions/vscode/src/diff/horizontal.ts b/extensions/vscode/src/diff/horizontal.ts index 870022457..6313f0bfa 100644 --- a/extensions/vscode/src/diff/horizontal.ts +++ b/extensions/vscode/src/diff/horizontal.ts @@ -1,7 +1,7 @@ +import { devDataPath } from "core/util/paths"; import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; -import { devDataPath } from "core/util/paths"; import * as vscode from "vscode"; import { getMetaKeyLabel, getPlatform } from "../util/util"; import { uriFromFilePath } from "../util/vscode"; @@ -64,7 +64,10 @@ export class DiffManager { } private escapeFilepath(filepath: string): string { - return filepath.replace(/\//g, "_f_").replace(/\\/g, "_b_"); + return filepath + .replace(/\//g, "_f_") + .replace(/\\/g, "_b_") + .replace(/:/g, "_c_"); } private remoteTmpDir = "/tmp/continue"; diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 075f4adc4..5ee17db44 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -18,6 +18,7 @@ import { ToCoreOrIdeFromWebviewProtocol, VsCodeWebviewProtocol, } from "../webviewProtocol"; +import { ConfigHandler } from "core/config/handler"; /** * A shared messenger class between Core and Webview @@ -69,6 +70,7 @@ export class VsCodeMessenger { private readonly webviewProtocol: VsCodeWebviewProtocol, private readonly ide: VsCodeIde, private readonly verticalDiffManagerPromise: Promise, + private readonly configHandlerPromise: Promise, ) { /** WEBVIEW ONLY LISTENERS **/ this.onWebview("showFile", (msg) => { @@ -116,9 +118,11 @@ export class VsCodeMessenger { msg.data.stepIndex, ); }); + this.onWebview("applyToCurrentFile", async (msg) => { // Select the entire current file const editor = vscode.window.activeTextEditor; + if (!editor) { vscode.window.showErrorMessage("No active editor to apply edits to"); return; @@ -134,11 +138,19 @@ export class VsCodeMessenger { editor.selection = new vscode.Selection(start, end); } - (await this.verticalDiffManagerPromise).streamEdit( - `The following code was suggested as an edit:\n\`\`\`\n${msg.data.text}\n\`\`\`\nPlease apply it to the previous code.`, - await this.webviewProtocol.request("getDefaultModelTitle", undefined), - ); + const verticalDiffManager = await this.verticalDiffManagerPromise; + const prompt = `The following code was suggested as an edit:\n\`\`\`\n${msg.data.text}\n\`\`\`\nPlease apply it to the previous code.`; + + const configHandler = await configHandlerPromise; + const config = await configHandler.loadConfig(); + + const modelTitle = + config.experimental?.modelRoles?.applyCodeBlock ?? + (await this.webviewProtocol.request("getDefaultModelTitle", undefined)); + + verticalDiffManager.streamEdit(prompt, modelTitle); }); + this.onWebview("showTutorial", async (msg) => { const tutorialPath = path.join( getExtensionUri().fsPath, @@ -182,6 +194,7 @@ export class VsCodeMessenger { return (await this.inProcessMessenger.externalRequest( messageType, msg.data, + msg.messageId, )) as TODO; }); }); diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index b51217bba..002b6a2d9 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -93,12 +93,15 @@ export class VsCodeExtension { ToCoreProtocol, FromCoreProtocol >(); - const vscodeMessenger = new VsCodeMessenger( + + new VsCodeMessenger( inProcessMessenger, this.sidebar.webviewProtocol, this.ide, verticalDiffManagerPromise, + configHandlerPromise, ); + this.core = new Core(inProcessMessenger, this.ide, async (log: string) => { outputChannel.appendLine( "==========================================================================", @@ -178,9 +181,10 @@ export class VsCodeExtension { // Listen for file saving - use global file watcher so that changes // from outside the window are also caught - fs.watchFile(getConfigJsonPath(), { interval: 1000 }, (stats) => { - this.configHandler.reloadConfig(); + fs.watchFile(getConfigJsonPath(), { interval: 1000 }, async (stats) => { + await this.configHandler.reloadConfig(); }); + fs.watchFile(getConfigTsPath(), { interval: 1000 }, (stats) => { this.configHandler.reloadConfig(); }); @@ -193,6 +197,24 @@ export class VsCodeExtension { // Listen for file changes in the workspace const filepath = event.uri.fsPath; + if (filepath === getConfigJsonPath()) { + // Trigger a toast notification to provide UI feedback that config + // has been updated + const showToast = context.globalState.get( + "showConfigUpdateToast", + true, + ); + if (showToast) { + vscode.window + .showInformationMessage("Config updated", "Don't show again") + .then((selection) => { + if (selection === "Don't show again") { + context.globalState.update("showConfigUpdateToast", false); + } + }); + } + } + if ( filepath.endsWith(".continuerc.json") || filepath.endsWith(".prompt") @@ -260,6 +282,7 @@ export class VsCodeExtension { static continueVirtualDocumentScheme = "continue"; + // eslint-disable-next-line @typescript-eslint/naming-convention private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {}; registerCustomContextProvider(contextProvider: IContextProvider) { diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index c890142f6..0c23e98b0 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -9,7 +9,9 @@ import type { IdeInfo, IdeSettings, IndexTag, + Location, Problem, + RangeInFile, Thread, } from "core"; import { Range } from "core"; @@ -20,6 +22,7 @@ import { getContinueGlobalPath, } from "core/util/paths"; import * as vscode from "vscode"; +import { executeGotoProvider } from "./autocomplete/lsp"; import { DiffManager } from "./diff/horizontal"; import { Repository } from "./otherExtensions/git"; import { VsCodeIdeUtils } from "./util/ideUtils"; @@ -47,6 +50,25 @@ class VsCodeIde implements IDE { ); } + async gotoDefinition(location: Location): Promise { + const result = await executeGotoProvider({ + uri: location.filepath, + line: location.position.line, + character: location.position.character, + name: "vscode.executeDefinitionProvider", + }); + + return result; + } + + onDidChangeActiveTextEditor(callback: (filepath: string) => void): void { + vscode.window.onDidChangeActiveTextEditor((editor) => { + if (editor) { + callback(editor.document.uri.fsPath); + } + }); + } + private authToken: string | undefined; private askedForAuth = false; diff --git a/extensions/vscode/src/util/cleanSlate.ts b/extensions/vscode/src/util/cleanSlate.ts index 837d93fec..09703f481 100644 --- a/extensions/vscode/src/util/cleanSlate.ts +++ b/extensions/vscode/src/util/cleanSlate.ts @@ -1,4 +1,7 @@ +import { getContinueGlobalPath } from "core/util/paths"; import { ExtensionContext } from "vscode"; +import fs from "fs"; + /** * Clear all Continue-related artifacts to simulate a brand new user */ diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index 14e70921c..14bf0acfa 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -259,6 +259,23 @@ export class VsCodeIdeUtils { }); } + private _cachedPath: path.PlatformPath | undefined; + get path(): path.PlatformPath { + if (this._cachedPath) { + return this._cachedPath; + } + + // Return "path" module for either windows or posix depending on sample workspace folder path format + const sampleWorkspaceFolder = + vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; + const isWindows = sampleWorkspaceFolder + ? !sampleWorkspaceFolder.startsWith("/") + : false; + + this._cachedPath = isWindows ? path.win32 : path.posix; + return this._cachedPath; + } + async getDirectoryContents( directory: string, recursive: boolean, @@ -271,7 +288,31 @@ export class VsCodeIdeUtils { .filter(([name, type]) => { type === vscode.FileType.File && !defaultIgnoreFile.ignores(name); }) - .map(([name, type]) => path.join(directory, name)); + .map(([name, type]) => this.path.join(directory, name)); + } + + // If not using gitignore, just read all contents recursively + if (!useGitIgnore) { + const dirQueue = []; + const allFiles: string[] = []; + dirQueue.push(directory); + + while (dirQueue.length > 0) { + const currentDir = dirQueue.shift()!; + const files = await vscode.workspace.fs.readDirectory( + uriFromFilePath(currentDir), + ); + for (const [name, type] of files) { + const filepath = this.path.join(currentDir, name); + if (type === vscode.FileType.Directory) { + dirQueue.push(filepath); + } else { + allFiles.push(filepath); + } + } + } + + return allFiles; } try { @@ -288,7 +329,7 @@ export class VsCodeIdeUtils { const gitRoot = await this.getGitRoot(directory); let onlyThisDirectory = undefined; if (gitRoot) { - onlyThisDirectory = directory.slice(gitRoot.length).split(path.sep); + onlyThisDirectory = directory.slice(gitRoot.length).split(this.path.sep); if (onlyThisDirectory[0] === "") { onlyThisDirectory.shift(); } @@ -307,8 +348,8 @@ export class VsCodeIdeUtils { getAbsolutePath(filepath: string): string { const workspaceDirectories = this.getWorkspaceDirectories(); - if (!path.isAbsolute(filepath) && workspaceDirectories.length === 1) { - return path.join(workspaceDirectories[0], filepath); + if (!this.path.isAbsolute(filepath) && workspaceDirectories.length === 1) { + return this.path.join(workspaceDirectories[0], filepath); } else { return filepath; } diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-c-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/c.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-c-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/c.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-c_sharp-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/c_sharp.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-c_sharp-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/c_sharp.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-cpp-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/cpp.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-cpp-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/cpp.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-elisp-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/elisp.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-elisp-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/elisp.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-elixir-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/elixir.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-elixir-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/elixir.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-go-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/go.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-go-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/go.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-java-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/java.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-java-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/java.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-javascript-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/javascript.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-javascript-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/javascript.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ocaml-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/ocaml.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ocaml-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/ocaml.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-php-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/php.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-php-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/php.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-python-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/python.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-python-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/python.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ql-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/ql.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ql-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/ql.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ruby-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/ruby.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-ruby-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/ruby.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-rust-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/rust.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-rust-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/rust.scm diff --git a/extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-typescript-tags.scm b/extensions/vscode/tree-sitter/code-snippet-queries/typescript.scm similarity index 100% rename from extensions/vscode/tree-sitter/code-snippet-queries/tree-sitter-typescript-tags.scm rename to extensions/vscode/tree-sitter/code-snippet-queries/typescript.scm diff --git a/extensions/vscode/tree-sitter/import-queries/typescript.scm b/extensions/vscode/tree-sitter/import-queries/typescript.scm new file mode 100644 index 000000000..19a4d024a --- /dev/null +++ b/extensions/vscode/tree-sitter/import-queries/typescript.scm @@ -0,0 +1,9 @@ +(import_statement + (import_clause + (named_imports + (import_specifier + (identifier) @import)))) + +(import_statement + (import_clause + (identifier) @import )) \ No newline at end of file diff --git a/gui/src/App.tsx b/gui/src/App.tsx index bc051c1d9..f72f9aaa8 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -11,13 +11,12 @@ import ErrorPage from "./pages/error"; import GUI from "./pages/gui"; import { default as Help, default as HelpPage } from "./pages/help"; import History from "./pages/history"; -import LocalOnboarding from "./pages/localOnboarding"; import MigrationPage from "./pages/migration"; import MonacoPage from "./pages/monaco"; import ApiKeyAutocompleteOnboarding from "./pages/onboarding/apiKeyAutocompleteOnboarding"; -import ApiKeyOnboarding from "./pages/onboarding/apiKeyOnboarding"; -import ExistingUserOnboarding from "./pages/onboarding/existingUserOnboarding"; -import Onboarding from "./pages/onboarding/onboarding"; +import ApiKeysOnboarding from "./pages/onboarding/ApiKeysOnboarding"; +import LocalOnboarding from "./pages/onboarding/LocalOnboarding"; +import Onboarding from "./pages/onboarding/Onboarding"; import SettingsPage from "./pages/settings"; import Stats from "./pages/stats"; @@ -71,10 +70,6 @@ const router = createMemoryRouter([ path: "/onboarding", element: , }, - { - path: "/existingUserOnboarding", - element: , - }, { path: "/localOnboarding", element: , @@ -84,8 +79,8 @@ const router = createMemoryRouter([ element: , }, { - path: "/apiKeyOnboarding", - element: , + path: "/apiKeysOnboarding", + element: , }, { path: "/apiKeyAutocompleteOnboarding", diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index f213ead29..a02f46905 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -26,10 +26,11 @@ import { getFontSize, isMetaEquivalentKeyPressed } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import HeaderButtonWithText from "./HeaderButtonWithText"; import TextDialog from "./dialogs"; -import { ftl } from "./dialogs/FTCDialog"; import IndexingProgressBar from "./loaders/IndexingProgressBar"; import ProgressBar from "./loaders/ProgressBar"; import ModelSelect from "./modelSelection/ModelSelect"; +import PostHogPageView from "./PosthogPageView"; +import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial"; // #region Styled Components const FOOTER_HEIGHT = "1.8em"; @@ -89,8 +90,6 @@ const DropdownPortalDiv = styled.div` // #endregion const HIDE_FOOTER_ON_PAGES = [ - "/onboarding", - "/existingUserOnboarding", "/onboarding", "/localOnboarding", "/apiKeyOnboarding", @@ -250,17 +249,20 @@ const Layout = () => { /> + {HIDE_FOOTER_ON_PAGES.includes(location.pathname) || (