diff --git a/core/autocomplete/ast.ts b/core/autocomplete/ast.ts index 220597217..30ac77a99 100644 --- a/core/autocomplete/ast.ts +++ b/core/autocomplete/ast.ts @@ -4,7 +4,7 @@ import { getParserForFile } from "../util/treeSitter"; export async function getAst( filepath: string, - fileContents: string + fileContents: string, ): Promise { const parser = await getParserForFile(filepath); @@ -18,7 +18,7 @@ export async function getAst( export async function getTreePathAtCursor( ast: Parser.Tree, - cursorIndex: number + cursorIndex: number, ): Promise { const path = [ast.rootNode]; while (path[path.length - 1].childCount > 0) { @@ -40,7 +40,7 @@ export async function getTreePathAtCursor( } export async function getScopeAroundRange( - range: RangeInFileWithContents + range: RangeInFileWithContents, ): Promise { const ast = await getAst(range.filepath, range.contents); if (!ast) { @@ -51,10 +51,10 @@ export async function getScopeAroundRange( const lines = range.contents.split("\n"); const startIndex = lines.slice(0, s.line).join("\n").length + - (lines[s.line]?.slice(s.character).length ?? 0); + (lines[s.line]?.slice(s.character).length ?? 0); const endIndex = lines.slice(0, e.line).join("\n").length + - (lines[e.line]?.slice(0, e.character).length ?? 0); + (lines[e.line]?.slice(0, e.character).length ?? 0); let node = ast.rootNode; while (node.childCount > 0) { @@ -79,11 +79,11 @@ export async function getScopeAroundRange( start: { line: node.startPosition.row, character: node.startPosition.column, - }, + }, end: { line: node.endPosition.row, character: node.endPosition.column, - } + }, }, - } + }; } diff --git a/core/autocomplete/cache.ts b/core/autocomplete/cache.ts index 3ceab63dc..bd9c24d56 100644 --- a/core/autocomplete/cache.ts +++ b/core/autocomplete/cache.ts @@ -32,14 +32,14 @@ export class AutocompleteLruCache { async get(key: string): Promise { const result = await this.db.get( "SELECT value FROM cache WHERE key = ?", - key + key, ); if (result) { await this.db.run( "UPDATE cache SET timestamp = ? WHERE key = ?", Date.now(), - key + key, ); return result.value; } @@ -50,7 +50,7 @@ export class AutocompleteLruCache { async put(key: string, value: string) { const result = await this.db.get( "SELECT key FROM cache WHERE key = ?", - key + key, ); if (result) { @@ -58,14 +58,14 @@ export class AutocompleteLruCache { "UPDATE cache SET value = ?, timestamp = ? WHERE key = ?", value, Date.now(), - key + key, ); } else { const count = await this.db.get("SELECT COUNT(*) as count FROM cache"); if (count.count >= AutocompleteLruCache.capacity) { await this.db.run( - "DELETE FROM cache WHERE key = (SELECT key FROM cache ORDER BY timestamp ASC LIMIT 1)" + "DELETE FROM cache WHERE key = (SELECT key FROM cache ORDER BY timestamp ASC LIMIT 1)", ); } @@ -73,7 +73,7 @@ export class AutocompleteLruCache { "INSERT INTO cache (key, value, timestamp) VALUES (?, ?, ?)", key, value, - Date.now() + Date.now(), ); } } diff --git a/core/autocomplete/charStream.ts b/core/autocomplete/charStream.ts index 5994c7759..c1b787127 100644 --- a/core/autocomplete/charStream.ts +++ b/core/autocomplete/charStream.ts @@ -1,6 +1,6 @@ export async function* onlyWhitespaceAfterEndOfLine( stream: AsyncGenerator, - endOfLine: string[] + endOfLine: string[], ): AsyncGenerator { let pending = ""; for await (let chunk of stream) { diff --git a/core/autocomplete/constructPrompt.ts b/core/autocomplete/constructPrompt.ts index 44333dae2..9ba4083c3 100644 --- a/core/autocomplete/constructPrompt.ts +++ b/core/autocomplete/constructPrompt.ts @@ -10,11 +10,16 @@ import { getBasename } from "../util"; import { getAst, getTreePathAtCursor } from "./ast"; import { AutocompleteLanguageInfo, LANGUAGES, Typescript } from "./languages"; -import { AutocompleteSnippet, fillPromptWithSnippets, rankSnippets, removeRangeFromSnippets } from "./ranking"; +import { + AutocompleteSnippet, + fillPromptWithSnippets, + rankSnippets, + removeRangeFromSnippets, +} from "./ranking"; import { slidingWindowMatcher } from "./slidingWindow"; export function languageForFilepath( - filepath: string + filepath: string, ): AutocompleteLanguageInfo { return LANGUAGES[filepath.split(".").slice(-1)[0]] || Typescript; } @@ -22,12 +27,15 @@ export function languageForFilepath( function formatExternalSnippet( filepath: string, snippet: string, - language: AutocompleteLanguageInfo + language: AutocompleteLanguageInfo, ) { const comment = language.comment; const lines = [ comment + " Path: " + getBasename(filepath), - ...snippet.trim().split("\n").map((line) => comment + " " + line), + ...snippet + .trim() + .split("\n") + .map((line) => comment + " " + line), comment, ]; return lines.join("\n"); @@ -37,7 +45,7 @@ const BLOCK_TYPES = ["body", "statement_block"]; function shouldCompleteMultilineAst( treePath: Parser.SyntaxNode[], - cursorLine: number + cursorLine: number, ): boolean { // If at the base of the file, do multiline if (treePath.length === 1) { @@ -65,7 +73,7 @@ function shouldCompleteMultilineAst( async function shouldCompleteMultiline( filepath: string, fullPrefix: string, - fullSuffix: string + fullSuffix: string, ): Promise { // Use AST to determine whether to complete multiline let treePath: Parser.SyntaxNode[] | undefined; @@ -99,7 +107,7 @@ export async function constructAutocompletePrompt( recentlyEditedRanges: RangeInFileWithContents[], recentlyEditedDocuments: RangeInFileWithContents[], modelName: string, - extraSnippets: AutocompleteSnippet[] + extraSnippets: AutocompleteSnippet[], ): Promise<{ prefix: string; suffix: string; @@ -111,78 +119,88 @@ export async function constructAutocompletePrompt( const windowAroundCursor = fullPrefix.slice( - -options.slidingWindowSize * options.slidingWindowPrefixPercentage + -options.slidingWindowSize * options.slidingWindowPrefixPercentage, ) + fullSuffix.slice( - options.slidingWindowSize * (1 - options.slidingWindowPrefixPercentage) + options.slidingWindowSize * (1 - options.slidingWindowPrefixPercentage), ); const slidingWindowMatches = await slidingWindowMatcher( recentlyEditedDocuments, windowAroundCursor, 3, - options.slidingWindowSize + options.slidingWindowSize, ); snippets.push(...slidingWindowMatches); - const recentlyEdited = (await Promise.all( - recentlyEditedRanges - .map(async (r) => { + const recentlyEdited = ( + await Promise.all( + recentlyEditedRanges.map(async (r) => { return r; // return await getScopeAroundRange(r); - }) - )).filter((s) => !!s); + }), + ) + ).filter((s) => !!s); snippets.push(...(recentlyEdited as any)); // Rank / order the snippets - const scoredSnippets = rankSnippets(snippets, windowAroundCursor) + const scoredSnippets = rankSnippets(snippets, windowAroundCursor); // Fill maxSnippetTokens with snippets - const maxSnippetTokens = options.maxPromptTokens * options.maxSnippetPercentage; - + const maxSnippetTokens = + options.maxPromptTokens * options.maxSnippetPercentage; + // Construct basic prefix - const maxPrefixTokens = - options.maxPromptTokens * options.prefixPercentage + const maxPrefixTokens = options.maxPromptTokens * options.prefixPercentage; let prefix = pruneLinesFromTop(fullPrefix, maxPrefixTokens, modelName); - + // Construct suffix const maxSuffixTokens = Math.min( options.maxPromptTokens - countTokens(prefix, modelName), - options.maxSuffixPercentage * options.maxPromptTokens + options.maxSuffixPercentage * options.maxPromptTokens, ); let suffix = pruneLinesFromBottom(fullSuffix, maxSuffixTokens, modelName); // Remove prefix range from snippets - const prefixLines = prefix.split('\n').length; - const suffixLines = suffix.split('\n').length; + const prefixLines = prefix.split("\n").length; + const suffixLines = suffix.split("\n").length; const buffer = 8; const prefixSuffixRangeWithBuffer = { start: { line: cursorLine - prefixLines - buffer, - character: 0 + character: 0, }, end: { - line: cursorLine + suffixLines+ buffer, - character: 0 - } - } - let finalSnippets = removeRangeFromSnippets(scoredSnippets, filepath.split("://").slice(-1)[0], prefixSuffixRangeWithBuffer); + line: cursorLine + suffixLines + buffer, + character: 0, + }, + }; + let finalSnippets = removeRangeFromSnippets( + scoredSnippets, + filepath.split("://").slice(-1)[0], + prefixSuffixRangeWithBuffer, + ); // Filter snippets for those with best scores (must be above threshold) - finalSnippets = finalSnippets.filter((snippet) => snippet.score >= options.recentlyEditedSimilarityThreshold) - finalSnippets = fillPromptWithSnippets(scoredSnippets, maxSnippetTokens, modelName); - + finalSnippets = finalSnippets.filter( + (snippet) => snippet.score >= options.recentlyEditedSimilarityThreshold, + ); + finalSnippets = fillPromptWithSnippets( + scoredSnippets, + maxSnippetTokens, + modelName, + ); + // Format snippets as comments and prepend to prefix const formattedSnippets = finalSnippets - .map((snippet) => - formatExternalSnippet(snippet.filepath, snippet.contents, language) - ) - .join("\n"); + .map((snippet) => + formatExternalSnippet(snippet.filepath, snippet.contents, language), + ) + .join("\n"); if (formattedSnippets.length > 0) { prefix = formattedSnippets + "\n\n" + prefix; } - return { prefix, suffix, @@ -190,7 +208,7 @@ export async function constructAutocompletePrompt( completeMultiline: await shouldCompleteMultiline( filepath, fullPrefix, - fullSuffix + fullSuffix, ), }; } diff --git a/core/autocomplete/parameters.ts b/core/autocomplete/parameters.ts index 3f14abf5c..fdc72932e 100644 --- a/core/autocomplete/parameters.ts +++ b/core/autocomplete/parameters.ts @@ -13,5 +13,5 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = { maxSnippetPercentage: 0.6, recentlyEditedSimilarityThreshold: 0.3, useCache: true, - onlyMyCode: true + onlyMyCode: true, }; diff --git a/core/autocomplete/ranking.ts b/core/autocomplete/ranking.ts index 0c0970f7b..0d2609d70 100644 --- a/core/autocomplete/ranking.ts +++ b/core/autocomplete/ranking.ts @@ -43,7 +43,7 @@ export function jaccardSimilarity(a: string, b: string): number { */ export function rankSnippets( ranges: RangeInFileWithContents[], - windowAroundCursor: string + windowAroundCursor: string, ): AutocompleteSnippet[] { const snippets = ranges.map((snippet) => ({ score: jaccardSimilarity(snippet.contents, windowAroundCursor), @@ -57,7 +57,7 @@ export function rankSnippets( * Deduplicate code snippets by merging overlapping ranges into a single range. */ export function deduplicateSnippets( - snippets: AutocompleteSnippet[] + snippets: AutocompleteSnippet[], ): AutocompleteSnippet[] { // Group by file const fileGroups: { [key: string]: AutocompleteSnippet[] } = {}; @@ -77,14 +77,14 @@ export function deduplicateSnippets( } function mergeSnippetsByRange( - snippets: AutocompleteSnippet[] + snippets: AutocompleteSnippet[], ): AutocompleteSnippet[] { if (snippets.length === 0) { return snippets; } const sorted = snippets.sort( - (a, b) => a.range.start.line - b.range.start.line + (a, b) => a.range.start.line - b.range.start.line, ); const merged: AutocompleteSnippet[] = []; @@ -106,23 +106,26 @@ function mergeSnippetsByRange( function mergeOverlappingRangeContents( first: RangeInFileWithContents, - second: RangeInFileWithContents + second: RangeInFileWithContents, ): string { const firstLines = first.contents.split("\n"); const numOverlapping = first.range.end.line - second.range.start.line; return firstLines.slice(-numOverlapping).join("\n") + "\n" + second.contents; } - /** * Fill the allowed space with snippets */ -export function fillPromptWithSnippets(snippets: AutocompleteSnippet[], maxSnippetTokens: number, modelName: string): AutocompleteSnippet[] { +export function fillPromptWithSnippets( + snippets: AutocompleteSnippet[], + maxSnippetTokens: number, + modelName: string, +): AutocompleteSnippet[] { let tokensRemaining = maxSnippetTokens; - const keptSnippets: AutocompleteSnippet[] = [] + const keptSnippets: AutocompleteSnippet[] = []; for (let i = 0; i < snippets.length; i++) { const snippet = snippets[i]; - const tokenCount = countTokens(snippet.contents, modelName) + const tokenCount = countTokens(snippet.contents, modelName); if (tokensRemaining - tokenCount >= 0) { tokensRemaining -= tokenCount; keptSnippets.push(snippet); @@ -132,24 +135,24 @@ export function fillPromptWithSnippets(snippets: AutocompleteSnippet[], maxSnipp } return keptSnippets; -}; +} function rangeIntersectionByLines(a: Range, b: Range): Range | null { const startLine = Math.max(a.start.line, b.start.line); const endLine = Math.min(a.end.line, b.end.line); - if (startLine >= endLine) { + if (startLine >= endLine) { return null; } else { return { start: { line: startLine, - character: 0 + character: 0, }, end: { line: endLine, - character: 0 - } - } + character: 0, + }, + }; } } @@ -157,37 +160,60 @@ function rangeIntersectionByLines(a: Range, b: Range): Range | null { * Remove one range from another range, which may lead to returning two disjoint ranges */ function rangeDifferenceByLines(orig: Range, remove: Range): Range[] { - if (orig.start.line >= remove.start.line && orig.end.line <= remove.end.line) { + if ( + orig.start.line >= remove.start.line && + orig.end.line <= remove.end.line + ) { // / | | / return []; - } else if (orig.start.line <= remove.start.line && orig.end.line >= remove.end.line) { + } else if ( + orig.start.line <= remove.start.line && + orig.end.line >= remove.end.line + ) { // | / / | // Splits the range - return [{ - start: orig.start, - end: remove.start - }, { - start: remove.end, - end: orig.end - }] - } else if (orig.start.line >= remove.start.line && orig.end.line >= remove.end.line) { + return [ + { + start: orig.start, + end: remove.start, + }, + { + start: remove.end, + end: orig.end, + }, + ]; + } else if ( + orig.start.line >= remove.start.line && + orig.end.line >= remove.end.line + ) { // \ | / | - return [{ - start: remove.end, - end: orig.end - }] - } else if (orig.start.line <= remove.start.line && orig.end.line <= remove.end.line) { + return [ + { + start: remove.end, + end: orig.end, + }, + ]; + } else if ( + orig.start.line <= remove.start.line && + orig.end.line <= remove.end.line + ) { // | / | / - return [{ - start: orig.start, - end: remove.start - }] + return [ + { + start: orig.start, + end: remove.start, + }, + ]; } else { - return [orig] + return [orig]; } } -export function removeRangeFromSnippets(snippets: AutocompleteSnippet[], filepath: string, range: Range): AutocompleteSnippet[] { +export function removeRangeFromSnippets( + snippets: AutocompleteSnippet[], + filepath: string, + range: Range, +): AutocompleteSnippet[] { const finalSnippets: AutocompleteSnippet[] = []; for (let snippet of snippets) { if (snippet.filepath !== filepath) { @@ -199,9 +225,14 @@ export function removeRangeFromSnippets(snippets: AutocompleteSnippet[], filepat if (!intersection) { finalSnippets.push(snippet); } else { - finalSnippets.push(...rangeDifferenceByLines(snippet.range, intersection).map(range => ({...snippet, range}))); + finalSnippets.push( + ...rangeDifferenceByLines(snippet.range, intersection).map((range) => ({ + ...snippet, + range, + })), + ); } } return finalSnippets; -} \ No newline at end of file +} diff --git a/core/autocomplete/retrieval.ts b/core/autocomplete/retrieval.ts index 2beb3b44d..00272d377 100644 --- a/core/autocomplete/retrieval.ts +++ b/core/autocomplete/retrieval.ts @@ -5,7 +5,7 @@ import { IndexTag } from "../indexing/types"; export async function fullTextRetrieve( prefix: string, suffix: string, - indexTag: IndexTag + indexTag: IndexTag, ): Promise { const index = new FullTextSearchCodebaseIndex(); const searchStrings = prefix.split("\n").slice(-3); @@ -16,7 +16,7 @@ export async function fullTextRetrieve( searchString, 3, undefined, - undefined + undefined, ); results.push(...chunks); }); diff --git a/core/autocomplete/slidingWindow.ts b/core/autocomplete/slidingWindow.ts index cfcdbb340..253860925 100644 --- a/core/autocomplete/slidingWindow.ts +++ b/core/autocomplete/slidingWindow.ts @@ -3,7 +3,7 @@ import { AutocompleteSnippet, jaccardSimilarity } from "./ranking"; function* slidingWindow( content: string, - windowSize: number + windowSize: number, ): Generator { const lines = content.split("\n"); @@ -35,7 +35,7 @@ export async function slidingWindowMatcher( recentDocuments: RangeInFileWithContents[], windowAroundCursor: string, topN: number, - windowSize: number + windowSize: number, ): Promise { // Sorted lowest similarity to highest const topMatches: AutocompleteSnippet[] = []; diff --git a/core/autocomplete/util.ts b/core/autocomplete/util.ts index 79560c4de..f27b149ea 100644 --- a/core/autocomplete/util.ts +++ b/core/autocomplete/util.ts @@ -71,13 +71,13 @@ export class GeneratorReuseManager { private static _createListenableGenerator( gen: AsyncGenerator, - prefix: string + prefix: string, ) { GeneratorReuseManager.currentGenerator?.cancel(); const listenableGen = new ListenableGenerator(gen); listenableGen.listen( - (chunk) => (GeneratorReuseManager.pendingCompletion += chunk ?? "") + (chunk) => (GeneratorReuseManager.pendingCompletion += chunk ?? ""), ); GeneratorReuseManager.pendingGeneratorPrefix = prefix; @@ -87,7 +87,7 @@ export class GeneratorReuseManager { static async *getGenerator( prefix: string, - newGenerator: () => AsyncGenerator + newGenerator: () => AsyncGenerator, ): AsyncGenerator { // Check if current can be reused if ( diff --git a/core/commands/index.ts b/core/commands/index.ts index f686f9273..ff0dc35db 100644 --- a/core/commands/index.ts +++ b/core/commands/index.ts @@ -3,7 +3,7 @@ import { stripImages } from "../llm/countTokens"; import SlashCommands from "./slash"; export function slashFromCustomCommand( - customCommand: CustomCommand + customCommand: CustomCommand, ): SlashCommand { return { name: customCommand.name, @@ -30,7 +30,7 @@ export function slashFromCustomCommand( } export function slashCommandFromDescription( - desc: SlashCommandDescription + desc: SlashCommandDescription, ): SlashCommand | undefined { const cmd = SlashCommands.find((cmd) => cmd.name === desc.name); if (!cmd) { diff --git a/core/commands/slash/draftIssue.ts b/core/commands/slash/draftIssue.ts index 2250151da..1dd2c8cc4 100644 --- a/core/commands/slash/draftIssue.ts +++ b/core/commands/slash/draftIssue.ts @@ -4,7 +4,7 @@ import { removeQuotesAndEscapes } from "../../util"; const PROMPT = ( input: string, - title: string + title: string, ) => `You will be asked to generate the body of a GitHub issue given a user request. You should follow these rules: - Be descriptive but do not make up details - If the the user request includes any code snippets that are relevant, reference them in code blocks @@ -31,7 +31,7 @@ const DraftIssueCommand: SlashCommand = { } let title = await llm.complete( `Generate a title for the GitHub issue requested in this user input: '${input}'. Use no more than 20 words and output nothing other than the title. Do not surround it with quotes. The title is: `, - { maxTokens: 20 } + { maxTokens: 20 }, ); title = removeQuotesAndEscapes(title.trim()) + "\n\n"; @@ -49,7 +49,7 @@ const DraftIssueCommand: SlashCommand = { } const url = `${params.repositoryUrl}/issues/new?title=${encodeURIComponent( - title + title, )}&body=${encodeURIComponent(body)}`; yield `\n\n[Link to draft of issue](${url})`; }, diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index f94172499..54ada4e0b 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -54,7 +54,7 @@ export async function getPromptParts( fullFileContents: string, model: ILLM, input: string, - tokenLimit: number | undefined + tokenLimit: number | undefined, ) { let maxTokens = Math.floor(model.contextLength / 2); @@ -119,7 +119,7 @@ export async function getPromptParts( fileSuffix = lastLine + fileSuffix; rif.contents = rif.contents.substring( 0, - rif.contents.length - lastLine.length + rif.contents.length - lastLine.length, ); lines = rif.contents.split(/\r?\n/); lastLine = lines[lines.length - 1] || null; @@ -141,7 +141,7 @@ function compilePrompt( filePrefix: string, contents: string, fileSuffix: string, - input: string + input: string, ): string { if (contents.trim() == "") { // Separate prompt for insertion at the cursor, the other tends to cause it to repeat whole file @@ -216,11 +216,11 @@ const EditSlashCommand: SlashCommand = { run: async function* ({ ide, llm, input, history, contextItems, params }) { let contextItemToEdit = contextItems.find( (item: ContextItemWithId) => - item.editing && item.id.providerTitle === "code" + item.editing && item.id.providerTitle === "code", ); if (!contextItemToEdit) { contextItemToEdit = contextItems.find( - (item: ContextItemWithId) => item.id.providerTitle === "code" + (item: ContextItemWithId) => item.id.providerTitle === "code", ); } @@ -236,11 +236,11 @@ const EditSlashCommand: SlashCommand = { if (part.text && part.text.startsWith("/edit")) { part.text = part.text.replace("/edit", "").trimStart(); } - }) + }); } let userInput = stripImages(content).replace( `\`\`\`${contextItemToEdit.name}\n${contextItemToEdit.content}\n\`\`\`\n`, - "" + "", ); const rif: RangeInFileWithContents = @@ -254,7 +254,7 @@ const EditSlashCommand: SlashCommand = { fullFileContents, llm, userInput, - params?.tokenLimit + params?.tokenLimit, ); const [dedentedContents, commonWhitespace] = dedentAndGetCommonWhitespace(contents); @@ -264,7 +264,7 @@ const EditSlashCommand: SlashCommand = { let fullFileContentsLines = fullFileContents.split("\n"); let fullPrefixLines = fullFileContentsLines.slice( 0, - Math.max(0, rif.range.start.line - 1) + Math.max(0, rif.range.start.line - 1), ); let fullSuffixLines = fullFileContentsLines.slice(rif.range.end.line); @@ -426,7 +426,7 @@ const EditSlashCommand: SlashCommand = { // Make sure they are sorted by index indicesOfLastMatchedLines = indicesOfLastMatchedLines.sort( - (a, b) => a[0] - b[0] + (a, b) => a[0] - b[0], ); currentBlockLines.push(line); @@ -457,7 +457,7 @@ const EditSlashCommand: SlashCommand = { fileSuffix: fileSuffix, systemMessage: llm.systemMessage || "", // "contextItems": (await sdk.getContextItemChatMessages()).map(x => x.content || "").join("\n\n"), - } + }, ); if (typeof rendered === "string") { messages = [ @@ -481,7 +481,7 @@ const EditSlashCommand: SlashCommand = { lineStream = filterEnglishLinesAtEnd(filterCodeBlockLines(lineStream)); generator = streamWithNewLines( - fixCodeLlamaFirstLineIndentation(lineStream) + fixCodeLlamaFirstLineIndentation(lineStream), ); } else { async function* gen() { @@ -490,7 +490,7 @@ const EditSlashCommand: SlashCommand = { maxTokens: Math.min( maxTokens, Math.floor(llm.contextLength / 2), - 4096 + 4096, ), })) { yield stripImages(chunk.content); @@ -567,7 +567,7 @@ const EditSlashCommand: SlashCommand = { unfinishedLine?.startsWith("<") ? commonWhitespace : commonWhitespace + unfinishedLine, - ]) + ]), ); } diff --git a/core/commands/slash/stackOverflow.ts b/core/commands/slash/stackOverflow.ts index 4d263cdff..6ec8b8cf0 100644 --- a/core/commands/slash/stackOverflow.ts +++ b/core/commands/slash/stackOverflow.ts @@ -3,7 +3,7 @@ import { pruneStringFromBottom, stripImages } from "../../llm/countTokens"; const SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app"; const PROMPT = ( - input: string + input: string, ) => `The above sources are excerpts from related StackOverflow questions. Use them to help answer the below question from our user. Provide links to the sources in markdown whenever possible: ${input} @@ -82,7 +82,7 @@ const StackOverflowSlashCommand: SlashCommand = { sources[sources.length - 1] = pruneStringFromBottom( llm.model, contextLength - (totalTokens - newTokens), - sources[sources.length - 1] + sources[sources.length - 1], ); shouldBreak = true; } diff --git a/core/commands/util.ts b/core/commands/util.ts index e9ec5943d..f7111beb6 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -10,7 +10,7 @@ export interface RangeInFileWithContents { } export function contextItemToRangeInFileWithContents( - item: ContextItemWithId + item: ContextItemWithId, ): RangeInFileWithContents { const lines = item.name.split("(")[1].split(")")[0].split("-"); diff --git a/core/config/default.ts b/core/config/default.ts index 3cf7d4390..11474e8e5 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -63,7 +63,7 @@ export const defaultConfig: SerializedContinueConfig = { title: "Starcoder 3b", provider: "ollama", model: "starcoder-3b", - } + }, }; export const defaultConfigJetBrains: SerializedContinueConfig = { diff --git a/core/config/handler.ts b/core/config/handler.ts index 2930d547d..85bc7f844 100644 --- a/core/config/handler.ts +++ b/core/config/handler.ts @@ -23,7 +23,7 @@ export class ConfigHandler { ide: IDE, remoteConfigServerUrl: URL | undefined, writeLog: (text: string) => void, - onConfigUpdate: () => void + onConfigUpdate: () => void, ) { this.ide = ide; this.remoteConfigServerUrl = remoteConfigServerUrl; @@ -40,7 +40,7 @@ export class ConfigHandler { this.savedConfig = undefined; this.savedBrowserConfig = undefined; this.loadConfig(); - this.onConfigUpdate() + this.onConfigUpdate(); } async getSerializedConfig(): Promise { @@ -69,7 +69,7 @@ export class ConfigHandler { this.ide.readFile, workspaceConfigs, this.remoteConfigServerUrl, - ideInfo.ideType + ideInfo.ideType, ); this.savedConfig.allowAnonymousTelemetry = this.savedConfig.allowAnonymousTelemetry && @@ -78,7 +78,7 @@ export class ConfigHandler { // Setup telemetry only after (and if) we know it is enabled await Telemetry.setup( this.savedConfig.allowAnonymousTelemetry ?? true, - await this.ide.getUniqueId() + await this.ide.getUniqueId(), ); return this.savedConfig; @@ -98,7 +98,7 @@ export class ConfigHandler { : llm.requestOptions?.caBundlePath; if (customCerts) { ca.push( - ...customCerts.map((customCert) => fs.readFileSync(customCert, "utf8")) + ...customCerts.map((customCert) => fs.readFileSync(customCert, "utf8")), ); } @@ -174,7 +174,7 @@ export class ConfigHandler { } } throw new Error( - `HTTP ${resp.status} ${resp.statusText} from ${resp.url}\n\n${text}` + `HTTP ${resp.status} ${resp.statusText} from ${resp.url}\n\n${text}`, ); } diff --git a/core/config/load.ts b/core/config/load.ts index cdeff8db9..8771c1d7e 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -51,7 +51,7 @@ function resolveSerializedConfig(filepath: string): SerializedContinueConfig { config.env.forEach((envVar) => { content = content.replaceAll( new RegExp(`"${envVar}"`, "g"), - `"${env[envVar]}"` + `"${env[envVar]}"`, ); }); } @@ -60,16 +60,16 @@ function resolveSerializedConfig(filepath: string): SerializedContinueConfig { } const configMergeKeys = { - "models": (a: any, b: any) => a.title === b.title, - "contextProviders": (a: any, b: any) => a.name === b.name, - "slashCommands": (a: any, b: any) => a.name === b.name, - "customCommands": (a: any, b: any) => a.name === b.name, -} + models: (a: any, b: any) => a.title === b.title, + contextProviders: (a: any, b: any) => a.name === b.name, + slashCommands: (a: any, b: any) => a.name === b.name, + customCommands: (a: any, b: any) => a.name === b.name, +}; function loadSerializedConfig( workspaceConfigs: ContinueRcJson[], remoteConfigServerUrl: URL | undefined, - ideType: IdeType + ideType: IdeType, ): SerializedContinueConfig { const configPath = getConfigJsonPath(ideType); let config = resolveSerializedConfig(configPath); @@ -133,20 +133,25 @@ function loadSerializedConfig( if (remoteConfigServerUrl) { const remoteConfigJson = resolveSerializedConfig( - getConfigJsonPathForRemote(remoteConfigServerUrl) + getConfigJsonPathForRemote(remoteConfigServerUrl), ); config = mergeJson(config, remoteConfigJson, "merge", configMergeKeys); } for (const workspaceConfig of workspaceConfigs) { - config = mergeJson(config, workspaceConfig, workspaceConfig.mergeBehavior, configMergeKeys); + config = mergeJson( + config, + workspaceConfig, + workspaceConfig.mergeBehavior, + configMergeKeys, + ); } return config; } function serializedToIntermediateConfig( - initial: SerializedContinueConfig + initial: SerializedContinueConfig, ): Config { const slashCommands: SlashCommand[] = []; for (const command of initial.slashCommands || []) { @@ -169,13 +174,13 @@ function serializedToIntermediateConfig( } function isModelDescription( - llm: ModelDescription | CustomLLM + llm: ModelDescription | CustomLLM, ): llm is ModelDescription { return (llm as ModelDescription).title !== undefined; } function isContextProviderWithParams( - contextProvider: CustomContextProvider | ContextProviderWithParams + contextProvider: CustomContextProvider | ContextProviderWithParams, ): contextProvider is ContextProviderWithParams { return (contextProvider as ContextProviderWithParams).name !== undefined; } @@ -183,7 +188,7 @@ function isContextProviderWithParams( /** Only difference between intermediate and final configs is the `models` array */ async function intermediateToFinalConfig( config: Config, - readFile: (filepath: string) => Promise + readFile: (filepath: string) => Promise, ): Promise { const models: BaseLLM[] = []; for (const desc of config.models) { @@ -192,7 +197,7 @@ async function intermediateToFinalConfig( desc, readFile, config.completionOptions, - config.systemMessage + config.systemMessage, ); if (!llm) continue; @@ -209,14 +214,14 @@ async function intermediateToFinalConfig( }, readFile, config.completionOptions, - config.systemMessage + config.systemMessage, ); - }) + }), ); models.push( ...(detectedModels.filter( - (x) => typeof x !== "undefined" - ) as BaseLLM[]) + (x) => typeof x !== "undefined", + ) as BaseLLM[]), ); } catch (e) { console.warn("Error listing models: ", e); @@ -234,7 +239,7 @@ async function intermediateToFinalConfig( new CustomLLMClass({ ...desc, options: { ...desc.options, model: modelName }, - }) + }), ); models.push(...models); @@ -254,7 +259,7 @@ async function intermediateToFinalConfig( config.tabAutocompleteModel, readFile, config.completionOptions, - config.systemMessage + config.systemMessage, ); } else { autocompleteLlm = new CustomLLMClass(config.tabAutocompleteModel); @@ -298,7 +303,7 @@ async function intermediateToFinalConfig( } function finalToBrowserConfig( - final: ContinueConfig + final: ContinueConfig, ): BrowserSerializedContinueConfig { return { allowAnonymousTelemetry: final.allowAnonymousTelemetry, @@ -375,10 +380,10 @@ async function buildConfigTs() { `/esbuild${ getTarget().startsWith("win32") ? ".exe" : "" } ${escapeSpacesInPath( - getConfigTsPath() + getConfigTsPath(), )} --bundle --outfile=${escapeSpacesInPath( - getConfigJsPath() - )} --platform=node --format=cjs --sourcemap --external:fetch --external:fs --external:path --external:os --external:child_process` + getConfigJsPath(), + )} --platform=node --format=cjs --sourcemap --external:fetch --external:fs --external:path --external:os --external:child_process`, ); } else { // Dynamic import esbuild so potentially disastrous errors can be caught @@ -396,7 +401,7 @@ async function buildConfigTs() { } } catch (e) { console.log( - "Build error. Please check your ~/.continue/config.ts file: " + e + "Build error. Please check your ~/.continue/config.ts file: " + e, ); return undefined; } @@ -411,12 +416,12 @@ async function loadFullConfigNode( readFile: (filepath: string) => Promise, workspaceConfigs: ContinueRcJson[], remoteConfigServerUrl: URL | undefined, - ideType: IdeType + ideType: IdeType, ): Promise { let serialized = loadSerializedConfig( workspaceConfigs, remoteConfigServerUrl, - ideType + ideType, ); let intermediate = serializedToIntermediateConfig(serialized); @@ -440,7 +445,7 @@ async function loadFullConfigNode( if (remoteConfigServerUrl) { try { const configJsPathForRemote = getConfigJsPathForRemote( - remoteConfigServerUrl + remoteConfigServerUrl, ); const module = await require(configJsPathForRemote); delete require.cache[require.resolve(configJsPathForRemote)]; @@ -462,5 +467,5 @@ export { intermediateToFinalConfig, loadFullConfigNode, serializedToIntermediateConfig, - type BrowserSerializedContinueConfig + type BrowserSerializedContinueConfig, }; diff --git a/core/config/util.ts b/core/config/util.ts index 94ebda6b8..154b819f8 100644 --- a/core/config/util.ts +++ b/core/config/util.ts @@ -11,7 +11,7 @@ export function addModel(model: ModelDescription) { (key, value) => { return value === null ? undefined : value; }, - 2 + 2, ); writeFileSync(getConfigJsonPath(), newConfigString); return newConfigString; diff --git a/core/context/index.ts b/core/context/index.ts index c462b52d2..24dbdd92f 100644 --- a/core/context/index.ts +++ b/core/context/index.ts @@ -22,11 +22,11 @@ export abstract class BaseContextProvider implements IContextProvider { // Maybe just include the chat message in here. Should never have to go back to the context provider once you have the information. abstract getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise; async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { return []; } diff --git a/core/context/providers/CodeHighlightsContextProvider.ts b/core/context/providers/CodeHighlightsContextProvider.ts index ebf0405f1..761bd4495 100644 --- a/core/context/providers/CodeHighlightsContextProvider.ts +++ b/core/context/providers/CodeHighlightsContextProvider.ts @@ -20,7 +20,7 @@ class CodeHighlightsContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const ide = extras.ide; const openFiles = await ide.getOpenFiles(); @@ -32,7 +32,7 @@ class CodeHighlightsContextProvider extends BaseContextProvider { absPath: filepath, content: `${await ide.readFile(filepath)}`, }; - }) + }), ); // const contextSizer = { // fits(content: string): boolean { @@ -58,7 +58,7 @@ class CodeHighlightsContextProvider extends BaseContextProvider { // description: "Code highlights from open files", // }, // ]; - return [] + return []; } async load(): Promise {} diff --git a/core/context/providers/CodeOutlineContextProvider.ts b/core/context/providers/CodeOutlineContextProvider.ts index 6667e60cf..ead6fdc85 100644 --- a/core/context/providers/CodeOutlineContextProvider.ts +++ b/core/context/providers/CodeOutlineContextProvider.ts @@ -18,7 +18,7 @@ class CodeOutlineContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const ide = extras.ide; const openFiles = await ide.getOpenFiles(); @@ -30,7 +30,7 @@ class CodeOutlineContextProvider extends BaseContextProvider { absPath: filepath, content: `${await ide.readFile(filepath)}`, }; - }) + }), ); // const outlines = await getOutlines( // allFiles @@ -49,7 +49,7 @@ class CodeOutlineContextProvider extends BaseContextProvider { // description: "Definition lines only (from open files)", // }, // ]; - return [] + return []; } async load(): Promise {} diff --git a/core/context/providers/CodebaseContextProvider.ts b/core/context/providers/CodebaseContextProvider.ts index bca80c9c0..67d695508 100644 --- a/core/context/providers/CodebaseContextProvider.ts +++ b/core/context/providers/CodebaseContextProvider.ts @@ -17,7 +17,7 @@ class CodebaseContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { return retrieveContextItemsFromEmbeddings(extras, this.options, undefined); } diff --git a/core/context/providers/CustomContextProvider.ts b/core/context/providers/CustomContextProvider.ts index 5d5ababb2..124c9e76a 100644 --- a/core/context/providers/CustomContextProvider.ts +++ b/core/context/providers/CustomContextProvider.ts @@ -25,7 +25,7 @@ class CustomContextProviderClass implements IContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { return await this.custom.getContextItems(query, extras); } diff --git a/core/context/providers/DatabaseContextProvider.ts b/core/context/providers/DatabaseContextProvider.ts index 5a5df7053..e0fa4ce3a 100644 --- a/core/context/providers/DatabaseContextProvider.ts +++ b/core/context/providers/DatabaseContextProvider.ts @@ -3,8 +3,8 @@ import { ContextItem, ContextProviderDescription, ContextProviderExtras, - LoadSubmenuItemsArgs, ContextSubmenuItem, + LoadSubmenuItemsArgs, } from "../.."; class DatabaseContextProvider extends BaseContextProvider { @@ -17,52 +17,58 @@ class DatabaseContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const contextItems: ContextItem[] = []; const connections = this.options?.connections; - if (connections === null) { return contextItems; } + if (connections === null) { + return contextItems; + } - let [connectionName, table] = query.split('.'); + let [connectionName, table] = query.split("."); const getDatabaseAdapter = await require("dbinfoz"); for (const connection of connections) { - if(connection.name == connectionName) { - const adapter = getDatabaseAdapter(connection.connection_type, connection.connection); - const tablesAndSchemas = await adapter.getAllTablesAndSchemas(connection.connection.database); + if (connection.name == connectionName) { + const adapter = getDatabaseAdapter( + connection.connection_type, + connection.connection, + ); + const tablesAndSchemas = await adapter.getAllTablesAndSchemas( + connection.connection.database, + ); - if(table === 'all') { + if (table === "all") { let prompt = `Schema for all tables on ${connection.connection_type} is `; prompt += JSON.stringify(tablesAndSchemas); let contextItem = { name: `${connectionName}-all-tables-schemas`, description: `Schema for all tables.`, - content: prompt - } + content: prompt, + }; contextItems.push(contextItem); } else { const tables = Object.keys(tablesAndSchemas); - tables.forEach(tableName => { - if(table === tableName) { + tables.forEach((tableName) => { + if (table === tableName) { let prompt = `Schema for ${tableName} on ${connection.connection_type} is `; prompt += JSON.stringify(tablesAndSchemas[tableName]); let contextItem = { name: `${connectionName}-${tableName}-schema`, description: `${tableName} Schema`, - content: prompt - } - + content: prompt, + }; + contextItems.push(contextItem); } }); - } } } @@ -71,35 +77,42 @@ class DatabaseContextProvider extends BaseContextProvider { } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const contextItems: ContextSubmenuItem[] = []; const connections = this.options?.connections; - if (connections === null) { return contextItems; } + if (connections === null) { + return contextItems; + } const getDatabaseAdapter = await require("dbinfoz"); for (const connection of connections) { - let adapter = getDatabaseAdapter(connection.connection_type, connection.connection); - const tablesAndSchemas = await adapter.getAllTablesAndSchemas(connection.connection.database); + let adapter = getDatabaseAdapter( + connection.connection_type, + connection.connection, + ); + const tablesAndSchemas = await adapter.getAllTablesAndSchemas( + connection.connection.database, + ); const tables = Object.keys(tablesAndSchemas); let contextItem = { - id: `${connection.name}.all`, - title: `${connection.name} all table schemas`, - description: `` - } - + id: `${connection.name}.all`, + title: `${connection.name} all table schemas`, + description: ``, + }; + contextItems.push(contextItem); - tables.forEach(tableName => { + tables.forEach((tableName) => { let contextItem = { id: `${connection.name}.${tableName}`, title: `${connection.name}.${tableName} schema`, - description: `` - } - + description: ``, + }; + contextItems.push(contextItem); }); } @@ -109,4 +122,3 @@ class DatabaseContextProvider extends BaseContextProvider { } export default DatabaseContextProvider; - diff --git a/core/context/providers/DiffContextProvider.ts b/core/context/providers/DiffContextProvider.ts index 3d9e6b0c9..44b9168b5 100644 --- a/core/context/providers/DiffContextProvider.ts +++ b/core/context/providers/DiffContextProvider.ts @@ -15,7 +15,7 @@ class DiffContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const diff = await extras.ide.getDiff(); return [ diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index 803628f0c..ec20e20ef 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -18,7 +18,7 @@ class DocsContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const { retrieveDocs } = await import("../../indexing/docs/db"); @@ -28,7 +28,7 @@ class DocsContextProvider extends BaseContextProvider { const chunks = await retrieveDocs( query, vector, - this.options?.nRetrieve || 15 + this.options?.nRetrieve || 15, ); console.log(chunks); @@ -59,7 +59,7 @@ class DocsContextProvider extends BaseContextProvider { } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const { listDocs } = await import("../../indexing/docs/db"); const docs = await listDocs(); diff --git a/core/context/providers/FileContextProvider.ts b/core/context/providers/FileContextProvider.ts index d4481a2c1..70fd11df3 100644 --- a/core/context/providers/FileContextProvider.ts +++ b/core/context/providers/FileContextProvider.ts @@ -18,7 +18,7 @@ class FileContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { // Assume the query is a filepath query = query.trim(); @@ -33,13 +33,13 @@ class FileContextProvider extends BaseContextProvider { } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const workspaceDirs = await args.ide.getWorkspaceDirs(); const results = await Promise.all( workspaceDirs.map((dir) => { return args.ide.listWorkspaceContents(dir); - }) + }), ); const files = results.flat(); return files.map((file) => { diff --git a/core/context/providers/FileTreeContextProvider.ts b/core/context/providers/FileTreeContextProvider.ts index 6e8fe39f4..b51c46c1d 100644 --- a/core/context/providers/FileTreeContextProvider.ts +++ b/core/context/providers/FileTreeContextProvider.ts @@ -44,7 +44,7 @@ class FileTreeContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const workspaceDirs = await extras.ide.getWorkspaceDirs(); let trees = []; diff --git a/core/context/providers/FolderContextProvider.ts b/core/context/providers/FolderContextProvider.ts index 81955cb1e..44b7e4f6b 100644 --- a/core/context/providers/FolderContextProvider.ts +++ b/core/context/providers/FolderContextProvider.ts @@ -18,13 +18,13 @@ class FolderContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const { retrieveContextItemsFromEmbeddings } = await import("../retrieval"); return retrieveContextItemsFromEmbeddings(extras, this.options, query); } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const folders = await args.ide.listFolders(); return folders.map((folder) => { diff --git a/core/context/providers/GitHubIssuesContextProvider.ts b/core/context/providers/GitHubIssuesContextProvider.ts index f94e10768..c3464af75 100644 --- a/core/context/providers/GitHubIssuesContextProvider.ts +++ b/core/context/providers/GitHubIssuesContextProvider.ts @@ -17,7 +17,7 @@ class GitHubIssuesContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const issueId = query; const { Octokit } = await import("@octokit/rest"); @@ -58,7 +58,7 @@ class GitHubIssuesContextProvider extends BaseContextProvider { } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const { Octokit } = await import("@octokit/rest"); @@ -83,7 +83,7 @@ class GitHubIssuesContextProvider extends BaseContextProvider { repo: repo.repo, issue_number: issue.number, }), - })) + })), ); } diff --git a/core/context/providers/GoogleContextProvider.ts b/core/context/providers/GoogleContextProvider.ts index 0f0a562e6..c2ee4877b 100644 --- a/core/context/providers/GoogleContextProvider.ts +++ b/core/context/providers/GoogleContextProvider.ts @@ -22,7 +22,7 @@ class GoogleContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const url = "https://google.serper.dev/search"; diff --git a/core/context/providers/HttpContextProvider.ts b/core/context/providers/HttpContextProvider.ts index 83c9fb13e..c72d8c654 100644 --- a/core/context/providers/HttpContextProvider.ts +++ b/core/context/providers/HttpContextProvider.ts @@ -26,7 +26,7 @@ class HttpContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const response = await fetch(this.options.url, { method: "POST", diff --git a/core/context/providers/JiraIssuesContextProvider.ts b/core/context/providers/JiraIssuesContextProvider.ts index 9c81845e4..00bed2a48 100644 --- a/core/context/providers/JiraIssuesContextProvider.ts +++ b/core/context/providers/JiraIssuesContextProvider.ts @@ -59,7 +59,7 @@ class JiraIssuesContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const issueId = query; @@ -89,7 +89,7 @@ class JiraIssuesContextProvider extends BaseContextProvider { const commentText = convert(comment.body).result; return `### ${comment.author.displayName} on ${comment.created}\n\n${commentText}`; - }) + }), ); } @@ -105,7 +105,7 @@ class JiraIssuesContextProvider extends BaseContextProvider { } async loadSubmenuItems( - args: LoadSubmenuItemsArgs + args: LoadSubmenuItemsArgs, ): Promise { const api = await this.createApi(); diff --git a/core/context/providers/OpenFilesContextProvider.ts b/core/context/providers/OpenFilesContextProvider.ts index 6da871dd3..a5b91bb34 100644 --- a/core/context/providers/OpenFilesContextProvider.ts +++ b/core/context/providers/OpenFilesContextProvider.ts @@ -16,7 +16,7 @@ class OpenFilesContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const ide = extras.ide; const openFiles = this.options?.onlyPinned @@ -27,11 +27,11 @@ class OpenFilesContextProvider extends BaseContextProvider { return { description: filepath, content: `\`\`\`${getBasename(filepath)}\n${await ide.readFile( - filepath + filepath, )}\n\`\`\``, name: (filepath.split("/").pop() || "").split("\\").pop() || "", }; - }) + }), ); } } diff --git a/core/context/providers/PostgresContextProvider.ts b/core/context/providers/PostgresContextProvider.ts index 34c829f4d..9c7e78528 100644 --- a/core/context/providers/PostgresContextProvider.ts +++ b/core/context/providers/PostgresContextProvider.ts @@ -3,8 +3,8 @@ import { ContextItem, ContextProviderDescription, ContextProviderExtras, - LoadSubmenuItemsArgs, ContextSubmenuItem, + LoadSubmenuItemsArgs, } from "../.."; class PostgresContextProvider extends BaseContextProvider { @@ -51,13 +51,13 @@ FROM information_schema.tables`; } const { rows: tablesInfo } = await pool.query(tablesInfoQuery); return tablesInfo.map( - (tableInfo: any) => `${tableInfo.table_schema}.${tableInfo.table_name}` + (tableInfo: any) => `${tableInfo.table_schema}.${tableInfo.table_name}`, ); } async getContextItems( query: string = "", - _: ContextProviderExtras = {} as ContextProviderExtras + _: ContextProviderExtras = {} as ContextProviderExtras, ): Promise { const pool = await this.getPool(); @@ -75,7 +75,7 @@ FROM information_schema.tables`; // Get the table schema if (!tableName.includes(".")) { throw new Error( - `Table name must be in format schema.table_name, got ${tableName}` + `Table name must be in format schema.table_name, got ${tableName}`, ); } var schemaQuery = ` @@ -115,7 +115,7 @@ LIMIT ${sampleRows}`); } async loadSubmenuItems( - _: LoadSubmenuItemsArgs + _: LoadSubmenuItemsArgs, ): Promise { const pool = await this.getPool(); diff --git a/core/context/providers/ProblemsContextProvider.ts b/core/context/providers/ProblemsContextProvider.ts index 82357b180..62916b8f5 100644 --- a/core/context/providers/ProblemsContextProvider.ts +++ b/core/context/providers/ProblemsContextProvider.ts @@ -16,7 +16,7 @@ class ProblemsContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const ide = extras.ide; const problems = await ide.getProblems(); @@ -28,18 +28,18 @@ class ProblemsContextProvider extends BaseContextProvider { const rangeContent = lines .slice( Math.max(0, problem.range.start.line - 2), - problem.range.end.line + 2 + problem.range.end.line + 2, ) .join("\n"); return { description: "Problems in current file", content: `\`\`\`${getBasename( - problem.filepath + problem.filepath, )}\n${rangeContent}\n\`\`\`\n${problem.message}\n\n`, name: `Warning in ${getBasename(problem.filepath)}`, }; - }) + }), ); return items.length === 0 diff --git a/core/context/providers/SearchContextProvider.ts b/core/context/providers/SearchContextProvider.ts index c3198abd1..9760d14de 100644 --- a/core/context/providers/SearchContextProvider.ts +++ b/core/context/providers/SearchContextProvider.ts @@ -15,7 +15,7 @@ class SearchContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const results = await extras.ide.getSearchResults(query); return [ diff --git a/core/context/providers/TerminalContextProvider.ts b/core/context/providers/TerminalContextProvider.ts index db1bd6f94..67e5b5957 100644 --- a/core/context/providers/TerminalContextProvider.ts +++ b/core/context/providers/TerminalContextProvider.ts @@ -15,7 +15,7 @@ class TerminalContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { const content = await extras.ide.getTerminalContents(); return [ diff --git a/core/context/providers/URLContextProvider.ts b/core/context/providers/URLContextProvider.ts index f527cbca0..a26fdf7dc 100644 --- a/core/context/providers/URLContextProvider.ts +++ b/core/context/providers/URLContextProvider.ts @@ -15,7 +15,7 @@ class URLContextProvider extends BaseContextProvider { async getContextItems( query: string, - extras: ContextProviderExtras + extras: ContextProviderExtras, ): Promise { let url = query.trim(); if (!url.startsWith("http")) { diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index c8a08ea4d..072f453fe 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -39,7 +39,7 @@ const Providers: (typeof BaseContextProvider)[] = [ ]; export function contextProviderClassFromName( - name: ContextProviderName + name: ContextProviderName, ): typeof BaseContextProvider | undefined { const cls = Providers.find((cls) => cls.description.title === name); diff --git a/core/diff/streamDiff.ts b/core/diff/streamDiff.ts index 912fc20db..a86bda9b3 100644 --- a/core/diff/streamDiff.ts +++ b/core/diff/streamDiff.ts @@ -11,7 +11,7 @@ import { LineStream, matchLine } from "./util"; */ export async function* streamDiff( oldLines: string[], - newLines: LineStream + newLines: LineStream, ): AsyncGenerator { const mutatedOldLines = [...oldLines]; // be careful let seenIndentationMistake = false; @@ -21,7 +21,7 @@ export async function* streamDiff( const [matchIndex, isPerfectMatch, newLine] = matchLine( newLineResult.value, oldLines, - seenIndentationMistake + seenIndentationMistake, ); if (!seenIndentationMistake && newLineResult.value !== newLine) { seenIndentationMistake = true; diff --git a/core/diff/util.ts b/core/diff/util.ts index 9a41b18b8..1d06b4344 100644 --- a/core/diff/util.ts +++ b/core/diff/util.ts @@ -28,7 +28,7 @@ function linesMatch(lineA: string, lineB: string): boolean { export function matchLine( newLine: string, oldLines: string[], - permissiveAboutIndentation: boolean = false + permissiveAboutIndentation: boolean = false, ): [number, boolean, string] { // Only match empty lines if it's the next one: if (newLine.trim() === "" && oldLines[0]?.trim() === "") { @@ -57,7 +57,7 @@ export function matchLine( * Convert a stream of arbitrary chunks to a stream of lines */ export async function* streamLines( - streamCompletion: AsyncGenerator + streamCompletion: AsyncGenerator, ): LineStream { let buffer = ""; for await (const chunk of streamCompletion) { diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts index e1387174e..c4bd785f2 100644 --- a/core/indexing/FullTextSearch.ts +++ b/core/indexing/FullTextSearch.ts @@ -31,7 +31,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { async *update( tag: IndexTag, results: RefreshIndexResults, - markComplete: MarkCompleteCallback + markComplete: MarkCompleteCallback, ): AsyncGenerator { const db = await SqliteDb.get(); await this._createTables(db); @@ -42,17 +42,17 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { // Insert chunks const chunks = await db.all( `SELECT * FROM chunks WHERE path = ? AND cacheKey = ?`, - [item.path, item.cacheKey] + [item.path, item.cacheKey], ); for (let chunk of chunks) { const { lastID } = await db.run( `INSERT INTO fts (path, content) VALUES (?, ?)`, - [item.path, chunk.content] + [item.path, chunk.content], ); await db.run( `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) VALUES (?, ?, ?, ?)`, - [lastID, item.path, item.cacheKey, chunk.id] + [lastID, item.path, item.cacheKey, chunk.id], ); } @@ -77,7 +77,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { for (const item of results.del) { const { lastID } = await db.run( `DELETE FROM fts_metadata WHERE path = ? AND cacheKey = ?`, - [item.path, item.cacheKey] + [item.path, item.cacheKey], ); await db.run(`DELETE FROM fts WHERE rowid = ?`, [lastID]); @@ -90,7 +90,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { text: string, n: number, directory: string | undefined, - filterPaths: string[] | undefined + filterPaths: string[] | undefined, ): Promise { const db = await SqliteDb.get(); const tagStrings = tags.map(tagToString); @@ -101,7 +101,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { JOIN chunk_tags ON fts_metadata.chunkId = chunk_tags.chunkId WHERE fts MATCH '${text.replace( /\?/g, - "" + "", )}' AND chunk_tags.tag IN (${tagStrings.map(() => "?").join(",")}) ${ filterPaths @@ -119,7 +119,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { const chunks = await db.all( `SELECT * FROM chunks WHERE id IN (${results.map(() => "?").join(",")})`, - results.map((result) => result.chunkId) + results.map((result) => result.chunkId), ); return chunks.map((chunk) => { diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 123c1d25c..1a63cc7c0 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -35,7 +35,7 @@ export class LanceDbIndex implements CodebaseIndex { constructor( embeddingsProvider: EmbeddingsProvider, - readFile: (filepath: string) => Promise + readFile: (filepath: string) => Promise, ) { this.embeddingsProvider = embeddingsProvider; this.readFile = readFile; @@ -61,7 +61,7 @@ export class LanceDbIndex implements CodebaseIndex { } private async *computeChunks( - items: PathAndCacheKey[] + items: PathAndCacheKey[], ): AsyncGenerator< | [ number, @@ -72,7 +72,7 @@ export class LanceDbIndex implements CodebaseIndex { | PathAndCacheKey > { const contents = await Promise.all( - items.map(({ path }) => this.readFile(path)) + items.map(({ path }) => this.readFile(path)), ); for (let i = 0; i < items.length; i++) { @@ -84,7 +84,7 @@ export class LanceDbIndex implements CodebaseIndex { items[i].path, content, LanceDbIndex.MAX_CHUNK_SIZE, - items[i].cacheKey + items[i].cacheKey, )) { chunks.push(chunk); } @@ -96,7 +96,7 @@ export class LanceDbIndex implements CodebaseIndex { // Calculate embeddings const embeddings = await this.embeddingsProvider.embed( - chunks.map((c) => c.content) + chunks.map((c) => c.content), ); // Create row format @@ -130,8 +130,8 @@ export class LanceDbIndex implements CodebaseIndex { results: RefreshIndexResults, markComplete: ( items: PathAndCacheKey[], - resultType: IndexResultType - ) => void + resultType: IndexResultType, + ) => void, ): AsyncGenerator { const lancedb = await import("vectordb"); const tableName = this.tableNameForTag(tag); @@ -160,7 +160,7 @@ export class LanceDbIndex implements CodebaseIndex { JSON.stringify(row.vector), data.startLine, data.endLine, - data.contents + data.contents, ); yield { progress, desc }; @@ -193,7 +193,7 @@ export class LanceDbIndex implements CodebaseIndex { const stmt = await sqlite.prepare( "SELECT * FROM lance_db_cache WHERE cacheKey = ? AND path = ?", cacheKey, - path + path, ); const cachedItems = await stmt.all(); @@ -230,7 +230,7 @@ export class LanceDbIndex implements CodebaseIndex { await sqlite.run( "DELETE FROM lance_db_cache WHERE cacheKey = ? AND path = ?", cacheKey, - path + path, ); } @@ -243,7 +243,7 @@ export class LanceDbIndex implements CodebaseIndex { n: number, directory: string | undefined, vector: number[], - db: any /// lancedb.Connection + db: any, /// lancedb.Connection ): Promise { const tableName = this.tableNameForTag(tag); const tableNames = await db.tableNames(); @@ -267,7 +267,7 @@ export class LanceDbIndex implements CodebaseIndex { tags: IndexTag[], text: string, n: number, - directory: string | undefined + directory: string | undefined, ): Promise { const lancedb = await import("vectordb"); if (!lancedb.connect) { @@ -290,7 +290,7 @@ export class LanceDbIndex implements CodebaseIndex { const data = await sqliteDb.all( `SELECT * FROM lance_db_cache WHERE uuid in (${allResults .map((r) => `'${r.uuid}'`) - .join(",")})` + .join(",")})`, ); return data.map((d) => { diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index 477328365..ab485a04a 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -42,7 +42,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex { async *update( tag: IndexTag, results: RefreshIndexResults, - markComplete: MarkCompleteCallback + markComplete: MarkCompleteCallback, ): AsyncGenerator { const db = await SqliteDb.get(); await this._createTables(db); @@ -50,7 +50,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex { // Compute chunks for new files const contents = await Promise.all( - results.compute.map(({ path }) => this.readFile(path)) + results.compute.map(({ path }) => this.readFile(path)), ); for (let i = 0; i < results.compute.length; i++) { const item = results.compute[i]; @@ -60,7 +60,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex { item.path, contents[i], MAX_CHUNK_SIZE, - item.cacheKey + item.cacheKey, )) { const { lastID } = await db.run( `INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)`, @@ -71,7 +71,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex { chunk.startLine, chunk.endLine, chunk.content, - ] + ], ); await db.run(`INSERT INTO chunk_tags (chunkId, tag) VALUES (?, ?)`, [ @@ -91,7 +91,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex { for (const item of results.addTag) { const chunksWithPath = await db.all( `SELECT * FROM chunks WHERE cacheKey = ?`, - [item.cacheKey] + [item.cacheKey], ); for (const chunk of chunksWithPath) { diff --git a/core/indexing/chunk/basic.ts b/core/indexing/chunk/basic.ts index e0e506a90..454e80202 100644 --- a/core/indexing/chunk/basic.ts +++ b/core/indexing/chunk/basic.ts @@ -3,7 +3,7 @@ import { countTokens } from "../../llm/countTokens"; export function* basicChunker( contents: string, - maxChunkSize: number + maxChunkSize: number, ): Generator { let chunkContent = ""; let chunkTokens = 0; diff --git a/core/indexing/chunk/chunk.ts b/core/indexing/chunk/chunk.ts index 84c802e15..e37d999d6 100644 --- a/core/indexing/chunk/chunk.ts +++ b/core/indexing/chunk/chunk.ts @@ -8,7 +8,7 @@ import { codeChunker } from "./code"; async function* chunkDocumentWithoutId( filepath: string, contents: string, - maxChunkSize: number + maxChunkSize: number, ): AsyncGenerator { if (contents.trim() === "") { return; @@ -35,19 +35,19 @@ export async function* chunkDocument( filepath: string, contents: string, maxChunkSize: number, - digest: string + digest: string, ): AsyncGenerator { let index = 0; for await (let chunkWithoutId of chunkDocumentWithoutId( filepath, contents, - maxChunkSize + maxChunkSize, )) { if (countTokens(chunkWithoutId.content) > MAX_CHUNK_SIZE) { console.warn( `Chunk with more than ${maxChunkSize} tokens constructed: `, filepath, - countTokens(chunkWithoutId.content) + countTokens(chunkWithoutId.content), ); continue; } diff --git a/core/indexing/chunk/code.ts b/core/indexing/chunk/code.ts index b7527d422..558009de7 100644 --- a/core/indexing/chunk/code.ts +++ b/core/indexing/chunk/code.ts @@ -13,7 +13,7 @@ function collapsedReplacement(node: SyntaxNode): string { function firstChild( node: SyntaxNode, - grammarName: string | string[] + grammarName: string | string[], ): SyntaxNode | null { if (Array.isArray(grammarName)) { return ( @@ -30,7 +30,7 @@ function collapseChildren( blockTypes: string[], collapseTypes: string[], collapseBlockTypes: string[], - maxChunkSize: number + maxChunkSize: number, ): string { code = code.slice(0, node.endIndex); const block = firstChild(node, blockTypes); @@ -38,7 +38,7 @@ function collapseChildren( if (block) { const childrenToCollapse = block.children.filter((child) => - collapseTypes.includes(child.type) + collapseTypes.includes(child.type), ); for (const child of childrenToCollapse.reverse()) { const grandChild = firstChild(child, collapseBlockTypes); @@ -99,7 +99,7 @@ function collapseChildren( function constructClassDefinitionChunk( node: SyntaxNode, code: string, - maxChunkSize: number + maxChunkSize: number, ): string { return collapseChildren( node, @@ -107,14 +107,14 @@ function constructClassDefinitionChunk( ["block", "class_body", "declaration_list"], ["method_definition", "function_definition", "function_item"], ["block", "statement_block"], - maxChunkSize + maxChunkSize, ); } function constructFunctionDefinitionChunk( node: SyntaxNode, code: string, - maxChunkSize: number + maxChunkSize: number, ): string { const bodyNode = node.children[node.children.length - 1]; const funcText = @@ -144,7 +144,7 @@ const collapsedNodeConstructors: { [key: string]: ( node: SyntaxNode, code: string, - maxChunkSize: number + maxChunkSize: number, ) => string; } = { // Classes, structs, etc @@ -161,7 +161,7 @@ function* getSmartCollapsedChunks( node: SyntaxNode, code: string, maxChunkSize: number, - root = true + root = true, ): Generator { // Keep entire text if not over size if ( @@ -194,7 +194,7 @@ function* getSmartCollapsedChunks( export async function* codeChunker( filepath: string, contents: string, - maxChunkSize: number + maxChunkSize: number, ): AsyncGenerator { if (contents.trim().length === 0) { return; diff --git a/core/indexing/chunk/markdown.ts b/core/indexing/chunk/markdown.ts index 252d43f5e..bad8360ea 100644 --- a/core/indexing/chunk/markdown.ts +++ b/core/indexing/chunk/markdown.ts @@ -55,7 +55,7 @@ function findHeader(lines: string[]): string | undefined { export async function* markdownChunker( content: string, maxChunkSize: number, - hLevel: number + hLevel: number, ): AsyncGenerator { if (countTokens(content) <= maxChunkSize) { const header = findHeader(content.split("\n")); @@ -123,7 +123,7 @@ export async function* markdownChunker( for await (const chunk of markdownChunker( section.content, maxChunkSize - (section.header ? countTokens(section.header) : 0), - hLevel + 1 + hLevel + 1, )) { yield { content: section.header + "\n" + chunk.content, diff --git a/core/indexing/docs/crawl.ts b/core/indexing/docs/crawl.ts index 1f6fce52d..5fae57ee4 100644 --- a/core/indexing/docs/crawl.ts +++ b/core/indexing/docs/crawl.ts @@ -45,7 +45,7 @@ function shouldFilterPath(pathname: string, baseUrl: URL): boolean { async function* crawlLinks( path: string, baseUrl: URL, - visited: Set + visited: Set, ): AsyncGenerator { if (visited.has(path) || shouldFilterPath(path, baseUrl)) { return; @@ -78,7 +78,7 @@ async function* crawlLinks( children.map(async (child) => { for await (const _ of crawlLinks(child, baseUrl, visited)) { } - }) + }), ); yield visited.size; } @@ -105,12 +105,12 @@ async function crawlGithubRepo(baseUrl: URL) { "X-GitHub-Api-Version": "2022-11-28", }, recursive: "true", - } + }, ); const paths = tree.data.tree .filter( - (file) => file.type === "blob" && file.path?.endsWith(".md") + (file) => file.type === "blob" && file.path?.endsWith(".md"), // || // file.path?.endsWith(".rst") || // file.path?.split("/").includes("documentation") || @@ -125,7 +125,7 @@ async function crawlGithubRepo(baseUrl: URL) { } export async function* crawlSubpages( - baseUrl: URL + baseUrl: URL, ): AsyncGenerator { // Special case for GitHub repos if (baseUrl.hostname === "github.com") { @@ -158,7 +158,7 @@ export async function* crawlSubpages( for await (const count of crawlLinks( realBaseUrl.pathname || "/", realBaseUrl, - visited + visited, )) { yield count; } diff --git a/core/indexing/docs/db.ts b/core/indexing/docs/db.ts index 4250a6610..6179acf40 100644 --- a/core/indexing/docs/db.ts +++ b/core/indexing/docs/db.ts @@ -28,7 +28,7 @@ async function createDocsTable(db: Database) { export async function retrieveDocs( baseUrl: string, vector: number[], - nRetrieve: number + nRetrieve: number, ): Promise { const lancedb = await import("vectordb"); const lance = await lancedb.connect(getLanceDbPath()); @@ -56,7 +56,7 @@ export async function addDocs( title: string, baseUrl: URL, chunks: Chunk[], - embeddings: number[][] + embeddings: number[][], ) { const data: LanceDbDocsRow[] = chunks.map((chunk, i) => ({ title: chunk.otherMetadata?.title || title, @@ -87,7 +87,7 @@ export async function addDocs( await db.run( `INSERT INTO docs (title, baseUrl) VALUES (?, ?)`, title, - baseUrl.toString() + baseUrl.toString(), ); } diff --git a/core/indexing/docs/index.ts b/core/indexing/docs/index.ts index 5c2ade9ac..777245381 100644 --- a/core/indexing/docs/index.ts +++ b/core/indexing/docs/index.ts @@ -13,7 +13,7 @@ import { convertURLToMarkdown } from "./urlToMarkdown"; export async function* indexDocs( title: string, baseUrl: URL, - embeddingsProvider: EmbeddingsProvider + embeddingsProvider: EmbeddingsProvider, ): AsyncGenerator { const existingDocs = await listDocs(); if (existingDocs.find((doc) => doc.baseUrl === baseUrl.toString())) { @@ -50,7 +50,7 @@ export async function* indexDocs( const embeddings: number[][] = []; let markdownForSubpaths = await Promise.all( - subpaths.map((subpath) => convertURLToMarkdown(new URL(subpath, baseUrl))) + subpaths.map((subpath) => convertURLToMarkdown(new URL(subpath, baseUrl))), ); // Filter out undefineds @@ -79,7 +79,7 @@ export async function* indexDocs( } const subpathEmbeddings = await embeddingsProvider.embed( - markdownChunks.map((chunk) => chunk.content) + markdownChunks.map((chunk) => chunk.content), ); markdownChunks.forEach((chunk, index) => { diff --git a/core/indexing/docs/urlToMarkdown.ts b/core/indexing/docs/urlToMarkdown.ts index ec0a678da..b280677ab 100644 --- a/core/indexing/docs/urlToMarkdown.ts +++ b/core/indexing/docs/urlToMarkdown.ts @@ -16,7 +16,7 @@ const nhm = new NodeHtmlMarkdown( }, }, }, - undefined + undefined, ); const STRIP_BEFORE = ["\n# "]; @@ -39,7 +39,7 @@ async function retrieveGitHubBlob(url: URL): Promise { const content = Buffer.from( (response.data as any).content || "", - "base64" + "base64", ).toString(); const fileExtension = url.pathname.split(".").slice(-1)[0]; @@ -51,7 +51,7 @@ async function retrieveGitHubBlob(url: URL): Promise { } export async function convertURLToMarkdown( - url: URL + url: URL, ): Promise { try { if (url.hostname === "github.com") { diff --git a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts index d4375604d..ce1ea2a4f 100644 --- a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts +++ b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts @@ -32,7 +32,7 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { }); const data = await resp.json(); return data.data[0].embedding; - }) + }), ); } } diff --git a/core/indexing/embeddings/TransformersJsEmbeddingsProvider.ts b/core/indexing/embeddings/TransformersJsEmbeddingsProvider.ts index b4918ae3c..7517d43e2 100644 --- a/core/indexing/embeddings/TransformersJsEmbeddingsProvider.ts +++ b/core/indexing/embeddings/TransformersJsEmbeddingsProvider.ts @@ -58,7 +58,7 @@ class TransformersJsEmbeddingsProvider extends BaseEmbeddingsProvider { ) { let chunkGroup = chunks.slice( i, - i + TransformersJsEmbeddingsProvider.MaxGroupSize + i + TransformersJsEmbeddingsProvider.MaxGroupSize, ); let output = await extractor(chunkGroup, { pooling: "mean", diff --git a/core/indexing/embeddings/TransformersJsWorkerThread.js b/core/indexing/embeddings/TransformersJsWorkerThread.js index 4ec59603c..c294e44fe 100644 --- a/core/indexing/embeddings/TransformersJsWorkerThread.js +++ b/core/indexing/embeddings/TransformersJsWorkerThread.js @@ -43,7 +43,7 @@ parentPort.on("message", async (chunks) => { ) { let chunkGroup = chunks.slice( i, - i + TransformersJsEmbeddingsProvider.MaxGroupSize + i + TransformersJsEmbeddingsProvider.MaxGroupSize, ); let output = await extractor(chunkGroup, { pooling: "mean", diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index fe094711e..03597e99e 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -36,7 +36,7 @@ export class CodebaseIndexer { new ChunkCodebaseIndex(this.ide.readFile.bind(this.ide)), // Chunking must come first new LanceDbIndex( config.embeddingsProvider, - this.ide.readFile.bind(this.ide) + this.ide.readFile.bind(this.ide), ), new FullTextSearchCodebaseIndex(), ]; @@ -45,7 +45,7 @@ export class CodebaseIndexer { } async *refresh( - workspaceDirs: string[] + workspaceDirs: string[], ): AsyncGenerator { const config = await this.configHandler.loadConfig(); if (config.disableIndexing) { @@ -57,8 +57,7 @@ export class CodebaseIndexer { let completedDirs = 0; yield { - progress: - 0, + progress: 0, desc: "Starting indexing...", }; @@ -77,13 +76,13 @@ export class CodebaseIndexer { const [results, markComplete] = await getComputeDeleteAddRemove( tag, { ...stats }, - (filepath) => this.ide.readFile(filepath) + (filepath) => this.ide.readFile(filepath), ); for await (let { progress, desc } of codebaseIndex.update( tag, results, - markComplete + markComplete, )) { // Handle pausing in this loop because it's the only one really taking time while (this.pauseToken.paused) { diff --git a/core/indexing/refreshIndex.ts b/core/indexing/refreshIndex.ts index 97bb0d2a3..c908bc7bd 100644 --- a/core/indexing/refreshIndex.ts +++ b/core/indexing/refreshIndex.ts @@ -33,7 +33,7 @@ export class SqliteDb { path STRING NOT NULL, cacheKey STRING NOT NULL, lastUpdated INTEGER NOT NULL - )` + )`, ); await db.exec( @@ -43,7 +43,7 @@ export class SqliteDb { dir STRING NOT NULL, branch STRING NOT NULL, artifactId STRING NOT NULL - )` + )`, ); } @@ -67,7 +67,7 @@ export class SqliteDb { } async function getSavedItemsForTag( - tag: IndexTag + tag: IndexTag, ): Promise<{ path: string; cacheKey: string; lastUpdated: number }[]> { const db = await SqliteDb.get(); const stmt = await db.prepare( @@ -75,7 +75,7 @@ async function getSavedItemsForTag( WHERE dir = ? AND branch = ? AND artifactId = ?`, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); const rows = await stmt.all(); return rows; @@ -96,7 +96,7 @@ enum AddRemoveResultType { async function getAddRemoveForTag( tag: IndexTag, currentFiles: LastModifiedMap, - readFile: (path: string) => Promise + readFile: (path: string) => Promise, ): Promise<[PathAndCacheKey[], PathAndCacheKey[], MarkCompleteCallback]> { const newLastUpdatedTimestamp = Date.now(); @@ -137,8 +137,8 @@ async function getAddRemoveForTag( Object.keys(currentFiles).map(async (path) => { const fileContents = await readFile(path); return { path, cacheKey: calculateHash(fileContents) }; - }) - )) + }), + )), ); // Create the markComplete callback function @@ -159,7 +159,7 @@ async function getAddRemoveForTag( newLastUpdatedTimestamp, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); break; case AddRemoveResultType.Remove: @@ -175,7 +175,7 @@ async function getAddRemoveForTag( path, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); break; case AddRemoveResultType.UpdateNewVersion: @@ -194,7 +194,7 @@ async function getAddRemoveForTag( path, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); break; case AddRemoveResultType.UpdateOldVersion: @@ -235,11 +235,11 @@ async function getAddRemoveForTag( */ async function getTagsFromGlobalCache( cacheKey: string, - artifactId: string + artifactId: string, ): Promise { const db = await SqliteDb.get(); const stmt = await db.prepare( - `SELECT dir, branch, artifactId FROM global_cache WHERE cacheKey = ? AND artifactId = ?` + `SELECT dir, branch, artifactId FROM global_cache WHERE cacheKey = ? AND artifactId = ?`, ); const rows = await stmt.all(cacheKey, artifactId); return rows; @@ -254,12 +254,12 @@ function calculateHash(fileContents: string): string { export async function getComputeDeleteAddRemove( tag: IndexTag, currentFiles: LastModifiedMap, - readFile: (path: string) => Promise + readFile: (path: string) => Promise, ): Promise<[RefreshIndexResults, MarkCompleteCallback]> { const [add, remove, markComplete] = await getAddRemoveForTag( tag, currentFiles, - readFile + readFile, ); const compute: PathAndCacheKey[] = []; @@ -333,7 +333,7 @@ export class GlobalCacheCodeBaseIndex implements CodebaseIndex { async *update( tag: IndexTag, results: RefreshIndexResults, - _: MarkCompleteCallback + _: MarkCompleteCallback, ): AsyncGenerator { const add = [...results.compute, ...results.addTag]; const remove = [...results.del, ...results.removeTag]; @@ -350,26 +350,26 @@ export class GlobalCacheCodeBaseIndex implements CodebaseIndex { private async computeOrAddTag( cacheKey: string, - tag: IndexTag + tag: IndexTag, ): Promise { await this.db.run( "INSERT INTO global_cache (cacheKey, dir, branch, artifactId) VALUES (?, ?, ?, ?)", cacheKey, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); } private async deleteOrRemoveTag( cacheKey: string, - tag: IndexTag + tag: IndexTag, ): Promise { await this.db.run( "DELETE FROM global_cache WHERE cacheKey = ? AND dir = ? AND branch = ? AND artifactId = ?", cacheKey, tag.directory, tag.branch, - tag.artifactId + tag.artifactId, ); } } diff --git a/core/indexing/types.ts b/core/indexing/types.ts index dacc88ee6..e62897238 100644 --- a/core/indexing/types.ts +++ b/core/indexing/types.ts @@ -9,7 +9,7 @@ export enum IndexResultType { export type MarkCompleteCallback = ( items: PathAndCacheKey[], - resultType: IndexResultType + resultType: IndexResultType, ) => void; export interface CodebaseIndex { @@ -17,7 +17,7 @@ export interface CodebaseIndex { update( tag: IndexTag, results: RefreshIndexResults, - markComplete: MarkCompleteCallback + markComplete: MarkCompleteCallback, ): AsyncGenerator; } diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index f68e22b11..656ed9c40 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -81,7 +81,7 @@ const PARALLEL_PROVIDERS: ModelProvider[] = [ function llmCanGenerateInParallel( provider: ModelProvider, - model: string + model: string, ): boolean { if (provider === "openai") { return model.includes("gpt"); @@ -168,7 +168,7 @@ function autodetectTemplateType(model: string): TemplateType | undefined { function autodetectTemplateFunction( model: string, provider: ModelProvider, - explicitTemplate: TemplateType | undefined = undefined + explicitTemplate: TemplateType | undefined = undefined, ) { if ( explicitTemplate === undefined && @@ -205,7 +205,7 @@ function autodetectTemplateFunction( function autodetectPromptTemplates( model: string, - explicitTemplate: TemplateType | undefined = undefined + explicitTemplate: TemplateType | undefined = undefined, ) { const templateType = explicitTemplate || autodetectTemplateType(model); const templates: Record = {}; diff --git a/core/llm/countTokens.ts b/core/llm/countTokens.ts index 292efd09e..285630a04 100644 --- a/core/llm/countTokens.ts +++ b/core/llm/countTokens.ts @@ -37,7 +37,7 @@ function countImageTokens(content: MessagePart): number { function countTokens( content: MessageContent, // defaults to llama2 because the tokenizer tends to produce more tokens - modelName: string = "llama2" + modelName: string = "llama2", ): number { const encoding = encodingForModel(modelName); if (Array.isArray(content)) { @@ -80,7 +80,7 @@ export function stripImages(content: MessageContent): string { function countChatMessageTokens( modelName: string, - chatMessage: ChatMessage + chatMessage: ChatMessage, ): number { // Doing simpler, safer version of what is here: // https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb @@ -92,7 +92,7 @@ function countChatMessageTokens( function pruneLinesFromTop( prompt: string, maxTokens: number, - modelName: string + modelName: string, ): string { let totalTokens = countTokens(prompt, modelName); const lines = prompt.split("\n"); @@ -106,7 +106,7 @@ function pruneLinesFromTop( function pruneLinesFromBottom( prompt: string, maxTokens: number, - modelName: string + modelName: string, ): string { let totalTokens = countTokens(prompt, modelName); const lines = prompt.split("\n"); @@ -120,7 +120,7 @@ function pruneLinesFromBottom( function pruneStringFromBottom( modelName: string, maxTokens: number, - prompt: string + prompt: string, ): string { const encoding = encodingForModel(modelName); @@ -135,7 +135,7 @@ function pruneStringFromBottom( function pruneStringFromTop( modelName: string, maxTokens: number, - prompt: string + prompt: string, ): string { const encoding = encodingForModel(modelName); @@ -151,7 +151,7 @@ function pruneRawPromptFromTop( modelName: string, contextLength: number, prompt: string, - tokensForCompletion: number + tokensForCompletion: number, ): string { const maxTokens = contextLength - tokensForCompletion - TOKEN_BUFFER_FOR_SAFETY; @@ -162,7 +162,7 @@ function pruneRawPromptFromBottom( modelName: string, contextLength: number, prompt: string, - tokensForCompletion: number + tokensForCompletion: number, ): string { const maxTokens = contextLength - tokensForCompletion - TOKEN_BUFFER_FOR_SAFETY; @@ -181,7 +181,7 @@ function pruneChatHistory( modelName: string, chatHistory: ChatMessage[], contextLength: number, - tokensForCompletion: number + tokensForCompletion: number, ): ChatMessage[] { let totalTokens = tokensForCompletion + @@ -195,11 +195,11 @@ function pruneChatHistory( const longerThanOneThird = longestMessages.filter( (message: ChatMessage) => - countTokens(message.content, modelName) > contextLength / 3 + countTokens(message.content, modelName) > contextLength / 3, ); const distanceFromThird = longerThanOneThird.map( (message: ChatMessage) => - countTokens(message.content, modelName) - contextLength / 3 + countTokens(message.content, modelName) - contextLength / 3, ); for (let i = 0; i < longerThanOneThird.length; i++) { @@ -267,7 +267,7 @@ function pruneChatHistory( modelName, contextLength, stripImages(message.content), - tokensForCompletion + tokensForCompletion, ); totalTokens = contextLength; } @@ -283,7 +283,7 @@ function compileChatMessages( supportsImages: boolean, prompt: string | undefined = undefined, functions: any[] | undefined = undefined, - systemMessage: string | undefined = undefined + systemMessage: string | undefined = undefined, ): ChatMessage[] { const msgsCopy = msgs ? msgs.map((msg) => ({ ...msg })) : []; @@ -314,7 +314,7 @@ function compileChatMessages( if (maxTokens + functionTokens + TOKEN_BUFFER_FOR_SAFETY >= contextLength) { throw new Error( - `maxTokens (${maxTokens}) is too close to contextLength (${contextLength}), which doesn't leave room for response. Try increasing the contextLength parameter of the model in your config.json.` + `maxTokens (${maxTokens}) is too close to contextLength (${contextLength}), which doesn't leave room for response. Try increasing the contextLength parameter of the model in your config.json.`, ); } @@ -332,7 +332,7 @@ function compileChatMessages( modelName, msgsCopy, contextLength, - functionTokens + maxTokens + TOKEN_BUFFER_FOR_SAFETY + functionTokens + maxTokens + TOKEN_BUFFER_FOR_SAFETY, ); if ( diff --git a/core/llm/llms/Anthropic.ts b/core/llm/llms/Anthropic.ts index 20deffce3..8e21aea8d 100644 --- a/core/llm/llms/Anthropic.ts +++ b/core/llm/llms/Anthropic.ts @@ -36,7 +36,7 @@ class Anthropic extends BaseLLM { protected async _complete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): Promise { const response = await this.fetch(this.apiBase + "/complete", { method: "POST", @@ -57,7 +57,7 @@ class Anthropic extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const response = await this.fetch(this.apiBase + "/complete", { method: "POST", diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 93de02020..dc17832ab 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -8,7 +8,7 @@ class Bedrock extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const response = await this.fetch( `${this.apiBase}/model/${options.model}/invoke-with-response-stream`, @@ -22,7 +22,7 @@ class Bedrock extends BaseLLM { body: JSON.stringify({ inputText: prompt, }), - } + }, ); for await (const value of streamSse(response)) { diff --git a/core/llm/llms/CustomLLM.ts b/core/llm/llms/CustomLLM.ts index 463f0f0f7..38a5adaa4 100644 --- a/core/llm/llms/CustomLLM.ts +++ b/core/llm/llms/CustomLLM.ts @@ -5,13 +5,13 @@ class CustomLLMClass extends BaseLLM { private customStreamCompletion?: ( prompt: string, options: CompletionOptions, - fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise + fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise, ) => AsyncGenerator; private customStreamChat?: ( messages: ChatMessage[], options: CompletionOptions, - fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise + fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise, ) => AsyncGenerator; constructor(custom: CustomLLM) { @@ -22,13 +22,13 @@ class CustomLLMClass extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { if (this.customStreamChat) { for await (const content of this.customStreamChat( messages, options, - (...args) => this.fetch(...args) + (...args) => this.fetch(...args), )) { yield { role: "assistant", content }; } @@ -41,13 +41,13 @@ class CustomLLMClass extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { if (this.customStreamCompletion) { for await (const content of this.customStreamCompletion( prompt, options, - (...args) => this.fetch(...args) + (...args) => this.fetch(...args), )) { yield content; } @@ -55,13 +55,13 @@ class CustomLLMClass extends BaseLLM { for await (const content of this.customStreamChat( [{ role: "user", content: prompt }], options, - (...args) => this.fetch(...args) + (...args) => this.fetch(...args), )) { yield content; } } else { throw new Error( - "Either streamCompletion or streamChat must be defined in a custom LLM in config.ts" + "Either streamCompletion or streamChat must be defined in a custom LLM in config.ts", ); } } diff --git a/core/llm/llms/Flowise.ts b/core/llm/llms/Flowise.ts index 1d2cc777c..482bcce25 100644 --- a/core/llm/llms/Flowise.ts +++ b/core/llm/llms/Flowise.ts @@ -120,7 +120,7 @@ class Flowise extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const message: ChatMessage = { role: "user", content: prompt }; for await (const chunk of this._streamChat([message], options)) { @@ -130,7 +130,7 @@ class Flowise extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const requestBody = this._getRequestBody(messages, options); const { socket, socketInfo } = await this._initializeSocket(); @@ -156,7 +156,7 @@ class Flowise extends BaseLLM { protected _getRequestBody( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): any { const lastMessage = messages[messages.length - 1]; const history = messages @@ -200,7 +200,7 @@ class Flowise extends BaseLLM { socketInfo.internal.hasNextTokenPromiseResolve = hasNextTokenResolve; socketInfo.internal.hasNextTokenPromiseReject = hasNextTokenReject; - } + }, ); }; const resetTimeout = () => { diff --git a/core/llm/llms/FreeTrial.ts b/core/llm/llms/FreeTrial.ts index 1ef07cca1..463f41cc0 100644 --- a/core/llm/llms/FreeTrial.ts +++ b/core/llm/llms/FreeTrial.ts @@ -29,7 +29,7 @@ class FreeTrial extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const args = this._convertArgs(this.collectArgs(options)); @@ -67,7 +67,7 @@ class FreeTrial extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const args = this._convertArgs(this.collectArgs(options)); diff --git a/core/llm/llms/Gemini.ts b/core/llm/llms/Gemini.ts index 126f94a01..836bdf970 100644 --- a/core/llm/llms/Gemini.ts +++ b/core/llm/llms/Gemini.ts @@ -17,11 +17,11 @@ class Gemini extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { for await (const chunk of this._streamChat( [{ role: "user", content: prompt }], - options + options, )) { yield stripImages(chunk.content); } @@ -29,7 +29,7 @@ class Gemini extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const apiUrl = `https://${this.region}-aiplatform.googleapis.com/v1/projects/${this.projectId}/locations/${this.region}/publishers/google/models/gemini-pro:streamGenerateContent`; const body = { @@ -60,12 +60,13 @@ class Gemini extends BaseLLM { if (data[0]?.error) { throw new Error(data[0].error.message); } - let combinedText = ''; + let combinedText = ""; for (const entry of data || []) { - combinedText += entry?.candidates?.[0]?.content?.parts?.[0]?.text || ''; + combinedText += entry?.candidates?.[0]?.content?.parts?.[0]?.text || ""; } - yield { role: "assistant", content: combinedText.trim() }; } + yield { role: "assistant", content: combinedText.trim() }; + } } export default Gemini; diff --git a/core/llm/llms/GooglePalm.ts b/core/llm/llms/GooglePalm.ts index 8f63a961f..3c62a49ca 100644 --- a/core/llm/llms/GooglePalm.ts +++ b/core/llm/llms/GooglePalm.ts @@ -19,11 +19,11 @@ class GooglePalm extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { for await (const message of this._streamChat( [{ content: prompt, role: "user" }], - options + options, )) { yield stripImages(message.content); } @@ -45,20 +45,20 @@ class GooglePalm extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { let convertedMsgs = this.removeSystemMessage(messages); if (options.model.includes("gemini")) { for await (const message of this.streamChatGemini( convertedMsgs, - options + options, )) { yield message; } } else { for await (const message of this.streamChatBison( convertedMsgs, - options + options, )) { yield message; } @@ -80,7 +80,7 @@ class GooglePalm extends BaseLLM { private async *streamChatGemini( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const apiURL = `${this.apiBase}/v1/models/${options.model}:streamGenerateContent?key=${this.apiKey}`; const body = { @@ -150,7 +150,7 @@ class GooglePalm extends BaseLLM { } private async *streamChatBison( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const msgList = []; for (const message of messages) { diff --git a/core/llm/llms/HuggingFaceInferenceAPI.ts b/core/llm/llms/HuggingFaceInferenceAPI.ts index 1bd6d3a2a..001680523 100644 --- a/core/llm/llms/HuggingFaceInferenceAPI.ts +++ b/core/llm/llms/HuggingFaceInferenceAPI.ts @@ -16,11 +16,11 @@ class HuggingFaceInferenceAPI extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { if (!this.apiBase) { throw new Error( - "No API base URL provided. Please add the `apiBase` field in your config.json." + "No API base URL provided. Please add the `apiBase` field in your config.json.", ); } diff --git a/core/llm/llms/HuggingFaceTGI.ts b/core/llm/llms/HuggingFaceTGI.ts index 2941589f8..a4893b8eb 100644 --- a/core/llm/llms/HuggingFaceTGI.ts +++ b/core/llm/llms/HuggingFaceTGI.ts @@ -17,7 +17,7 @@ class HuggingFaceTGI extends BaseLLM { if (response.status !== 200) { console.warn( "Error calling Hugging Face TGI /info endpoint: ", - await response.text() + await response.text(), ); return; } @@ -44,7 +44,7 @@ class HuggingFaceTGI extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const args = this._convertArgs(options, prompt); diff --git a/core/llm/llms/LlamaCpp.ts b/core/llm/llms/LlamaCpp.ts index ddb0c00a6..eb947af11 100644 --- a/core/llm/llms/LlamaCpp.ts +++ b/core/llm/llms/LlamaCpp.ts @@ -22,7 +22,7 @@ class LlamaCpp extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const headers = { "Content-Type": "application/json", diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index 60ec16432..1f273560d 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -30,7 +30,7 @@ class Ollama extends BaseLLM { if (response.status !== 200) { console.warn( "Error calling Ollama /api/show endpoint: ", - await response.text() + await response.text(), ); return; } @@ -110,7 +110,7 @@ class Ollama extends BaseLLM { private _convertArgs( options: CompletionOptions, - prompt: string | ChatMessage[] + prompt: string | ChatMessage[], ) { const finalOptions: any = { model: this._getModel(), @@ -139,7 +139,7 @@ class Ollama extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const response = await this.fetch(`${this.apiBase}/api/generate`, { method: "POST", @@ -178,7 +178,7 @@ class Ollama extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const response = await this.fetch(`${this.apiBase}/api/chat`, { method: "POST", diff --git a/core/llm/llms/OpenAIFreeTrial.ts b/core/llm/llms/OpenAIFreeTrial.ts index 095e4e781..f2e936d24 100644 --- a/core/llm/llms/OpenAIFreeTrial.ts +++ b/core/llm/llms/OpenAIFreeTrial.ts @@ -17,7 +17,7 @@ class OpenAIFreeTrial extends BaseLLM { protected async _complete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): Promise { const args = this.collectArgs(options); @@ -35,7 +35,7 @@ class OpenAIFreeTrial extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const args = this.collectArgs(options); @@ -55,7 +55,7 @@ class OpenAIFreeTrial extends BaseLLM { protected async *_streamChat( messages: ChatMessage[], - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const args = this.collectArgs(options); diff --git a/core/llm/llms/Replicate.ts b/core/llm/llms/Replicate.ts index 2efb6e8ae..daca82a83 100644 --- a/core/llm/llms/Replicate.ts +++ b/core/llm/llms/Replicate.ts @@ -34,7 +34,7 @@ class Replicate extends BaseLLM { private _convertArgs( options: CompletionOptions, - prompt: string + prompt: string, ): [`${string}/${string}:${string}`, { input: any }] { return [ Replicate.MODEL_IDS[options.model] || (options.model as any), @@ -51,7 +51,7 @@ class Replicate extends BaseLLM { protected async _complete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): Promise { const [model, args] = this._convertArgs(options, prompt); const response = await this._replicate.run(model, args); @@ -61,7 +61,7 @@ class Replicate extends BaseLLM { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { const [model, args] = this._convertArgs(options, prompt); for await (const event of this._replicate.stream(model, args)) { diff --git a/core/llm/llms/Together.ts b/core/llm/llms/Together.ts index a498e621a..1b2aa29bd 100644 --- a/core/llm/llms/Together.ts +++ b/core/llm/llms/Together.ts @@ -39,7 +39,7 @@ class Together extends OpenAI { protected async *_streamComplete( prompt: string, - options: CompletionOptions + options: CompletionOptions, ): AsyncGenerator { for await (const chunk of this._legacystreamComplete(prompt, options)) { yield chunk; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 9da9ec2c0..2f5643129 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -38,7 +38,7 @@ function convertToLetter(num: number): string { } const getHandlebarsVars = ( - value: string + value: string, ): [string, { [key: string]: string }] => { const ast = Handlebars.parse(value); @@ -50,7 +50,7 @@ const getHandlebarsVars = ( keysToFilepath[letter] = (ast.body[i] as any).path.original; value = value.replace( new RegExp("{{\\s*" + (ast.body[i] as any).path.original + "\\s*}}"), - `{{${letter}}}` + `{{${letter}}}`, ); keyIndex++; } @@ -60,7 +60,7 @@ const getHandlebarsVars = ( async function renderTemplatedString( template: string, - readFile: (filepath: string) => Promise + readFile: (filepath: string) => Promise, ): Promise { const [newTemplate, vars] = getHandlebarsVars(template); template = newTemplate; @@ -100,7 +100,7 @@ export async function llmFromDescription( desc: ModelDescription, readFile: (filepath: string) => Promise, completionOptions?: BaseCompletionOptions, - systemMessage?: string + systemMessage?: string, ): Promise { const cls = LLMs.find((llm) => llm.providerName === desc.provider); @@ -136,7 +136,7 @@ export async function llmFromDescription( export function llmFromProviderAndOptions( providerName: string, - llmOptions: LLMOptions + llmOptions: LLMOptions, ): ILLM { const cls = LLMs.find((llm) => llm.providerName === providerName); diff --git a/core/llm/stream.ts b/core/llm/stream.ts index 01908c24e..302ee82ed 100644 --- a/core/llm/stream.ts +++ b/core/llm/stream.ts @@ -1,5 +1,5 @@ export async function* streamResponse( - response: Response + response: Response, ): AsyncGenerator { if (response.status !== 200) { throw new Error(await response.text()); diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index edc883cec..3f54e21b9 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -36,7 +36,7 @@ class FileSystemIde implements IDE { showLines( filepath: string, startLine: number, - endLine: number + endLine: number, ): Promise { return Promise.resolve(); } @@ -101,7 +101,7 @@ class FileSystemIde implements IDE { showDiff( filepath: string, newContents: string, - stepIndex: number + stepIndex: number, ): Promise { return Promise.resolve(); } diff --git a/core/util/history.ts b/core/util/history.ts index bab04c4f8..a7b4167e4 100644 --- a/core/util/history.ts +++ b/core/util/history.ts @@ -32,12 +32,12 @@ class HistoryManager { sessionsList = JSON.parse(sessionsListRaw); } catch (error) { throw new Error( - `It looks like there is a JSON formatting error in your sessions.json file (${sessionsListFile}). Please fix this before creating a new session.` + `It looks like there is a JSON formatting error in your sessions.json file (${sessionsListFile}). Please fix this before creating a new session.`, ); } sessionsList = sessionsList.filter( - (session) => session.sessionId !== sessionId + (session) => session.sessionId !== sessionId, ); fs.writeFileSync(sessionsListFile, JSON.stringify(sessionsList)); @@ -50,7 +50,7 @@ class HistoryManager { throw new Error(`Session file ${sessionFile} does not exist`); } const session: PersistedSessionInfo = JSON.parse( - fs.readFileSync(sessionFile, "utf8") + fs.readFileSync(sessionFile, "utf8"), ); session.sessionId = sessionId; return session; @@ -69,7 +69,7 @@ class HistoryManager { // Save the main session json file fs.writeFileSync( getSessionFilePath(session.sessionId), - JSON.stringify(session) + JSON.stringify(session), ); // Read and update the sessions list @@ -114,11 +114,11 @@ class HistoryManager { } catch (error) { if (error instanceof SyntaxError) { throw new Error( - `It looks like there is a JSON formatting error in your sessions.json file (${sessionsListFilePath}). Please fix this before creating a new session.` + `It looks like there is a JSON formatting error in your sessions.json file (${sessionsListFilePath}). Please fix this before creating a new session.`, ); } else { throw new Error( - `It looks like there is a validation error in your sessions.json file (${sessionsListFilePath}). Please fix this before creating a new session. Error: ${error}` + `It looks like there is a validation error in your sessions.json file (${sessionsListFilePath}). Please fix this before creating a new session. Error: ${error}`, ); } } diff --git a/core/util/index.ts b/core/util/index.ts index 80ef2e5c8..777d629e5 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -96,13 +96,13 @@ type PromptTemplate = | string | (( history: ChatMessage[], - otherData: Record + otherData: Record, ) => string | ChatMessage[]); export function renderPromptTemplate( template: PromptTemplate, history: ChatMessage[], - otherData: Record + otherData: Record, ): string | ChatMessage[] { if (typeof template === "string") { let data: any = { diff --git a/core/util/messageIde.ts b/core/util/messageIde.ts index 8534394c6..14e4c2e1d 100644 --- a/core/util/messageIde.ts +++ b/core/util/messageIde.ts @@ -2,7 +2,7 @@ import { ContinueRcJson, IDE, IdeInfo, Problem, Range } from ".."; export class MessageIde implements IDE { constructor( - private readonly request: (messageType: string, data: any) => Promise + private readonly request: (messageType: string, data: any) => Promise, ) {} getIdeInfo(): Promise { return this.request("getIdeInfo", undefined); @@ -45,7 +45,7 @@ export class MessageIde implements IDE { async showLines( filepath: string, startLine: number, - endLine: number + endLine: number, ): Promise { return await this.request("showLines", { filepath, startLine, endLine }); } @@ -90,7 +90,7 @@ export class MessageIde implements IDE { async showDiff( filepath: string, newContents: string, - stepIndex: number + stepIndex: number, ): Promise { await this.request("showDiff", { filepath, newContents, stepIndex }); } diff --git a/core/util/paths.ts b/core/util/paths.ts index 8fe150d9c..9f19099e7 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -62,7 +62,7 @@ export function getConfigTsPath(): string { p, `export function modifyConfig(config: Config): Config { return config; -}` +}`, ); } @@ -83,7 +83,7 @@ export function getConfigTsPath(): string { version: "1.0.0", description: "My Continue Configuration", main: "config.js", - }) + }), ); } @@ -123,8 +123,8 @@ export function getTsConfigPath(): string { include: ["./config.ts"], }, null, - 2 - ) + 2, + ), ); } return tsConfigPath; @@ -143,7 +143,7 @@ export function getDevDataFilePath(fileName: string): string { } export function editConfigJson( - callback: (config: SerializedContinueConfig) => SerializedContinueConfig + callback: (config: SerializedContinueConfig) => SerializedContinueConfig, ) { const config = fs.readFileSync(getConfigJsonPath(), "utf8"); let configJson = JSON.parse(config); @@ -196,7 +196,7 @@ export function getRemoteConfigsFolderPath(): string { export function getPathToRemoteConfig(remoteConfigServerUrl: URL): string { const dir = path.join( getRemoteConfigsFolderPath(), - remoteConfigServerUrl.hostname + remoteConfigServerUrl.hostname, ); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); diff --git a/core/util/posthog.ts b/core/util/posthog.ts index 887fa2390..4f83fdee5 100644 --- a/core/util/posthog.ts +++ b/core/util/posthog.ts @@ -26,7 +26,7 @@ export class Telemetry { "phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", { host: "https://app.posthog.com", - } + }, ); } } catch (e) { diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index 8411eb715..3e82e0811 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -1,5 +1,5 @@ import * as path from "path"; -const Parser = require("web-tree-sitter") +const Parser = require("web-tree-sitter"); export const supportedLanguages: { [key: string]: string } = { cpp: "cpp", @@ -72,21 +72,21 @@ export async function getParserForFile(filepath: string) { await Parser.init(); const parser = new Parser(); const extension = path.extname(filepath).slice(1); - + if (!supportedLanguages[extension]) { console.warn( "Unable to load language for file", extension, "from path: ", - filepath + filepath, ); return undefined; } - + const wasmPath = path.join( __dirname, "tree-sitter-wasms", - `tree-sitter-${supportedLanguages[extension]}.wasm` + `tree-sitter-${supportedLanguages[extension]}.wasm`, ); const language = await Parser.Language.load(wasmPath); parser.setLanguage(language); @@ -95,4 +95,4 @@ export async function getParserForFile(filepath: string) { console.error("Unable to load language for file", filepath, e); return undefined; } -} \ No newline at end of file +} diff --git a/core/util/verticalEdit.ts b/core/util/verticalEdit.ts index 81b55628b..97bcbd9f4 100644 --- a/core/util/verticalEdit.ts +++ b/core/util/verticalEdit.ts @@ -16,7 +16,7 @@ function constructPrompt( codeToEdit: string, llm: ILLM, userInput: string, - language: string | undefined + language: string | undefined, ): string { const template = llm.promptTemplates?.edit ?? gptEditPrompt; const rendered = renderPromptTemplate(template, [], { @@ -31,7 +31,7 @@ function constructPrompt( async function* addIndentation( diffLineGenerator: AsyncGenerator, - indentation: string + indentation: string, ): AsyncGenerator { for await (const diffLine of diffLineGenerator) { yield { @@ -49,7 +49,7 @@ export async function* streamDiffLines( oldCode: string, llm: ILLM, input: string, - language: string | undefined + language: string | undefined, ): AsyncGenerator { // Strip common indentation for the LLM, then add back after generation const [withoutIndentation, commonIndentation] = diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index 2e62fea3e..3de6b77be 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -12,7 +12,7 @@ import { setupInlineTips } from "./inlineTips"; export async function showTutorial() { const tutorialPath = path.join( getExtensionUri().fsPath, - "continue_tutorial.py" + "continue_tutorial.py", ); // Ensure keyboard shortcuts match OS if (process.platform !== "darwin") { @@ -22,7 +22,7 @@ export async function showTutorial() { } const doc = await vscode.workspace.openTextDocument( - vscode.Uri.file(tutorialPath) + vscode.Uri.file(tutorialPath), ); await vscode.window.showTextDocument(doc); } @@ -35,7 +35,7 @@ async function openTutorialFirstTime(context: vscode.ExtensionContext) { } function showRefactorMigrationMessage( - extensionContext: vscode.ExtensionContext + extensionContext: vscode.ExtensionContext, ) { // Only if the vscode setting continue.manuallyRunningSserver is true const manuallyRunningServer = @@ -45,21 +45,21 @@ function showRefactorMigrationMessage( if ( manuallyRunningServer && extensionContext?.globalState.get( - "continue.showRefactorMigrationMessage" + "continue.showRefactorMigrationMessage", ) !== false ) { vscode.window .showInformationMessage( "The Continue server protocol was recently updated in a way that requires the latest server version to work properly. Since you are manually running the server, please be sure to upgrade with `pip install --upgrade continuedev`.", "Got it", - "Don't show again" + "Don't show again", ) .then((selection) => { if (selection === "Don't show again") { // Get the global state extensionContext?.globalState.update( "continue.showRefactorMigrationMessage", - false + false, ); } }); @@ -82,8 +82,8 @@ export async function activateExtension(context: vscode.ExtensionContext) { vscode.commands.executeCommand( "markdown.showPreview", vscode.Uri.file( - path.join(getExtensionUri().fsPath, "media", "welcome.md") - ) + path.join(getExtensionUri().fsPath, "media", "welcome.md"), + ), ); }); diff --git a/extensions/vscode/src/activation/inlineTips.ts b/extensions/vscode/src/activation/inlineTips.ts index 001fb6c1a..774c35b48 100644 --- a/extensions/vscode/src/activation/inlineTips.ts +++ b/extensions/vscode/src/activation/inlineTips.ts @@ -31,7 +31,7 @@ function handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent) { const line = Math.max(0, selection.start.line - 1); const hoverMarkdown = new vscode.MarkdownString( - `Use ${getMetaKeyLabel()} L to select code, or ${getMetaKeyLabel()} I to edit highlighted code. Click [here](command:continue.hideInlineTip) if you don't want to see these inline suggestions.` + `Use ${getMetaKeyLabel()} L to select code, or ${getMetaKeyLabel()} I to edit highlighted code. Click [here](command:continue.hideInlineTip) if you don't want to see these inline suggestions.`, ); hoverMarkdown.isTrusted = true; hoverMarkdown.supportHtml = true; @@ -39,7 +39,7 @@ function handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent) { { range: new vscode.Range( new vscode.Position(line, Number.MAX_VALUE), - new vscode.Position(line, Number.MAX_VALUE) + new vscode.Position(line, Number.MAX_VALUE), ), hoverMessage: [hoverMarkdown], }, @@ -54,7 +54,7 @@ const emptyFileTooltipDecoration = vscode.window.createTextEditorDecorationType( margin: "2em 0 0 0", fontStyle: "italic", }, - } + }, ); let selectionChangeDebounceTimer: NodeJS.Timeout | undefined; @@ -68,7 +68,7 @@ export function setupInlineTips(context: vscode.ExtensionContext) { selectionChangeDebounceTimer = setTimeout(() => { handleSelectionChange(e); }, 200); - }) + }), ); context.subscriptions.push( @@ -85,12 +85,12 @@ export function setupInlineTips(context: vscode.ExtensionContext) { { range: new vscode.Range( new vscode.Position(0, Number.MAX_VALUE), - new vscode.Position(0, Number.MAX_VALUE) + new vscode.Position(0, Number.MAX_VALUE), ), }, ]); } - }) + }), ); context.subscriptions.push( @@ -104,7 +104,7 @@ export function setupInlineTips(context: vscode.ExtensionContext) { { range: new vscode.Range( new vscode.Position(0, Number.MAX_VALUE), - new vscode.Position(0, Number.MAX_VALUE) + new vscode.Position(0, Number.MAX_VALUE), ), }, ]); @@ -114,6 +114,6 @@ export function setupInlineTips(context: vscode.ExtensionContext) { editor.setDecorations(emptyFileTooltipDecoration, []); }); } - }) + }), ); } diff --git a/extensions/vscode/src/activation/languageClient.ts b/extensions/vscode/src/activation/languageClient.ts index 5b0bd612c..9e7e4ffa8 100644 --- a/extensions/vscode/src/activation/languageClient.ts +++ b/extensions/vscode/src/activation/languageClient.ts @@ -3,16 +3,15 @@ */ import * as path from "path"; -import { workspace, ExtensionContext, extensions } from "vscode"; +import { ExtensionContext, extensions, workspace } from "vscode"; import { - DefinitionParams, LanguageClient, LanguageClientOptions, ServerOptions, + State, StateChangeEvent, TransportKind, - State, } from "vscode-languageclient/node"; import { getExtensionUri } from "../util/vscode"; @@ -54,7 +53,7 @@ function startPythonLanguageServer(context: ExtensionContext): LanguageClient { let extensionPath = getExtensionUri().fsPath; const command = `cd ${path.join( extensionPath, - "scripts" + "scripts", )} && source env/bin/activate.fish && python -m pyls`; const serverOptions: ServerOptions = { command: command, @@ -109,7 +108,7 @@ async function startPylance(context: ExtensionContext) { "languageServerExample", "Language Server Example", serverOptions, - clientOptions + clientOptions, ); return client; } diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index afd2a2dc7..654c40ec8 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -20,13 +20,17 @@ export class ContinueCompletionProvider public static errorsShown: Set = new Set(); - constructor(private readonly configHandler: ConfigHandler, private readonly ide: IDE, private readonly tabAutocompleteModel: TabAutocompleteModel) {} + constructor( + private readonly configHandler: ConfigHandler, + private readonly ide: IDE, + private readonly tabAutocompleteModel: TabAutocompleteModel, + ) {} public async provideInlineCompletionItems( document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext, - token: vscode.CancellationToken + token: vscode.CancellationToken, //@ts-ignore ): ProviderResult { // Debounce @@ -44,7 +48,7 @@ export class ContinueCompletionProvider const lastUUID = await new Promise((resolve) => setTimeout(() => { resolve(ContinueCompletionProvider.lastUUID); - }, options.debounceDelay) + }, options.debounceDelay), ); if (uuid !== lastUUID) { return []; @@ -71,7 +75,7 @@ export class ContinueCompletionProvider token, options, this.tabAutocompleteModel, - this.ide + this.ide, ); const completion = outcome?.completion; @@ -84,7 +88,7 @@ export class ContinueCompletionProvider if (!outcome.cacheHit) { (await ContinueCompletionProvider.autocompleteCache).put( outcome.prompt, - completion + completion, ); } }, 100); @@ -103,7 +107,7 @@ export class ContinueCompletionProvider title: "Log Autocomplete Outcome", command: "continue.logAutocompleteOutcome", arguments: [outcome, logRejectionTimeout], - } + }, ), ]; } catch (e: any) { diff --git a/extensions/vscode/src/autocomplete/getTabCompletion.ts b/extensions/vscode/src/autocomplete/getTabCompletion.ts index 29200b767..0a2a894b9 100644 --- a/extensions/vscode/src/autocomplete/getTabCompletion.ts +++ b/extensions/vscode/src/autocomplete/getTabCompletion.ts @@ -44,7 +44,7 @@ export async function getTabCompletion( token: vscode.CancellationToken, options: TabAutocompleteOptions, tabAutocompleteModel: TabAutocompleteModel, - ide: IDE + ide: IDE, ): Promise { const startTime = Date.now(); @@ -59,7 +59,7 @@ export async function getTabCompletion( try { // Model - const llm = await tabAutocompleteModel.get() + const llm = await tabAutocompleteModel.get(); if (llm instanceof OpenAI) { llm.useLegacyCompletionsEndpoint = true; } @@ -67,31 +67,36 @@ export async function getTabCompletion( // Prompt const fullPrefix = document.getText( - new vscode.Range(new vscode.Position(0, 0), pos) + new vscode.Range(new vscode.Position(0, 0), pos), ); const fullSuffix = document.getText( new vscode.Range( pos, - new vscode.Position(document.lineCount, Number.MAX_SAFE_INTEGER) - ) + new vscode.Position(document.lineCount, Number.MAX_SAFE_INTEGER), + ), ); const lineBelowCursor = document.lineAt( - Math.min(pos.line + 1, document.lineCount - 1) + Math.min(pos.line + 1, document.lineCount - 1), ).text; const clipboardText = await vscode.env.clipboard.readText(); let extrasSnippets = (await Promise.race([ - getDefinitionsFromLsp(document.uri.fsPath, fullPrefix + fullSuffix, fullPrefix.length, ide), + getDefinitionsFromLsp( + document.uri.fsPath, + fullPrefix + fullSuffix, + fullPrefix.length, + ide, + ), new Promise((resolve) => { setTimeout(() => resolve([]), 100); - }) - ])) as AutocompleteSnippet[] + }), + ])) as AutocompleteSnippet[]; const workspaceDirs = await ide.getWorkspaceDirs(); if (options.onlyMyCode) { extrasSnippets = extrasSnippets.filter((snippet) => { return workspaceDirs.some((dir) => snippet.filepath.startsWith(dir)); - }) + }); } const { prefix, suffix, completeMultiline } = @@ -106,7 +111,7 @@ export async function getTabCompletion( await recentlyEditedTracker.getRecentlyEditedRanges(), await recentlyEditedTracker.getRecentlyEditedDocuments(), llm.model, - extrasSnippets + extrasSnippets, ); const { template, completionOptions } = options.template @@ -120,7 +125,9 @@ export async function getTabCompletion( let completion = ""; const cache = await autocompleteCache; - const cachedCompletion = options.useCache ? await cache.get(prompt) : undefined; + const cachedCompletion = options.useCache + ? await cache.get(prompt) + : undefined; let cacheHit = false; if (cachedCompletion) { // Cache @@ -148,7 +155,7 @@ export async function getTabCompletion( temperature: 0, raw: true, stop, - }) + }), ); // LLM @@ -165,9 +172,11 @@ export async function getTabCompletion( }; const gen2 = onlyWhitespaceAfterEndOfLine( generatorWithCancellation(), - lang.endOfLine + lang.endOfLine, + ); + const lineGenerator = streamWithNewLines( + avoidPathLine(stopAtLines(streamLines(gen2)), lang.comment), ); - const lineGenerator = streamWithNewLines(avoidPathLine(stopAtLines(streamLines(gen2)), lang.comment)); const finalGenerator = stopAtSimilarLine(lineGenerator, lineBelowCursor); for await (const update of finalGenerator) { completion += update; @@ -204,8 +213,8 @@ export async function getTabCompletion( if (val === "Documentation") { vscode.env.openExternal( vscode.Uri.parse( - "https://continue.dev/docs/walkthroughs/tab-autocomplete" - ) + "https://continue.dev/docs/walkthroughs/tab-autocomplete", + ), ); } }); diff --git a/extensions/vscode/src/autocomplete/statusBar.ts b/extensions/vscode/src/autocomplete/statusBar.ts index d9015a833..28bf2b9b7 100644 --- a/extensions/vscode/src/autocomplete/statusBar.ts +++ b/extensions/vscode/src/autocomplete/statusBar.ts @@ -17,7 +17,7 @@ export function stopStatusBarLoading() { export function setupStatusBar( enabled: boolean | undefined, - loading?: boolean + loading?: boolean, ) { if (loading !== false) { clearTimeout(statusBarFalseTimeout); @@ -25,7 +25,7 @@ export function setupStatusBar( } const statusBarItem = vscode.window.createStatusBarItem( - vscode.StatusBarAlignment.Right + vscode.StatusBarAlignment.Right, ); statusBarItem.text = loading ? "$(loading~spin) Continue" diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index c6d083281..c835917f0 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -15,7 +15,7 @@ export class ContinueGUIWebviewViewProvider resolveWebviewView( webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, - _token: vscode.CancellationToken + _token: vscode.CancellationToken, ): void | Thenable { this._webview = webviewView.webview; webviewView.webview.html = this.getSidebarContent( @@ -23,7 +23,7 @@ export class ContinueGUIWebviewViewProvider webviewView, this.ide, this.configHandler, - this.verticalDiffManager + this.verticalDiffManager, ); } @@ -45,12 +45,12 @@ export class ContinueGUIWebviewViewProvider private readonly ide: IDE, private readonly windowId: string, private readonly extensionContext: vscode.ExtensionContext, - private readonly verticalDiffManager: VerticalPerLineDiffManager + private readonly verticalDiffManager: VerticalPerLineDiffManager, ) { this.webviewProtocol = new VsCodeWebviewProtocol( ide, configHandler, - verticalDiffManager + verticalDiffManager, ); } @@ -62,7 +62,7 @@ export class ContinueGUIWebviewViewProvider verticalDiffManager: VerticalPerLineDiffManager, page: string | undefined = undefined, edits: FileEdit[] | undefined = undefined, - isFullScreen: boolean = false + isFullScreen: boolean = false, ): string { let extensionUri = getExtensionUri(); let scriptUri: string; @@ -148,8 +148,8 @@ export class ContinueGUIWebviewViewProvider diff --git a/extensions/vscode/src/decorations.ts b/extensions/vscode/src/decorations.ts index b7e2966c9..746d4b599 100644 --- a/extensions/vscode/src/decorations.ts +++ b/extensions/vscode/src/decorations.ts @@ -1,11 +1,11 @@ -import * as vscode from "vscode"; import * as path from "path"; +import * as vscode from "vscode"; import { uriFromFilePath } from "./util/vscode"; export function showAnswerInTextEditor( filename: string, range: vscode.Range, - answer: string + answer: string, ) { vscode.workspace.openTextDocument(uriFromFilePath(filename)).then((doc) => { const editor = vscode.window.activeTextEditor; @@ -17,7 +17,7 @@ export function showAnswerInTextEditor( vscode.window.showTextDocument(doc).then((new_editor) => { new_editor.revealRange( new vscode.Range(range.end, range.end), - vscode.TextEditorRevealType.InCenter + vscode.TextEditorRevealType.InCenter, ); let decorationType = vscode.window.createTextEditorDecorationType({ @@ -67,7 +67,7 @@ class DecorationManager { private rerenderDecorations( editorUri: string, - decorationType: vscode.TextEditorDecorationType + decorationType: vscode.TextEditorDecorationType, ) { const editor = vscode.window.activeTextEditor; if (!editor) { @@ -144,7 +144,7 @@ export const decorationManager = new DecorationManager(); function constructBaseKey( editor: vscode.TextEditor, lineno: number, - decorationType?: vscode.TextEditorDecorationType + decorationType?: vscode.TextEditorDecorationType, ): DecorationKey { return { editorUri: editor.document.uri.toString(), @@ -159,14 +159,14 @@ function constructBaseKey( const gutterSpinnerDecorationType = vscode.window.createTextEditorDecorationType({ gutterIconPath: vscode.Uri.file( - path.join(__dirname, "..", "media", "spinner.gif") + path.join(__dirname, "..", "media", "spinner.gif"), ), gutterIconSize: "contain", }); export function showGutterSpinner( editor: vscode.TextEditor, - lineno: number + lineno: number, ): DecorationKey { const key = constructBaseKey(editor, lineno, gutterSpinnerDecorationType); decorationManager.addDecoration(key); @@ -177,7 +177,7 @@ export function showGutterSpinner( export function showLintMessage( editor: vscode.TextEditor, lineno: number, - msg: string + msg: string, ): DecorationKey { const key = constructBaseKey(editor, lineno); key.decorationType = vscode.window.createTextEditorDecorationType({ @@ -186,7 +186,7 @@ export function showLintMessage( color: "rgb(255, 0, 0, 0.6)", }, gutterIconPath: vscode.Uri.file( - path.join(__dirname, "..", "media", "error.png") + path.join(__dirname, "..", "media", "error.png"), ), gutterIconSize: "contain", }); @@ -198,7 +198,7 @@ export function showLintMessage( export function highlightCode( editor: vscode.TextEditor, range: vscode.Range, - removeOnClick: boolean = true + removeOnClick: boolean = true, ): DecorationKey { const decorationType = vscode.window.createTextEditorDecorationType({ backgroundColor: "rgb(255, 255, 0, 0.1)", diff --git a/extensions/vscode/src/diff/horizontal.ts b/extensions/vscode/src/diff/horizontal.ts index b71abf9ba..dbf251f5a 100644 --- a/extensions/vscode/src/diff/horizontal.ts +++ b/extensions/vscode/src/diff/horizontal.ts @@ -78,7 +78,7 @@ export class DiffManager { vscode.workspace.fs.createDirectory(uriFromFilePath(this.remoteTmpDir)); return path.join( this.remoteTmpDir, - this.escapeFilepath(originalFilepath) + this.escapeFilepath(originalFilepath), ); } return path.join(DIFF_DIRECTORY, this.escapeFilepath(originalFilepath)); @@ -86,7 +86,7 @@ export class DiffManager { private async openDiffEditor( originalFilepath: string, - newFilepath: string + newFilepath: string, ): Promise { // If the file doesn't yet exist or the basename is a single digit number (vscode terminal), don't open the diff editor try { @@ -116,21 +116,21 @@ export class DiffManager { if ( this.extensionContext.globalState.get( - "continue.showDiffInfoMessage" + "continue.showDiffInfoMessage", ) !== false ) { vscode.window .showInformationMessage( `Accept (${getMetaKeyLabel()}⇧↩) or reject (${getMetaKeyLabel()}⇧⌫) at the top of the file.`, "Got it", - "Don't show again" + "Don't show again", ) .then((selection) => { if (selection === "Don't show again") { // Get the global state this.extensionContext.globalState.update( "continue.showDiffInfoMessage", - false + false, ); } }); @@ -153,7 +153,7 @@ export class DiffManager { async writeDiff( originalFilepath: string, newContent: string, - step_index: number + step_index: number, ): Promise { await this.setupDirectory(); @@ -181,7 +181,7 @@ export class DiffManager { if (diffInfo && !diffInfo?.editor) { diffInfo.editor = await this.openDiffEditor( originalFilepath, - newFilepath + newFilepath, ); this.diffs.set(newFilepath, diffInfo); } @@ -192,7 +192,7 @@ export class DiffManager { // Flashes too much on mac with it vscode.commands.executeCommand( "workbench.action.files.revert", - uriFromFilePath(newFilepath) + uriFromFilePath(newFilepath), ); } @@ -218,7 +218,7 @@ export class DiffManager { return activeEditorPath; } const visibleEditors = vscode.window.visibleTextEditors.map( - (editor) => editor.document.uri.fsPath + (editor) => editor.document.uri.fsPath, ); for (const editorPath of visibleEditors) { if (path.dirname(editorPath) === DIFF_DIRECTORY) { @@ -262,7 +262,7 @@ export class DiffManager { .then(async () => { await writeFile( uriFromFilePath(diffInfo.originalFilepath), - await readFile(diffInfo.newFilepath) + await readFile(diffInfo.newFilepath), ); this.cleanUpDiff(diffInfo); }); @@ -278,7 +278,7 @@ export class DiffManager { if (!newFilepath) { console.log( "No newFilepath provided to reject the diff, diffs.size was", - this.diffs.size + this.diffs.size, ); return; } @@ -328,6 +328,6 @@ async function recordAcceptReject(accepted: boolean, diffInfo: DiffInfo) { // Write the updated suggestions back to the file await writeFile( vscode.Uri.file(suggestionsPath), - JSON.stringify(suggestions, null, 4) + JSON.stringify(suggestions, null, 4), ); } diff --git a/extensions/vscode/src/diff/oldVerticalPerLine.ts b/extensions/vscode/src/diff/oldVerticalPerLine.ts index c4fbcd52b..661f9dfaa 100644 --- a/extensions/vscode/src/diff/oldVerticalPerLine.ts +++ b/extensions/vscode/src/diff/oldVerticalPerLine.ts @@ -30,7 +30,7 @@ type VerticalPerLineDiffEvent = async function* streamVerticalPerLineDiff( lineGenerator: AsyncGenerator, - oldCode: string + oldCode: string, ): AsyncGenerator { const remainingLines = oldCode.split("\n"); let index = 0; // Index in terms of oldCode diff --git a/extensions/vscode/src/diff/verticalPerCharacter.ts b/extensions/vscode/src/diff/verticalPerCharacter.ts index a7f2d962b..2dd7730ee 100644 --- a/extensions/vscode/src/diff/verticalPerCharacter.ts +++ b/extensions/vscode/src/diff/verticalPerCharacter.ts @@ -18,7 +18,7 @@ type DiffEvent = LineUpdate | DiffBlock; * Returns a stream of characters, but with "undefined" inserted into the stream whenever there is a new line */ async function* streamWithLineBreaks( - completionStream: AsyncGenerator + completionStream: AsyncGenerator, ): AsyncGenerator { for await (const chunk of completionStream) { if (chunk.includes("\n")) { @@ -37,7 +37,7 @@ async function* streamWithLineBreaks( async function* streamDiffEvents( completionStream: AsyncGenerator, - oldCode: string + oldCode: string, ): AsyncGenerator { let remainingLines = oldCode.split("\n"); let i = 0; diff --git a/extensions/vscode/src/diff/verticalPerLine/decorations.ts b/extensions/vscode/src/diff/verticalPerLine/decorations.ts index ec2e507d9..96cc4372e 100644 --- a/extensions/vscode/src/diff/verticalPerLine/decorations.ts +++ b/extensions/vscode/src/diff/verticalPerLine/decorations.ts @@ -12,7 +12,7 @@ export const greenDecorationType = vscode.window.createTextEditorDecorationType( isWholeLine: true, backgroundColor: "rgba(0, 255, 0, 0.2)", rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, - } + }, ); export const indexDecorationType = vscode.window.createTextEditorDecorationType( @@ -20,7 +20,7 @@ export const indexDecorationType = vscode.window.createTextEditorDecorationType( isWholeLine: true, backgroundColor: "rgba(255, 255, 255, 0.2)", rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, - } + }, ); export const belowIndexDecorationType = vscode.window.createTextEditorDecorationType({ @@ -35,7 +35,7 @@ export class DecorationTypeRangeManager { constructor( decorationType: vscode.TextEditorDecorationType, - editor: vscode.TextEditor + editor: vscode.TextEditor, ) { this.decorationType = decorationType; this.editor = editor; @@ -48,7 +48,7 @@ export class DecorationTypeRangeManager { if (lastRange && lastRange.end.line === startIndex - 1) { this.ranges[this.ranges.length - 1] = lastRange.with( undefined, - lastRange.end.translate(numLines) + lastRange.end.translate(numLines), ); } else { this.ranges.push( @@ -56,8 +56,8 @@ export class DecorationTypeRangeManager { startIndex, 0, startIndex + numLines - 1, - Number.MAX_SAFE_INTEGER - ) + Number.MAX_SAFE_INTEGER, + ), ); } @@ -79,11 +79,11 @@ export class DecorationTypeRangeManager { private translateRange( range: vscode.Range, - lineOffset: number + lineOffset: number, ): vscode.Range { return new vscode.Range( range.start.translate(lineOffset), - range.end.translate(lineOffset) + range.end.translate(lineOffset), ); } diff --git a/extensions/vscode/src/diff/verticalPerLine/handler.ts b/extensions/vscode/src/diff/verticalPerLine/handler.ts index d6737b701..302456eef 100644 --- a/extensions/vscode/src/diff/verticalPerLine/handler.ts +++ b/extensions/vscode/src/diff/verticalPerLine/handler.ts @@ -36,9 +36,9 @@ export class VerticalPerLineDiffHandler { >, private readonly clearForFilepath: ( filepath: string | undefined, - accept: boolean + accept: boolean, ) => void, - input?: string + input?: string, ) { this.currentLineIndex = startLine; this.startLine = startLine; @@ -48,11 +48,11 @@ export class VerticalPerLineDiffHandler { this.redDecorationManager = new DecorationTypeRangeManager( redDecorationType, - this.editor + this.editor, ); this.greenDecorationManager = new DecorationTypeRangeManager( greenDecorationType, - this.editor + this.editor, ); } @@ -93,16 +93,16 @@ export class VerticalPerLineDiffHandler { // Insert the block of deleted lines await this.insertTextAboveLine( this.currentLineIndex - this.insertedInCurrentBlock, - totalDeletedContent + totalDeletedContent, ); this.redDecorationManager.addLines( this.currentLineIndex - this.insertedInCurrentBlock, - this.deletionBuffer.length + this.deletionBuffer.length, ); // Shift green decorations downward this.greenDecorationManager.shiftDownAfterLine( this.currentLineIndex - this.insertedInCurrentBlock, - this.deletionBuffer.length + this.deletionBuffer.length, ); // Update line index, clear buffer @@ -128,9 +128,9 @@ export class VerticalPerLineDiffHandler { editBuilder.insert( new vscode.Position( lineCount, - this.editor.document.lineAt(lineCount - 1).text.length + this.editor.document.lineAt(lineCount - 1).text.length, ), - "\n" + text + "\n" + text, ); } else { editBuilder.insert(new vscode.Position(index, 0), text + "\n"); @@ -148,7 +148,7 @@ export class VerticalPerLineDiffHandler { const startLine = new vscode.Position(index, 0); await this.editor.edit((editBuilder) => { editBuilder.delete( - new vscode.Range(startLine, startLine.translate(numLines)) + new vscode.Range(startLine, startLine.translate(numLines)), ); }); } @@ -164,7 +164,7 @@ export class VerticalPerLineDiffHandler { this.editor.setDecorations(indexDecorationType, [ new vscode.Range( start, - new vscode.Position(start.line, Number.MAX_SAFE_INTEGER) + new vscode.Position(start.line, Number.MAX_SAFE_INTEGER), ), ]); const end = new vscode.Position(this.endLine, 0); @@ -183,7 +183,7 @@ export class VerticalPerLineDiffHandler { vscode.commands.executeCommand( "setContext", "continue.streamingDiff", - false + false, ); const rangesToDelete = accept ? this.redDecorationManager.getRanges() @@ -200,8 +200,8 @@ export class VerticalPerLineDiffHandler { editBuilder.delete( new vscode.Range( range.start, - new vscode.Position(range.end.line + 1, 0) - ) + new vscode.Position(range.end.line + 1, 0), + ), ); } }); @@ -265,7 +265,7 @@ export class VerticalPerLineDiffHandler { accept: boolean, startLine: number, numGreen: number, - numRed: number + numRed: number, ) { if (numGreen > 0) { // Delete the editor decoration diff --git a/extensions/vscode/src/diff/verticalPerLine/manager.ts b/extensions/vscode/src/diff/verticalPerLine/manager.ts index e4dff637e..85814ae38 100644 --- a/extensions/vscode/src/diff/verticalPerLine/manager.ts +++ b/extensions/vscode/src/diff/verticalPerLine/manager.ts @@ -22,7 +22,7 @@ export class VerticalPerLineDiffManager { filepath: string, startLine: number, endLine: number, - input: string + input: string, ) { if (this.filepathToEditorMap.has(filepath)) { this.filepathToEditorMap.get(filepath)?.clear(false); @@ -36,7 +36,7 @@ export class VerticalPerLineDiffManager { editor, this.editorToVerticalDiffCodeLens, this.clearForFilepath, - input + input, ); this.filepathToEditorMap.set(filepath, handler); return handler; @@ -48,7 +48,7 @@ export class VerticalPerLineDiffManager { getOrCreateVerticalPerLineDiffHandler( filepath: string, startLine: number, - endLine: number + endLine: number, ) { if (this.filepathToEditorMap.has(filepath)) { return this.filepathToEditorMap.get(filepath)!; @@ -60,7 +60,7 @@ export class VerticalPerLineDiffManager { endLine, editor, this.editorToVerticalDiffCodeLens, - this.clearForFilepath + this.clearForFilepath, ); this.filepathToEditorMap.set(filepath, handler); return handler; @@ -93,7 +93,7 @@ export class VerticalPerLineDiffManager { acceptRejectVerticalDiffBlock( accept: boolean, filepath?: string, - index?: number + index?: number, ) { if (!filepath) { const activeEditor = vscode.window.activeTextEditor; @@ -123,7 +123,7 @@ export class VerticalPerLineDiffManager { accept, block.start, block.numGreen, - block.numRed + block.numRed, ); } @@ -146,7 +146,7 @@ export class VerticalPerLineDiffManager { filepath, existingHandler?.range.start.line ?? startLine, existingHandler?.range.end.line ?? endLine, - input + input, ); if (!diffHandler) { return; @@ -156,7 +156,7 @@ export class VerticalPerLineDiffManager { existingHandler?.range ?? new vscode.Range( editor.selection.start.with(undefined, 0), - editor.selection.end.with(undefined, Number.MAX_SAFE_INTEGER) + editor.selection.end.with(undefined, Number.MAX_SAFE_INTEGER), ); const rangeContent = editor.document.getText(selectedRange); const llm = await this.configHandler.llmFromTitle(); @@ -164,19 +164,19 @@ export class VerticalPerLineDiffManager { // Unselect the range editor.selection = new vscode.Selection( editor.selection.active, - editor.selection.active + editor.selection.active, ); vscode.commands.executeCommand( "setContext", "continue.streamingDiff", - true + true, ); if (existingHandler?.input) { if (existingHandler.input.startsWith("Original request: ")) { existingHandler.input = existingHandler.input.substring( - "Original request: ".length + "Original request: ".length, ); } input = `Original request: ${existingHandler.input}\nUpdated request: ${input}`; @@ -187,14 +187,14 @@ export class VerticalPerLineDiffManager { rangeContent, llm, input, - getMarkdownLanguageTagForFile(filepath) - ) + getMarkdownLanguageTagForFile(filepath), + ), ); } finally { vscode.commands.executeCommand( "setContext", "continue.streamingDiff", - false + false, ); } } diff --git a/extensions/vscode/src/extension.ts b/extensions/vscode/src/extension.ts index a4cc680c3..dc164b6ee 100644 --- a/extensions/vscode/src/extension.ts +++ b/extensions/vscode/src/extension.ts @@ -16,7 +16,7 @@ async function dynamicImportAndActivate(context: vscode.ExtensionContext) { .showInformationMessage( "Error activating the Continue extension.", "View Logs", - "Retry" + "Retry", ) .then((selection) => { if (selection === "View Logs") { diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index 15c0e94b9..00521d338 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -2,9 +2,7 @@ import { ConfigHandler } from "core/config/handler"; import { CodebaseIndexer, PauseToken } from "core/indexing/indexCodebase"; import { v4 as uuidv4 } from "uuid"; import * as vscode from "vscode"; -import { - ContinueCompletionProvider, -} from "../autocomplete/completionProvider"; +import { ContinueCompletionProvider } from "../autocomplete/completionProvider"; import { setupStatusBar } from "../autocomplete/statusBar"; import { registerAllCommands } from "../commands"; import { ContinueGUIWebviewViewProvider } from "../debugPanel"; @@ -37,7 +35,7 @@ export class VsCodeExtension { // Config Handler with output channel const outputChannel = vscode.window.createOutputChannel( - "Continue - LLM Prompt/Completion" + "Continue - LLM Prompt/Completion", ); this.configHandler = new ConfigHandler( this.ide, @@ -46,19 +44,19 @@ export class VsCodeExtension { : new URL(remoteUrl), async (log: string) => { outputChannel.appendLine( - "==========================================================================" + "==========================================================================", ); outputChannel.appendLine( - "==========================================================================" + "==========================================================================", ); outputChannel.append(log); }, - () => this.webviewProtocol?.request("configUpdate", undefined) + () => this.webviewProtocol?.request("configUpdate", undefined), ); this.configHandler.reloadConfig(); this.verticalDiffManager = new VerticalPerLineDiffManager( - this.configHandler + this.configHandler, ); this.extensionContext = context; this.tabAutocompleteModel = new TabAutocompleteModel(this.configHandler); @@ -68,11 +66,11 @@ export class VsCodeExtension { this.ide, this.windowId, this.extensionContext, - this.verticalDiffManager + this.verticalDiffManager, ); try { const configSync = new RemoteConfigSync( - this.configHandler.reloadConfig.bind(this.configHandler) + this.configHandler.reloadConfig.bind(this.configHandler), ); configSync.setup(); } catch (e) { @@ -86,14 +84,14 @@ export class VsCodeExtension { this.sidebar, { webviewOptions: { retainContextWhenHidden: true }, - } - ) + }, + ), ); this.webviewProtocol = this.sidebar.webviewProtocol; // Indexing + pause token const indexingPauseToken = new PauseToken( - context.globalState.get("continue.indexingPaused") === true + context.globalState.get("continue.indexingPaused") === true, ); this.webviewProtocol.on("index/setPaused", (msg) => { context.globalState.update("continue.indexingPaused", msg.data); @@ -104,14 +102,14 @@ export class VsCodeExtension { this.indexer = new CodebaseIndexer( this.configHandler, this.ide, - indexingPauseToken + indexingPauseToken, ); // CodeLens registerAllCodeLensProviders( context, this.diffManager, - this.verticalDiffManager.editorToVerticalDiffCodeLens + this.verticalDiffManager.editorToVerticalDiffCodeLens, ); // Tab autocomplete @@ -130,9 +128,9 @@ export class VsCodeExtension { new ContinueCompletionProvider( this.configHandler, this.ide, - this.tabAutocompleteModel - ) - ) + this.tabAutocompleteModel, + ), + ), ); } @@ -144,7 +142,7 @@ export class VsCodeExtension { this.sidebar, this.configHandler, this.diffManager, - this.verticalDiffManager + this.verticalDiffManager, ); // Indexing @@ -193,7 +191,7 @@ export class VsCodeExtension { } }); } - }) + }), ); // Register a content provider for the readonly virtual documents @@ -211,8 +209,8 @@ export class VsCodeExtension { context.subscriptions.push( vscode.workspace.registerTextDocumentContentProvider( VsCodeExtension.continueVirtualDocumentScheme, - documentContentProvider - ) + documentContentProvider, + ), ); } diff --git a/extensions/vscode/src/lang-server/codeActions.ts b/extensions/vscode/src/lang-server/codeActions.ts index 892c69bef..0dbee4b43 100644 --- a/extensions/vscode/src/lang-server/codeActions.ts +++ b/extensions/vscode/src/lang-server/codeActions.ts @@ -9,7 +9,7 @@ class ContinueQuickFixProvider implements vscode.CodeActionProvider { document: vscode.TextDocument, range: vscode.Range | vscode.Selection, context: vscode.CodeActionContext, - token: vscode.CancellationToken + token: vscode.CancellationToken, ): vscode.ProviderResult<(vscode.Command | vscode.CodeAction)[]> { if (context.diagnostics.length === 0) { return []; @@ -19,14 +19,14 @@ class ContinueQuickFixProvider implements vscode.CodeActionProvider { const diagnostic = context.diagnostics[0]; const quickFix = new vscode.CodeAction( edit ? "Fix with Continue" : "Ask Continue", - vscode.CodeActionKind.QuickFix + vscode.CodeActionKind.QuickFix, ); quickFix.isPreferred = false; const surroundingRange = new vscode.Range( Math.max(0, range.start.line - 3), 0, Math.min(document.lineCount, range.end.line + 3), - 0 + 0, ); quickFix.command = { command: "continue.quickFix", @@ -53,6 +53,6 @@ export default function registerQuickFixProvider() { new ContinueQuickFixProvider(), { providedCodeActionKinds: ContinueQuickFixProvider.providedCodeActionKinds, - } + }, ); } diff --git a/extensions/vscode/src/lang-server/codeLens.ts b/extensions/vscode/src/lang-server/codeLens.ts index c75aa1c24..d2a2686a9 100644 --- a/extensions/vscode/src/lang-server/codeLens.ts +++ b/extensions/vscode/src/lang-server/codeLens.ts @@ -12,12 +12,12 @@ class VerticalPerLineCodeLensProvider implements vscode.CodeLensProvider { private readonly editorToVerticalDiffCodeLens: Map< string, VerticalDiffCodeLens[] - > + >, ) {} public provideCodeLenses( document: vscode.TextDocument, - _: vscode.CancellationToken + _: vscode.CancellationToken, ): vscode.CodeLens[] | Thenable { const filepath = document.uri.fsPath; const blocks = this.editorToVerticalDiffCodeLens.get(filepath); @@ -31,7 +31,7 @@ class VerticalPerLineCodeLensProvider implements vscode.CodeLensProvider { const start = new vscode.Position(block.start, 0); const range = new vscode.Range( start, - start.translate(block.numGreen + block.numRed) + start.translate(block.numGreen + block.numRed), ); codeLenses.push( new vscode.CodeLens(range, { @@ -43,14 +43,14 @@ class VerticalPerLineCodeLensProvider implements vscode.CodeLensProvider { title: "Reject", command: "continue.rejectVerticalDiffBlock", arguments: [filepath, i], - }) + }), ); if (codeLenses.length === 2) { codeLenses.push( new vscode.CodeLens(range, { title: `(${getMetaKeyLabel()}⇧↩/${getMetaKeyLabel()}⇧⌫ to accept/reject all, ${getMetaKeyLabel()}I to retry)`, command: "", - }) + }), ); } } @@ -62,7 +62,7 @@ class VerticalPerLineCodeLensProvider implements vscode.CodeLensProvider { class SuggestionsCodeLensProvider implements vscode.CodeLensProvider { public provideCodeLenses( document: vscode.TextDocument, - _: vscode.CancellationToken + _: vscode.CancellationToken, ): vscode.CodeLens[] | Thenable { const suggestions = editorToSuggestions.get(document.uri.toString()); if (!suggestions) { @@ -74,7 +74,7 @@ class SuggestionsCodeLensProvider implements vscode.CodeLensProvider { for (const suggestion of suggestions) { const range = new vscode.Range( suggestion.oldRange.start, - suggestion.newRange.end + suggestion.newRange.end, ); codeLenses.push( new vscode.CodeLens(range, { @@ -86,14 +86,14 @@ class SuggestionsCodeLensProvider implements vscode.CodeLensProvider { title: "Reject", command: "continue.rejectSuggestion", arguments: [suggestion], - }) + }), ); if (codeLenses.length === 2) { codeLenses.push( new vscode.CodeLens(range, { title: `(${getMetaKeyLabel()}⇧↩/${getMetaKeyLabel()}⇧⌫ to accept/reject all)`, command: "", - }) + }), ); } } @@ -111,7 +111,7 @@ class DiffViewerCodeLensProvider implements vscode.CodeLensProvider { public provideCodeLenses( document: vscode.TextDocument, - _: vscode.CancellationToken + _: vscode.CancellationToken, ): vscode.CodeLens[] | Thenable { if (path.dirname(document.uri.fsPath) === DIFF_DIRECTORY) { const codeLenses: vscode.CodeLens[] = []; @@ -130,7 +130,7 @@ class DiffViewerCodeLensProvider implements vscode.CodeLensProvider { title: `Reject All ❌ (${getMetaKeyLabel()}⇧⌫)`, command: "continue.rejectDiff", arguments: [document.uri.fsPath], - }) + }), // new vscode.CodeLens(range, { // title: `Further Edit ✏️ (${getMetaKeyLabel()}⇧M)`, // command: "continue.focusContinueInputWithEdit", @@ -146,7 +146,7 @@ class DiffViewerCodeLensProvider implements vscode.CodeLensProvider { class ConfigPyCodeLensProvider implements vscode.CodeLensProvider { public provideCodeLenses( document: vscode.TextDocument, - _: vscode.CancellationToken + _: vscode.CancellationToken, ): vscode.CodeLens[] | Thenable { const codeLenses: vscode.CodeLens[] = []; @@ -171,7 +171,7 @@ class ConfigPyCodeLensProvider implements vscode.CodeLensProvider { } const lineOfSystemMessage = lines.findIndex((line) => - line.includes("ContinueConfig(") + line.includes("ContinueConfig("), ); if (lineOfSystemMessage >= 0) { @@ -179,13 +179,13 @@ class ConfigPyCodeLensProvider implements vscode.CodeLensProvider { lineOfSystemMessage, 0, lineOfSystemMessage + 1, - 0 + 0, ); codeLenses.push( new vscode.CodeLens(range, { title: `✏️ Edit in UI`, command: "continue.openSettingsUI", - }) + }), ); } @@ -265,7 +265,7 @@ const actions: TutorialCodeLensItems[] = [ class TutorialCodeLensProvider implements vscode.CodeLensProvider { public provideCodeLenses( document: vscode.TextDocument, - _: vscode.CancellationToken + _: vscode.CancellationToken, ): vscode.CodeLens[] | Thenable { const codeLenses: vscode.CodeLens[] = []; @@ -277,7 +277,7 @@ class TutorialCodeLensProvider implements vscode.CodeLensProvider { for (const action of actions) { const lineOfAction = lines.findIndex((line) => - line.includes(action.lineIncludes) + line.includes(action.lineIncludes), ); if (lineOfAction >= 0) { @@ -289,7 +289,7 @@ class TutorialCodeLensProvider implements vscode.CodeLensProvider { } const lineOf11 = lines.findIndex((line) => - line.includes("Step 1: Highlight the function below") + line.includes("Step 1: Highlight the function below"), ); if (lineOf11 >= 0) { const range = new vscode.Range(lineOf11, 0, lineOf11 + 1, 0); @@ -298,11 +298,11 @@ class TutorialCodeLensProvider implements vscode.CodeLensProvider { title: "Highlight the function", command: "continue.selectRange", arguments: [lineOf11 + 3, lineOf11 + 11], - }) + }), ); } const lineOf21 = lines.findIndex((line) => - line.includes("Step 1: Highlight this code") + line.includes("Step 1: Highlight this code"), ); if (lineOf21 >= 0) { const range = new vscode.Range(lineOf21, 0, lineOf21 + 1, 0); @@ -311,7 +311,7 @@ class TutorialCodeLensProvider implements vscode.CodeLensProvider { title: "Highlight the function", command: "continue.selectRange", arguments: [lineOf21 + 3, lineOf21 + 14], - }) + }), ); } @@ -333,7 +333,7 @@ class TutorialCodeLensProvider implements vscode.CodeLensProvider { title: `Begin Section`, command: "continue.foldAndUnfold", arguments: [linesToFold, [lineOfRegion, lineOfRegion + 1]], - }) + }), ); } @@ -350,7 +350,7 @@ let tutorialCodeLensDisposable: vscode.Disposable | undefined = undefined; export function registerAllCodeLensProviders( context: vscode.ExtensionContext, diffManager: DiffManager, - editorToVerticalDiffCodeLens: Map + editorToVerticalDiffCodeLens: Map, ) { if (verticalPerLineCodeLensProvider) { verticalPerLineCodeLensProvider.dispose(); @@ -370,23 +370,23 @@ export function registerAllCodeLensProviders( verticalPerLineCodeLensProvider = vscode.languages.registerCodeLensProvider( "*", - new VerticalPerLineCodeLensProvider(editorToVerticalDiffCodeLens) + new VerticalPerLineCodeLensProvider(editorToVerticalDiffCodeLens), ); suggestionsCodeLensDisposable = vscode.languages.registerCodeLensProvider( "*", - new SuggestionsCodeLensProvider() + new SuggestionsCodeLensProvider(), ); diffsCodeLensDisposable = vscode.languages.registerCodeLensProvider( "*", - new DiffViewerCodeLensProvider(diffManager) + new DiffViewerCodeLensProvider(diffManager), ); configPyCodeLensDisposable = vscode.languages.registerCodeLensProvider( "*", - new ConfigPyCodeLensProvider() + new ConfigPyCodeLensProvider(), ); tutorialCodeLensDisposable = vscode.languages.registerCodeLensProvider( "*", - new TutorialCodeLensProvider() + new TutorialCodeLensProvider(), ); context.subscriptions.push(verticalPerLineCodeLensProvider); context.subscriptions.push(suggestionsCodeLensDisposable); diff --git a/extensions/vscode/src/suggestions.ts b/extensions/vscode/src/suggestions.ts index e13cb42b4..5a6d2985e 100644 --- a/extensions/vscode/src/suggestions.ts +++ b/extensions/vscode/src/suggestions.ts @@ -55,7 +55,7 @@ export function rerenderDecorations(editorUri: string) { const suggestions = editorToSuggestions.get(editorUri); const idx = currentSuggestion.get(editorUri); const editor = vscode.window.visibleTextEditors.find( - (editor) => editor.document.uri.toString() === editorUri + (editor) => editor.document.uri.toString() === editorUri, ); if (!suggestions || !editor) return; @@ -77,8 +77,8 @@ export function rerenderDecorations(editorUri: string) { range.start.character, // Don't include the last line if it is empty range.end.line - (range.end.character === 0 ? 1 : 0), - range.end.character - ) + range.end.character, + ), ); } return newRanges; @@ -119,7 +119,7 @@ export function rerenderDecorations(editorUri: string) { if (idx === undefined) return; editor.revealRange( suggestions[idx].newRange, - vscode.TextEditorRevealType.Default + vscode.TextEditorRevealType.Default, ); // if (extensionContext) { @@ -164,7 +164,7 @@ export function suggestionUpCommand() { type SuggestionSelectionOption = "old" | "new" | "selected"; function selectSuggestion( accept: SuggestionSelectionOption, - key: SuggestionRanges | null = null + key: SuggestionRanges | null = null, ) { const editor = vscode.window.activeTextEditor; if (!editor) return; @@ -210,7 +210,7 @@ function selectSuggestion( rangeToDelete = new vscode.Range( rangeToDelete.start, - new vscode.Position(rangeToDelete.end.line, 0) + new vscode.Position(rangeToDelete.end.line, 0), ); editor.edit((edit) => { edit.delete(rangeToDelete); @@ -264,7 +264,7 @@ export function rejectAllSuggestionsCommand() { } export async function rejectSuggestionCommand( - key: SuggestionRanges | null = null + key: SuggestionRanges | null = null, ) { selectSuggestion("old", key); } @@ -272,7 +272,7 @@ export async function rejectSuggestionCommand( export async function showSuggestion( editorFilename: string, range: vscode.Range, - suggestion: string + suggestion: string, ): Promise { // Check for empty suggestions: if ( @@ -292,10 +292,10 @@ export async function showSuggestion( (edit) => { edit.insert( new vscode.Position(range.end.line, 0), - suggestion + (suggestion === "" ? "" : "\n") + suggestion + (suggestion === "" ? "" : "\n"), ); }, - { undoStopBefore: false, undoStopAfter: false } + { undoStopBefore: false, undoStopAfter: false }, ) .then( (success) => { @@ -304,7 +304,7 @@ export async function showSuggestion( suggestion === "" ? 0 : suggestion.split("\n").length; let suggestionRange = new vscode.Range( new vscode.Position(range.end.line, 0), - new vscode.Position(range.end.line + suggestionLinesLength, 0) + new vscode.Position(range.end.line + suggestionLinesLength, 0), ); let content = editor!.document.getText(suggestionRange); @@ -335,7 +335,7 @@ export async function showSuggestion( } resolve(success); }, - (reason) => reject(reason) + (reason) => reject(reason), ); }); } diff --git a/extensions/vscode/src/terminal/terminalEmulator.ts b/extensions/vscode/src/terminal/terminalEmulator.ts index 15faf0993..960f5ef8e 100644 --- a/extensions/vscode/src/terminal/terminalEmulator.ts +++ b/extensions/vscode/src/terminal/terminalEmulator.ts @@ -164,7 +164,7 @@ export class CapturedTerminal { constructor( options: { name: string } & Partial, - onCommandOutput?: (output: string) => void + onCommandOutput?: (output: string) => void, ) { this.onCommandOutput = onCommandOutput; @@ -205,7 +205,7 @@ export class CapturedTerminal { (line) => line.trim().length > 0 && line.trim() !== "%" && - line.trim() !== "⏎" + line.trim() !== "⏎", ); const lastLine = strippedLines[strippedLines.length - 1] || ""; const lines = lastLine @@ -214,7 +214,7 @@ export class CapturedTerminal { (line) => line.trim().length > 0 && line.trim() !== "%" && - line.trim() !== "⏎" + line.trim() !== "⏎", ); const commandPromptString = (lines[lines.length - 1] || "").trim(); if ( @@ -225,7 +225,7 @@ export class CapturedTerminal { this.seenClear = false; this.commandPromptString = commandPromptString; console.log( - "Found command prompt string: " + this.commandPromptString + "Found command prompt string: " + this.commandPromptString, ); if (this.resolveMeWhenCommandPromptStringFound) { this.resolveMeWhenCommandPromptStringFound(undefined); diff --git a/extensions/vscode/src/util/getTheme.ts b/extensions/vscode/src/util/getTheme.ts index 81a0ad909..50a7e6132 100644 --- a/extensions/vscode/src/util/getTheme.ts +++ b/extensions/vscode/src/util/getTheme.ts @@ -60,7 +60,7 @@ export function getTheme() { const filename = builtinThemes[colorTheme] + ".json"; currentTheme = fs .readFileSync( - path.join(getExtensionUri().fsPath, "builtin-themes", filename) + path.join(getExtensionUri().fsPath, "builtin-themes", filename), ) .toString(); } @@ -71,7 +71,7 @@ export function getTheme() { if (parsed.include) { const includeThemeString = fs .readFileSync( - path.join(getExtensionUri().fsPath, "builtin-themes", parsed.include) + path.join(getExtensionUri().fsPath, "builtin-themes", parsed.include), ) .toString(); const includeTheme = parseThemeString(includeThemeString); diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index 49b04a44c..47208a95d 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -23,12 +23,12 @@ export class VsCodeIdeUtils { async gotoDefinition( filepath: string, - position: vscode.Position + position: vscode.Position, ): Promise { const locations: vscode.Location[] = await vscode.commands.executeCommand( "vscode.executeDefinitionProvider", uriFromFilePath(filepath), - position + position, ); return locations; } @@ -36,25 +36,25 @@ export class VsCodeIdeUtils { async documentSymbol(filepath: string): Promise { return await vscode.commands.executeCommand( "vscode.executeDocumentSymbolProvider", - uriFromFilePath(filepath) + uriFromFilePath(filepath), ); } async references( filepath: string, - position: vscode.Position + position: vscode.Position, ): Promise { return await vscode.commands.executeCommand( "vscode.executeReferenceProvider", uriFromFilePath(filepath), - position + position, ); } async foldingRanges(filepath: string): Promise { return await vscode.commands.executeCommand( "vscode.executeFoldingRangeProvider", - uriFromFilePath(filepath) + uriFromFilePath(filepath), ); } @@ -78,12 +78,12 @@ export class VsCodeIdeUtils { rangeInFile.range.start.line, rangeInFile.range.start.character, rangeInFile.range.end.line, - rangeInFile.range.end.character + rangeInFile.range.end.character, ); const editor = await openEditorAndRevealRange( rangeInFile.filepath, range, - vscode.ViewColumn.One + vscode.ViewColumn.One, ); if (editor) { const decorationType = vscode.window.createTextEditorDecorationType({ @@ -98,7 +98,7 @@ export class VsCodeIdeUtils { cursorDisposable.dispose(); editor.setDecorations(decorationType, []); } - } + }, ); setTimeout(() => { @@ -121,9 +121,9 @@ export class VsCodeIdeUtils { edit.range.start.line, edit.range.start.character, edit.range.end.line, - edit.range.end.character + edit.range.end.character, ), - edit.replacement + edit.replacement, ); } @@ -132,7 +132,7 @@ export class VsCodeIdeUtils { const panel = vscode.window.createWebviewPanel( "continue.continueGUIView", "Continue", - vscode.ViewColumn.One + vscode.ViewColumn.One, ); // panel.webview.html = this.sidebar.getSidebarContent( // extensionContext, @@ -163,8 +163,8 @@ export class VsCodeIdeUtils { vscode.Uri.parse( `${ VsCodeExtension.continueVirtualDocumentScheme - }:${encodeURIComponent(name)}?${encodeURIComponent(contents)}` - ) + }:${encodeURIComponent(name)}?${encodeURIComponent(contents)}`, + ), ) .then((doc) => { vscode.window.showTextDocument(doc, { preview: false }); @@ -246,7 +246,7 @@ export class VsCodeIdeUtils { async getDirectoryContents( directory: string, - recursive: boolean + recursive: boolean, ): Promise { if (!recursive) { return ( @@ -271,7 +271,7 @@ export class VsCodeIdeUtils { gitRoot || directory, [], true, - gitRoot === directory ? undefined : onlyThisDirectory + gitRoot === directory ? undefined : onlyThisDirectory, )) { allFiles.push(file); } @@ -295,14 +295,14 @@ export class VsCodeIdeUtils { if (typeof contents === "undefined") { try { const fileStats = await vscode.workspace.fs.stat( - uriFromFilePath(filepath) + uriFromFilePath(filepath), ); if (fileStats.size > 10 * MAX_BYTES) { return ""; } const bytes = await vscode.workspace.fs.readFile( - uriFromFilePath(filepath) + uriFromFilePath(filepath), ); // Truncate the buffer to the first MAX_BYTES @@ -317,10 +317,10 @@ export class VsCodeIdeUtils { async readRangeInFile( filepath: string, - range: vscode.Range + range: vscode.Range, ): Promise { const contents = new TextDecoder().decode( - await vscode.workspace.fs.readFile(vscode.Uri.file(filepath)) + await vscode.workspace.fs.readFile(vscode.Uri.file(filepath)), ); const lines = contents.split("\n"); return ( @@ -334,20 +334,20 @@ export class VsCodeIdeUtils { const tempCopyBuffer = await vscode.env.clipboard.readText(); if (commands < 0) { await vscode.commands.executeCommand( - "workbench.action.terminal.selectAll" + "workbench.action.terminal.selectAll", ); } else { for (let i = 0; i < commands; i++) { await vscode.commands.executeCommand( - "workbench.action.terminal.selectToPreviousCommand" + "workbench.action.terminal.selectToPreviousCommand", ); } } await vscode.commands.executeCommand( - "workbench.action.terminal.copySelection" + "workbench.action.terminal.copySelection", ); await vscode.commands.executeCommand( - "workbench.action.terminal.clearSelection" + "workbench.action.terminal.clearSelection", ); const terminalContents = await vscode.env.clipboard.readText(); await vscode.env.clipboard.writeText(tempCopyBuffer); diff --git a/extensions/vscode/src/util/loadAutocompleteModel.ts b/extensions/vscode/src/util/loadAutocompleteModel.ts index a720cad51..41fd7f886 100644 --- a/extensions/vscode/src/util/loadAutocompleteModel.ts +++ b/extensions/vscode/src/util/loadAutocompleteModel.ts @@ -34,14 +34,14 @@ export class TabAutocompleteModel { .showWarningMessage( `Your local Ollama instance doesn't yet have ${this.defaultTagName}. To download this model, run \`ollama run ${this.defaultTag}\` (recommended). If you'd like to use a custom model for tab autocomplete, learn more in the docs`, "Documentation", - "Copy Command" + "Copy Command", ) .then((value) => { if (value === "Documentation") { vscode.env.openExternal( vscode.Uri.parse( - "https://continue.dev/docs/walkthroughs/tab-autocomplete" - ) + "https://continue.dev/docs/walkthroughs/tab-autocomplete", + ), ); } else if (value === "Copy Command") { vscode.env.clipboard.writeText(`ollama run ${this.defaultTag}`); @@ -56,14 +56,14 @@ export class TabAutocompleteModel { vscode.window .showWarningMessage( "Continue failed to connect to Ollama, which is used by default for tab-autocomplete. If you haven't downloaded it yet, you can do so at https://ollama.ai (recommended). If you'd like to use a custom model for tab autocomplete, learn more in the docs", - "Documentation" + "Documentation", ) .then((value) => { if (value === "Documentation") { vscode.env.openExternal( vscode.Uri.parse( - "https://continue.dev/docs/walkthroughs/tab-autocomplete" - ) + "https://continue.dev/docs/walkthroughs/tab-autocomplete", + ), ); } }); diff --git a/extensions/vscode/src/util/remoteConfig.ts b/extensions/vscode/src/util/remoteConfig.ts index 2f27664a4..294277484 100644 --- a/extensions/vscode/src/util/remoteConfig.ts +++ b/extensions/vscode/src/util/remoteConfig.ts @@ -44,11 +44,11 @@ export class RemoteConfigSync { const userToken = settings.get("userToken", null); const remoteConfigServerUrl = settings.get( "remoteConfigServerUrl", - null + null, ); const remoteConfigSyncPeriod = settings.get( "remoteConfigSyncPeriod", - 60 + 60, ); return { @@ -69,7 +69,7 @@ export class RemoteConfigSync { if (!URL.canParse(this.remoteConfigServerUrl)) { vscode.window.showErrorMessage( "The value set for 'remoteConfigServerUrl' is not valid: ", - this.remoteConfigServerUrl + this.remoteConfigServerUrl, ); return; } @@ -85,10 +85,13 @@ export class RemoteConfigSync { if (this.syncInterval !== undefined) { clearInterval(this.syncInterval); } - this.syncInterval = setInterval(() => { - if (!this.userToken || !this.remoteConfigServerUrl) return; - this.sync(this.userToken, new URL(this.remoteConfigServerUrl)); - }, this.remoteConfigSyncPeriod * 1000 * 60); + this.syncInterval = setInterval( + () => { + if (!this.userToken || !this.remoteConfigServerUrl) return; + this.sync(this.userToken, new URL(this.remoteConfigServerUrl)); + }, + this.remoteConfigSyncPeriod * 1000 * 60, + ); } async sync(userToken: string, remoteConfigServerUrl: URL) { @@ -100,12 +103,12 @@ export class RemoteConfigSync { headers: { Authorization: `Bearer ${userToken}`, }, - } + }, ); if (!response.ok) { vscode.window.showErrorMessage( - `Failed to sync remote config (HTTP ${response.status}): ${response.statusText}` + `Failed to sync remote config (HTTP ${response.status}): ${response.statusText}`, ); return; } @@ -114,11 +117,11 @@ export class RemoteConfigSync { fs.writeFileSync( getConfigJsonPathForRemote(remoteConfigServerUrl), - configJson + configJson, ); fs.writeFileSync( getConfigJsPathForRemote(remoteConfigServerUrl), - configJs + configJs, ); this.triggerReloadConfig(); } catch (e) { diff --git a/extensions/vscode/src/util/traverseDirectory.ts b/extensions/vscode/src/util/traverseDirectory.ts index a1bc63d95..e1af01848 100644 --- a/extensions/vscode/src/util/traverseDirectory.ts +++ b/extensions/vscode/src/util/traverseDirectory.ts @@ -98,10 +98,10 @@ export async function* traverseDirectory( directory: string, gitIgnorePatterns: string[], returnFiles: boolean = true, - onlyThisDirectory: string[] | undefined + onlyThisDirectory: string[] | undefined, ): AsyncGenerator { const nodes = await vscode.workspace.fs.readDirectory( - uriFromFilePath(directory) + uriFromFilePath(directory), ); const files: string[] = []; const dirs: string[] = []; @@ -118,13 +118,13 @@ export async function* traverseDirectory( if (isIgnoreFilepath(name)) { // Make sure you are respecting windows with linux dev container const bytes = await vscode.workspace.fs.readFile( - uriFromFilePath(path.join(directory, name)) + uriFromFilePath(path.join(directory, name)), ); const contents = new TextDecoder().decode(bytes); ignorePatterns.push( ...contents .split("\n") - .filter((p) => p.trim() !== "" && p[0] !== "#") + .filter((p) => p.trim() !== "" && p[0] !== "#"), ); } else { files.push(name); @@ -144,7 +144,7 @@ export async function* traverseDirectory( return "**/" + pattern; } return pattern; - } + }, ); const ig = ignore().add(allIgnorePatterns); @@ -192,7 +192,7 @@ export async function* traverseDirectory( returnFiles, onlyThisDirectory && onlyThisDirectory.length > 1 ? onlyThisDirectory.slice(1) - : undefined + : undefined, )) { yield file; } diff --git a/extensions/vscode/src/util/vscode.ts b/extensions/vscode/src/util/vscode.ts index dccc75905..c385deac0 100644 --- a/extensions/vscode/src/util/vscode.ts +++ b/extensions/vscode/src/util/vscode.ts @@ -7,7 +7,7 @@ export function translate(range: vscode.Range, lines: number): vscode.Range { range.start.line + lines, range.start.character, range.end.line + lines, - range.end.character + range.end.character, ); } @@ -26,7 +26,7 @@ export function getExtensionUri(): vscode.Uri { } export function getViewColumnOfFile( - filepath: string + filepath: string, ): vscode.ViewColumn | undefined { for (let tabGroup of vscode.window.tabGroups.all) { for (let tab of tabGroup.tabs) { @@ -72,13 +72,13 @@ let showTextDocumentInProcess = false; export function openEditorAndRevealRange( editorFilename: string, range?: vscode.Range, - viewColumn?: vscode.ViewColumn + viewColumn?: vscode.ViewColumn, ): Promise { return new Promise((resolve, _) => { if (editorFilename.startsWith("~")) { editorFilename = path.join( process.env.HOME || process.env.USERPROFILE || "", - editorFilename.slice(1) + editorFilename.slice(1), ); } vscode.workspace.openTextDocument(editorFilename).then(async (doc) => { @@ -95,7 +95,7 @@ export function openEditorAndRevealRange( vscode.window .showTextDocument( doc, - getViewColumnOfFile(editorFilename) || viewColumn + getViewColumnOfFile(editorFilename) || viewColumn, ) .then((editor) => { if (range) { @@ -124,7 +124,7 @@ function isWindowsLocalButNotRemote(): boolean { return ( vscode.env.remoteName !== undefined && ["wsl", "ssh-remote", "dev-container", "attached-container"].includes( - vscode.env.remoteName + vscode.env.remoteName, ) && process.platform === "win32" ); @@ -140,7 +140,7 @@ export function uriFromFilePath(filepath: string): vscode.Uri { filepath = windowsToPosix(filepath); } return vscode.Uri.parse( - `vscode-remote://${vscode.env.remoteName}${filepath}` + `vscode-remote://${vscode.env.remoteName}${filepath}`, ); } else { return vscode.Uri.file(filepath); diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index 6cdda8a72..98f0e8834 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -33,8 +33,8 @@ export class VsCodeWebviewProtocol { on( messageType: T, handler: ( - message: Message - ) => Promise | WebviewProtocol[T][1] + message: Message, + ) => Promise | WebviewProtocol[T][1], ): void { if (!this.listeners.has(messageType)) { this.listeners.set(messageType, []); @@ -79,7 +79,7 @@ export class VsCodeWebviewProtocol { } catch (e: any) { console.error( "Error handling webview message: " + - JSON.stringify({ msg }, null, 2) + JSON.stringify({ msg }, null, 2), ); let message = `Continue error: ${e.message}`; @@ -98,11 +98,11 @@ export class VsCodeWebviewProtocol { .then((selection) => { if (selection === "Show Logs") { vscode.commands.executeCommand( - "workbench.action.toggleDevTools" + "workbench.action.toggleDevTools", ); } else if (selection === "Troubleshooting") { vscode.env.openExternal( - vscode.Uri.parse("https://continue.dev/docs/troubleshooting") + vscode.Uri.parse("https://continue.dev/docs/troubleshooting"), ); } }); @@ -114,7 +114,7 @@ export class VsCodeWebviewProtocol { constructor( private readonly ide: IDE, private readonly configHandler: ConfigHandler, - private readonly verticalDiffManager: VerticalPerLineDiffManager + private readonly verticalDiffManager: VerticalPerLineDiffManager, ) { this.on("abort", (msg) => { this.abortedMessageIds.add(msg.messageId); @@ -214,7 +214,7 @@ export class VsCodeWebviewProtocol { return await ide.showDiff( msg.data.filepath, msg.data.newContents, - msg.data.stepIndex + msg.data.stepIndex, ); }); @@ -277,12 +277,12 @@ export class VsCodeWebviewProtocol { this.ide.showLines( getConfigJsonPath(), startLine, - endLine + endLine, // "#fff1" ); } vscode.window.showInformationMessage( - "🎉 Your model has been successfully added to config.json. You can use this file to further edit its configuration." + "🎉 Your model has been successfully added to config.json. You can use this file to further edit its configuration.", ); }); this.on("config/deleteModel", (msg) => { @@ -296,12 +296,12 @@ export class VsCodeWebviewProtocol { async function* llmStreamComplete( protocol: VsCodeWebviewProtocol, - msg: Message + msg: Message, ) { const model = await protocol.configHandler.llmFromTitle(msg.data.title); const gen = model.streamComplete( msg.data.prompt, - msg.data.completionOptions + msg.data.completionOptions, ); let next = await gen.next(); while (!next.done) { @@ -320,12 +320,12 @@ export class VsCodeWebviewProtocol { async function* llmStreamChat( protocol: VsCodeWebviewProtocol, - msg: Message + msg: Message, ) { const model = await protocol.configHandler.llmFromTitle(msg.data.title); const gen = model.streamChat( msg.data.messages, - msg.data.completionOptions + msg.data.completionOptions, ); let next = await gen.next(); while (!next.done) { @@ -345,14 +345,14 @@ export class VsCodeWebviewProtocol { const model = await this.configHandler.llmFromTitle(msg.data.title); const completion = await model.complete( msg.data.prompt, - msg.data.completionOptions + msg.data.completionOptions, ); return completion; }); async function* runNodeJsSlashCommand( protocol: VsCodeWebviewProtocol, - msg: Message + msg: Message, ) { const { input, @@ -368,7 +368,7 @@ export class VsCodeWebviewProtocol { const config = await protocol.configHandler.loadConfig(); const llm = await protocol.configHandler.llmFromTitle(modelTitle); const slashCommand = config.slashCommands?.find( - (sc) => sc.name === slashCommandName + (sc) => sc.name === slashCommandName, ); if (!slashCommand) { throw new Error(`Unknown slash command ${slashCommandName}`); @@ -402,13 +402,13 @@ export class VsCodeWebviewProtocol { const { title } = msg.data; const config = await this.configHandler.loadConfig(); const provider = config.contextProviders?.find( - (p) => p.description.title === title + (p) => p.description.title === title, ); if (!provider) { vscode.window.showErrorMessage( `Unknown provider ${title}. Existing providers: ${config.contextProviders ?.map((p) => p.description.title) - .join(", ")}` + .join(", ")}`, ); return []; } @@ -418,7 +418,7 @@ export class VsCodeWebviewProtocol { return items; } catch (e) { vscode.window.showErrorMessage( - `Error loading submenu items from ${title}: ${e}` + `Error loading submenu items from ${title}: ${e}`, ); return []; } @@ -429,13 +429,13 @@ export class VsCodeWebviewProtocol { const config = await this.configHandler.loadConfig(); const llm = await this.configHandler.llmFromTitle(); const provider = config.contextProviders?.find( - (p) => p.description.title === name + (p) => p.description.title === name, ); if (!provider) { vscode.window.showErrorMessage( `Unknown provider ${name}. Existing providers: ${config.contextProviders ?.map((p) => p.description.title) - .join(", ")}` + .join(", ")}`, ); return []; } @@ -455,7 +455,7 @@ export class VsCodeWebviewProtocol { return items.map((item) => ({ ...item, id })); } catch (e) { vscode.window.showErrorMessage( - `Error getting context items from ${name}: ${e}` + `Error getting context items from ${name}: ${e}`, ); return []; } @@ -473,7 +473,7 @@ export class VsCodeWebviewProtocol { for await (const update of indexDocs( title, new URL(url), - embeddingsProvider + embeddingsProvider, )) { progress.report({ increment: update.progress, @@ -482,11 +482,11 @@ export class VsCodeWebviewProtocol { } vscode.window.showInformationMessage( - `🎉 Successfully indexed ${title}` + `🎉 Successfully indexed ${title}`, ); this.request("refreshSubmenuItems", undefined); - } + }, ); }); this.on("applyToCurrentFile", (msg) => { @@ -500,12 +500,12 @@ export class VsCodeWebviewProtocol { const start = new vscode.Position(0, 0); const end = new vscode.Position( document.lineCount - 1, - document.lineAt(document.lineCount - 1).text.length + document.lineAt(document.lineCount - 1).text.length, ); editor.selection = new vscode.Selection(start, end); this.verticalDiffManager.streamEdit( - `The following code was suggested as an edit:\n\`\`\`\n${msg.data.text}\n\`\`\`\nPlease apply it to the previous code.` + `The following code was suggested as an edit:\n\`\`\`\n${msg.data.text}\n\`\`\`\nPlease apply it to the previous code.`, ); }); this.on("showTutorial", (msg) => { @@ -519,7 +519,7 @@ export class VsCodeWebviewProtocol { public request( messageType: T, - data: ReverseWebviewProtocol[T][0] + data: ReverseWebviewProtocol[T][0], ): Promise { const messageId = uuidv4(); return new Promise((resolve) => {