From 30bfaa0904477e4db09420fdd6a9b54425a69fe5 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 15:37:07 -0700 Subject: [PATCH 01/31] add initial fplab static contextualization code --- .../static-context/StaticContextService.ts | 181 ++++++++++++++++++ .../queries/hole-queries/typescript.scm | 36 ++++ .../queries/hole-queries/typescript.ts | 36 ++++ .../typescript-get-toplevel-headers.scm | 22 +++ .../typescript-get-toplevel-headers.ts | 22 +++ .../typescript-extract-identifiers.scm | 10 + .../typescript-extract-identifiers.ts | 10 + ...ipt-find-typedecl-given-typeidentifier.scm | 11 ++ ...ript-find-typedecl-given-typeidentifier.ts | 11 ++ .../context/static-context/types.ts | 23 +++ 10 files changed, 362 insertions(+) create mode 100644 core/autocomplete/context/static-context/StaticContextService.ts create mode 100644 core/autocomplete/context/static-context/queries/hole-queries/typescript.scm create mode 100644 core/autocomplete/context/static-context/queries/hole-queries/typescript.ts create mode 100644 core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm create mode 100644 core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts create mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm create mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts create mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm create mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts create mode 100644 core/autocomplete/context/static-context/types.ts diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts new file mode 100644 index 000000000..eb005d0cb --- /dev/null +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -0,0 +1,181 @@ +import * as fs from "fs/promises"; +import { IDE, Position } from "../../.."; +import { AutocompleteCodeSnippet, AutocompleteStaticSnippet } from "../../snippets/types"; +import { HelperVars } from "../../util/HelperVars"; +import { HoleContext, RelevantHeaders, RelevantTypes } from "./types"; +import { getAst } from "../../util/ast"; +import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; +import path from "path"; + +export class StaticContextService { + private readonly ide: IDE; + + constructor(ide: IDE) { + this.ide = ide; + } + + public async getContext( + helper: HelperVars + ): Promise { + // Get the three contexts holeContext, relevantTypes, relevantHeaders. + const holeContext = await this.getHoleContext(helper.filepath, helper.pos); + + const relevantTypes = await this.extractRelevantTypes( + holeContext.fullHoverResult, + holeContext.functionName, + holeContext.range.start.line, + new Map(), + holeContext.source, + new Map(), + ); + + let repo: string[] = []; + if (this.language === "typescript") { + repo = getAllTSFiles(this.repoPath); + } else if (this.language === "ocaml") { + repo = getAllOCamlFiles(this.repoPath); + } + + const relevantHeaders = await this.extractRelevantHeaders( + repo, + relevantTypes, + holeContext.functionTypeSpan, + holeContext.functionName, + this.repoPath + ); + + const relevantTypesToReturn: Map = new Map(); + relevantTypes.forEach(({ typeSpan: v, sourceFile: src }, _) => { + if (relevantTypesToReturn.has(src)) { + const updated = relevantTypesToReturn.get(src)!; + updated.push(v); + relevantTypesToReturn.set(src, updated); + } else { + relevantTypesToReturn.set(src, [v]); + } + }) + + + const relevantHeadersToReturn: Map = new Map(); + relevantHeaders.forEach(({ typeSpan: v, sourceFile: src }) => { + if (relevantHeadersToReturn.has(src)) { + const updated = relevantHeadersToReturn.get(src)!; + if (!updated.includes(v)) { + updated.push(v); + } + relevantHeadersToReturn.set(src, updated); + } else { + relevantHeadersToReturn.set(src, [v]); + } + }) + + return { + holeType: "" + relevantTypes: "" + relevantHeaders: "" + }; + } + + private async getHoleContext( + sketchFilePath: string, + cursorPosition: Position + ): Promise { + // We need to inject the hole @ to trigger a treesitter error node. + const sketchFileContent = await fs.readFile(sketchFilePath, "utf8"); + const injectedContent = this.insertAtPosition( + sketchFileContent, + cursorPosition, + "@;" + ); + + // The hole's position is cursorPosition. + + // Use treesitter to parse. + const ast = await getAst(sketchFilePath, injectedContent); + if (!ast) { + throw new Error("failed to get ast"); + } + const language = getFullLanguageName(sketchFilePath); + const query = await getQueryForFile( + sketchFilePath, + path.join(`./queries/hole-queries/${language}.scm`) + ); + if (!query) { + throw new Error( + `failed to get query for file ${sketchFilePath} and language ${language}` + ); + } + + const captures = query.captures(ast.rootNode); + const res: HoleContext = { + fullHoverResult: "", + functionName: "", + functionTypeSpan: "", + range: { + start: { line: 0, character: 0 }, + end: { line: 0, character: 52 }, + }, + source: `file://${sketchFilePath}`, + }; + for (const c of captures) { + const { name, node } = c; + // console.log(`${name} →`, node.text, node.startPosition, node.endPosition); + + switch (name) { + case "function.decl": { + res.fullHoverResult = node.text; + } + case "function.name": { + res.functionName = node.text; + } + case "function.type": { + res.functionTypeSpan = node.text; + res.range = { + start: { + line: node.startPosition.row, + character: node.startPosition.column, + }, + end: { + line: node.endPosition.row, + character: node.endPosition.column, + }, + }; + } + } + } + + return res; + } + + private async extractRelevantTypes(): Promise { + + } + + private async extractRelevantHeaders(): Promise { + + } + + + private insertAtPosition = ( + contents: string, + cursorPosition: { line: number, character: number }, + insertText: string + ): string => { + const lines = contents.split(/\r?\n/); // Handle both LF and CRLF line endings + const { line, character } = cursorPosition; + + if (line < 0 || line >= lines.length) { + throw new Error("Invalid line number"); + } + + const targetLine = lines[line]; + if (character < 0 || character > targetLine.length) { + throw new Error("Invalid character index"); + } + + // Insert the text + lines[line] = targetLine.slice(0, character) + insertText + targetLine.slice(character); + + return lines.join("\n"); // Reconstruct the file + } +} diff --git a/core/autocomplete/context/static-context/queries/hole-queries/typescript.scm b/core/autocomplete/context/static-context/queries/hole-queries/typescript.scm new file mode 100644 index 000000000..e69122b07 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/hole-queries/typescript.scm @@ -0,0 +1,36 @@ +;; Capture the variable/function name +(variable_declarator + name: (identifier) @function.name + type: (type_annotation + (function_type) @function.type)) + +;; Capture the full parameter list +(function_type + parameters: (formal_parameters) @function.params) + +;; Capture the type identifiers used in the parameters +(formal_parameters + (required_parameter + type: (type_annotation + (type_identifier) @param.type)) + (required_parameter + type: (type_annotation + (type_identifier) @param.type))) + +;; Capture the return type of the function +(function_type + return_type: (type_identifier) @return.type) + +;; Capture any parse errors (e.g., the `??`) +(ERROR) @error.node + +;; Capture the entire function declaration line +(lexical_declaration) @function.decl + +;; Matches import declarations like: import { A, B } from "module"; +(import_statement + (import_clause + (named_imports + (import_specifier + name: (identifier) @import.name))) + source: (string) @import.source) diff --git a/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts b/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts new file mode 100644 index 000000000..b0b4ae8ab --- /dev/null +++ b/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts @@ -0,0 +1,36 @@ +export const TYPESCRIPT_HOLE_QUERY = `;; Capture the variable/function name +(variable_declarator + name: (identifier) @function.name + type: (type_annotation + (function_type) @function.type)) + +;; Capture the full parameter list +(function_type + parameters: (formal_parameters) @function.params) + +;; Capture the type identifiers used in the parameters +(formal_parameters + (required_parameter + type: (type_annotation + (type_identifier) @param.type)) + (required_parameter + type: (type_annotation + (type_identifier) @param.type))) + +;; Capture the return type of the function +(function_type + return_type: (type_identifier) @return.type) + +;; Capture any parse errors (e.g., the '?? ') +(ERROR) @error.node + +;; Capture the entire function declaration line +(lexical_declaration) @function.decl + +;; Matches import declarations like: import { A, B } from "module"; +(import_statement + (import_clause + (named_imports + (import_specifier + name: (identifier) @import.name))) + source: (string) @import.source)`; diff --git a/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm b/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm new file mode 100644 index 000000000..02b0bda77 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm @@ -0,0 +1,22 @@ +;; Match top-level `var`, `let`, or `const` declarations +(lexical_declaration + (variable_declarator + name: (identifier) @top.var.name + type: (type_annotation + (_) @top.var.type))) @top.var.decl + +(variable_declaration + (variable_declarator + name: (identifier) @top.var.name + type: (type_annotation + (_) @top.var.type))) @top.var.decl + +;; Match function declarations +(function_declaration + name: (identifier) @top.fn.name + parameters: (formal_parameters + (required_parameter + pattern: (identifier) @top.fn.param.name + type: (type_annotation (_) @top.fn.param.type)))* + + return_type: (type_annotation (_) @top.fn.type)?) @top.fn.decl diff --git a/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts b/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts new file mode 100644 index 000000000..bd0213af7 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts @@ -0,0 +1,22 @@ +export const TYPESCRIPT_GET_TOPLEVEL_HEADERS = `;; Match top-level 'var', 'let', or 'const' declarations +(lexical_declaration + (variable_declarator + name: (identifier) @top.var.name + type: (type_annotation + (_) @top.var.type))) @top.var.decl + +(variable_declaration + (variable_declarator + name: (identifier) @top.var.name + type: (type_annotation + (_) @top.var.type))) @top.var.decl + +;; Match function declarations +(function_declaration + name: (identifier) @top.fn.name + parameters: (formal_parameters + (required_parameter + pattern: (identifier) @top.fn.param.name + type: (type_annotation (_) @top.fn.param.type)))* + + return_type: (type_annotation (_) @top.fn.type)?) @top.fn.decl` diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm new file mode 100644 index 000000000..b5051cb77 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm @@ -0,0 +1,10 @@ +;; Capture the type alias name (left-hand side) +; (type_alias_declaration +; name: (type_identifier) @type.name) + +;; Capture all identifiers on the right-hand side (value), recursively +; (type_alias_declaration +; value: (_) @type.value) + +;; Match all identifiers inside the type value — deeply nested +(type_identifier) @type.identifier diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts new file mode 100644 index 000000000..6e76a0a78 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts @@ -0,0 +1,10 @@ +export const TYPESCRIPT_EXTRACT_IDENTIFIERS = `;; Capture the type alias name (left-hand side) +; (type_alias_declaration +; name: (type_identifier) @type.name) + +;; Capture all identifiers on the right-hand side (value), recursively +; (type_alias_declaration +; value: (_) @type.value) + +;; Match all identifiers inside the type value — deeply nested +(type_identifier) @type.identifier`; diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm new file mode 100644 index 000000000..b26180e05 --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm @@ -0,0 +1,11 @@ +(type_alias_declaration + name: (type_identifier) @type.identifier + value: (_) @type.value) + +(interface_declaration + name: (type_identifier) @type.identifier + body: (_) @type.value) + +(enum_declaration + name: (type_identifier) @type.identifier + body: (_) @type.value) diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts new file mode 100644 index 000000000..4e1eabd7f --- /dev/null +++ b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts @@ -0,0 +1,11 @@ +export const TYPESCRIPT_FIND_TYPEDECL_GIVEN_TYPEIDENTIFIER = `(type_alias_declaration + name: (type_identifier) @type.identifier + value: (_) @type.value) + +(interface_declaration + name: (type_identifier) @type.identifier + body: (_) @type.value) + +(enum_declaration + name: (type_identifier) @type.identifier + body: (_) @type.value)`; diff --git a/core/autocomplete/context/static-context/types.ts b/core/autocomplete/context/static-context/types.ts new file mode 100644 index 000000000..7ddefda97 --- /dev/null +++ b/core/autocomplete/context/static-context/types.ts @@ -0,0 +1,23 @@ +import { Tree } from "web-tree-sitter"; +import { Range } from "../../.."; + +interface TypeSpanAndSourceFile { + typeSpan: string, + sourceFile: string, +} + +interface TypeSpanAndSourceFileAndAst extends TypeSpanAndSourceFile { + ast: Tree +} + +export interface HoleContext { + fullHoverResult: string; + functionName: string; + functionTypeSpan: string; + range: Range; + source: string; +} + +export type RelevantTypes = Map; +export type RelevantHeaders = Set; + From be46653d1efbfb00bb2fd36da76d4b9d24e6718a Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 15:37:51 -0700 Subject: [PATCH 02/31] pull in static context --- .../context/ContextRetrievalService.ts | 10 ++++++++++ core/autocomplete/snippets/getAllSnippets.ts | 3 +++ core/autocomplete/snippets/types.ts | 14 +++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/autocomplete/context/ContextRetrievalService.ts b/core/autocomplete/context/ContextRetrievalService.ts index 72e061fed..c21473d65 100644 --- a/core/autocomplete/context/ContextRetrievalService.ts +++ b/core/autocomplete/context/ContextRetrievalService.ts @@ -2,16 +2,19 @@ import { IDE } from "../.."; import { AutocompleteCodeSnippet, AutocompleteSnippetType, + AutocompleteStaticSnippet, } from "../snippets/types"; import { HelperVars } from "../util/HelperVars"; import { ImportDefinitionsService } from "./ImportDefinitionsService"; import { getSymbolsForSnippet } from "./ranking"; import { RootPathContextService } from "./root-path-context/RootPathContextService"; +import { StaticContextService } from "./static-context/StaticContextService"; export class ContextRetrievalService { private importDefinitionsService: ImportDefinitionsService; private rootPathContextService: RootPathContextService; + private staticContextService: StaticContextService; constructor(private readonly ide: IDE) { this.importDefinitionsService = new ImportDefinitionsService(this.ide); @@ -19,6 +22,7 @@ export class ContextRetrievalService { this.importDefinitionsService, this.ide, ); + this.staticContextService = new StaticContextService(this.ide); } public async getSnippetsFromImportDefinitions( @@ -70,4 +74,10 @@ export class ContextRetrievalService { helper.treePath, ); } + + public async getStaticContextSnippets( + helper: HelperVars + ): Promise { + return this.staticContextService.getContext(helper); + } } diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index eaf287587..3db2c2542 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -1,3 +1,4 @@ +import { context } from "esbuild"; import { IDE } from "../../index"; import { findUriInDirs } from "../../util/uri"; import { ContextRetrievalService } from "../context/ContextRetrievalService"; @@ -123,6 +124,7 @@ export const getAllSnippets = async ({ ideSnippets, diffSnippets, clipboardSnippets, + staticSnippets ] = await Promise.all([ racePromise(contextRetrievalService.getRootPathSnippets(helper)), racePromise( @@ -133,6 +135,7 @@ export const getAllSnippets = async ({ : [], [], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882, racePromise(getClipboardSnippets(ide)), + racePromise(contextRetrievalService.getStaticContextSnippets(helper)) ]); return { diff --git a/core/autocomplete/snippets/types.ts b/core/autocomplete/snippets/types.ts index e43b59862..3c2cddcb6 100644 --- a/core/autocomplete/snippets/types.ts +++ b/core/autocomplete/snippets/types.ts @@ -23,7 +23,19 @@ export interface AutocompleteClipboardSnippet extends BaseAutocompleteSnippet { copiedAt: string; } +type Filepath = string; +type RelevantType = string; +type RelevantHeader = string; + +export interface AutocompleteStaticSnippet extends BaseAutocompleteSnippet { + type: AutocompleteSnippetType.Code; + holeType: string, + relevantTypes: Map, + relevantHeaders: Map +} + export type AutocompleteSnippet = | AutocompleteCodeSnippet | AutocompleteDiffSnippet - | AutocompleteClipboardSnippet; + | AutocompleteClipboardSnippet + | AutocompleteStaticSnippet; From a70c0b78417e256787be91665cf36633b4b4a885 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 16:00:33 -0700 Subject: [PATCH 03/31] add treesitter utility functions that are exclusively used for static context retrieval --- .../static-context/tree-sitter-utils.ts | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 core/autocomplete/context/static-context/tree-sitter-utils.ts diff --git a/core/autocomplete/context/static-context/tree-sitter-utils.ts b/core/autocomplete/context/static-context/tree-sitter-utils.ts new file mode 100644 index 000000000..12872e17f --- /dev/null +++ b/core/autocomplete/context/static-context/tree-sitter-utils.ts @@ -0,0 +1,164 @@ +import * as fs from "fs/promises"; +import Parser from "web-tree-sitter"; +import { getAst } from "../../util/ast"; +import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; +import path from "path"; + +export interface TypeDeclarationResult { + name: string; + fullText: string; + startLine: number; + startColumn: number; + endLine: number; + endColumn: number; + kind: string; +} + +export function findEnclosingTypeDeclaration( + sourceCode: string, + cursorLine: number, + cursorColumn: number, + ast: Parser.Tree +): TypeDeclarationResult | null { + const point = { row: cursorLine, column: cursorColumn }; + let node = ast.rootNode.descendantForPosition(point); + + while ( + node && + ![ + "type_alias_declaration", + "interface_declaration", + "enum_declaration", + ].includes(node.type) + ) { + if (!node.parent) return null; + node = node.parent; + } + + if (!node) return null; + + const nameNode = node.childForFieldName("name"); + const name = nameNode?.text ?? ""; + const fullText = sourceCode.slice(node.startIndex, node.endIndex); + + return { + name, + fullText, + startLine: node.startPosition.row, + startColumn: node.startPosition.column, + endLine: node.endPosition.row, + endColumn: node.endPosition.column, + kind: node.type, + }; +} + +export async function extractTopLevelDecls(currentFile: string, givenParser?: Parser) { + const ast = await getAst(currentFile, await fs.readFile(currentFile, "utf8")); + if (!ast) { + throw new Error(`failed to get ast for file ${currentFile}`); + } + let language; + if (givenParser) { + language = givenParser.getLanguage(); + } else { + language = getFullLanguageName(currentFile); + } + + const query = await getQueryForFile( + currentFile, + path.join( + __dirname, + "queries", + "relevant-headers-queries", + `${language}-get-toplevel-headers.scm` + ) + ); + if (!query) { + throw new Error( + `failed to get query for file ${currentFile} and language ${language}` + ); + } + return query.matches(ast.rootNode); +} + +export async function extractTopLevelDeclsWithFormatting(currentFile: string, givenParser?: Parser) { + const ast = await getAst(currentFile, await fs.readFile(currentFile, "utf8")); + if (!ast) { + throw new Error(`failed to get ast for file ${currentFile}`); + } + let language; + if (givenParser) { + language = givenParser.getLanguage(); + } else { + language = getFullLanguageName(currentFile); + } + + const query = await getQueryForFile( + currentFile, + path.join( + __dirname, + "queries", + "relevant-headers-queries", + `${language}-get-toplevel-headers.scm` + ) + ); + if (!query) { + throw new Error( + `failed to get query for file ${currentFile} and language ${language}` + ); + } + const matches = query.matches(ast.rootNode); + + const results = []; + + for (const match of matches) { + const item: { + declaration: string; + nodeType: string; + name: string; + declaredType: string; + returnType?: string; + } = { + declaration: "", + nodeType: "", + name: "", + declaredType: "", + }; + + for (const { name, node } of match.captures) { + if (name === "top.var.decl") { + item.nodeType = "variable"; + item.declaration = node.text; + + // Attempt to get the declared type (e.g., const x: string = ...) + const typeNode = node.descendantsOfType("type_annotation")[0]; + if (typeNode) { + item.declaredType = typeNode.text.replace(/^:\s*/, ""); + } + } else if (name === "top.var.name" || name === "top.fn.name") { + item.name = node.text; + } else if (name === "top.fn.decl") { + item.nodeType = "function"; + item.declaration = node.text; + + // Get the return type (e.g., function foo(): string) + const returnTypeNode = node.childForFieldName("return_type"); + if (returnTypeNode) { + item.returnType = returnTypeNode.text.replace(/^:\s*/, ""); + } + + // Get declaredType if needed (TypeScript style) + const nameNode = node.childForFieldName("name"); + if (nameNode && nameNode.nextSibling?.type === "type_annotation") { + item.declaredType = nameNode.nextSibling.text.replace(/^:\s*/, ""); + } + } + } + + if (item.name && item.declaration) { + results.push(item); + } + } + + return results; +} From e4b412acfeda3aac0e4683b1b308a2d07e91f009 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 16:01:00 -0700 Subject: [PATCH 04/31] export types --- core/autocomplete/context/static-context/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/context/static-context/types.ts b/core/autocomplete/context/static-context/types.ts index 7ddefda97..03f1f839d 100644 --- a/core/autocomplete/context/static-context/types.ts +++ b/core/autocomplete/context/static-context/types.ts @@ -1,12 +1,12 @@ import { Tree } from "web-tree-sitter"; import { Range } from "../../.."; -interface TypeSpanAndSourceFile { +export interface TypeSpanAndSourceFile { typeSpan: string, sourceFile: string, } -interface TypeSpanAndSourceFileAndAst extends TypeSpanAndSourceFile { +export interface TypeSpanAndSourceFileAndAst extends TypeSpanAndSourceFile { ast: Tree } From fed6ba1591d6608dfb93a643d251cfaca356fc4d Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 16:04:46 -0700 Subject: [PATCH 05/31] add gotoTypeDefinition method --- core/index.d.ts | 47 +++++++++++++++--------------- extensions/vscode/src/VsCodeIde.ts | 11 +++++++ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index eb0de41d5..470b0eed9 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -49,13 +49,13 @@ export interface IndexingProgressUpdate { desc: string; shouldClearIndexes?: boolean; status: - | "loading" - | "indexing" - | "done" - | "failed" - | "paused" - | "disabled" - | "cancelled"; + | "loading" + | "indexing" + | "done" + | "failed" + | "paused" + | "disabled" + | "cancelled"; debugInfo?: string; } @@ -91,7 +91,7 @@ type RequiredLLMOptions = export interface ILLM extends Omit, - Required> { + Required> { get providerName(): string; get underlyingProviderName(): string; @@ -773,10 +773,10 @@ export interface IDE { getCurrentFile(): Promise< | undefined | { - isUntitled: boolean; - path: string; - contents: string; - } + isUntitled: boolean; + path: string; + contents: string; + } >; getPinnedFiles(): Promise; @@ -814,6 +814,7 @@ export interface IDE { // LSP gotoDefinition(location: Location): Promise; + gotoTypeDefinition(location: Location): Promise; // Callbacks onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void; @@ -955,11 +956,11 @@ export interface CustomCommand { export interface Prediction { type: "content"; content: - | string - | { - type: "text"; - text: string; - }[]; + | string + | { + type: "text"; + text: string; + }[]; } export interface ToolExtras { @@ -1455,9 +1456,9 @@ export interface Config { embeddingsProvider?: EmbeddingsProviderDescription | ILLM; /** The model that Continue will use for tab autocompletions. */ tabAutocompleteModel?: - | CustomLLM - | JSONModelDescription - | (CustomLLM | JSONModelDescription)[]; + | CustomLLM + | JSONModelDescription + | (CustomLLM | JSONModelDescription)[]; /** Options for tab autocomplete */ tabAutocompleteOptions?: Partial; /** UI styles customization */ @@ -1551,9 +1552,9 @@ export type PackageDetailsSuccess = PackageDetails & { export type PackageDocsResult = { packageInfo: ParsedPackageInfo; } & ( - | { error: string; details?: never } - | { details: PackageDetailsSuccess; error?: never } -); + | { error: string; details?: never } + | { details: PackageDetailsSuccess; error?: never } + ); export interface TerminalOptions { reuseTerminal?: boolean; diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 5ca51d183..a9ea5d9c6 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -88,6 +88,17 @@ class VsCodeIde implements IDE { return result; } + async gotoTypeDefinition(location: Location): Promise { + const result = await executeGotoProvider({ + uri: vscode.Uri.parse(location.filepath), + line: location.position.line, + character: location.position.character, + name: "vscode.executeTypeDefinitionProvider", + }); + + return result; + } + onDidChangeActiveTextEditor(callback: (uri: string) => void): void { vscode.window.onDidChangeActiveTextEditor((editor) => { if (editor) { From 1717fca23193b56e42e748218a10003e95b453b8 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 16:05:01 -0700 Subject: [PATCH 06/31] add method to extract relevant types --- .../static-context/StaticContextService.ts | 126 +++++++++++++++++- 1 file changed, 123 insertions(+), 3 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index eb005d0cb..465be3456 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -2,10 +2,11 @@ import * as fs from "fs/promises"; import { IDE, Position } from "../../.."; import { AutocompleteCodeSnippet, AutocompleteStaticSnippet } from "../../snippets/types"; import { HelperVars } from "../../util/HelperVars"; -import { HoleContext, RelevantHeaders, RelevantTypes } from "./types"; +import { HoleContext, RelevantHeaders, RelevantTypes, TypeSpanAndSourceFileAndAst } from "./types"; import { getAst } from "../../util/ast"; import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; import path from "path"; +import { findEnclosingTypeDeclaration } from "./tree-sitter-utils"; export class StaticContextService { private readonly ide: IDE; @@ -24,7 +25,6 @@ export class StaticContextService { holeContext.fullHoverResult, holeContext.functionName, holeContext.range.start.line, - new Map(), holeContext.source, new Map(), ); @@ -147,10 +147,130 @@ export class StaticContextService { return res; } - private async extractRelevantTypes(): Promise { + private async extractRelevantTypes( + declText: string, + typeName: string, + startLine: number, + currentFile: string, + foundContents: Map, // uri -> contents + ): Promise { + const foundSoFar = new Map(); // identifier -> [full hover result, source] + await this.extractRelevantTypesHelper( + declText, + typeName, + startLine, + foundSoFar, + currentFile, + foundContents, + ); + + return foundSoFar; } + private async extractRelevantTypesHelper( + declText: string, + typeName: string, + startLine: number, + foundSoFar: Map, // identifier -> [full hover result, source] + currentFile: string, + foundContents: Map, // uri -> contents + ) { + if (!foundSoFar.has(typeName)) { + const ast = await getAst(currentFile, declText); + if (!ast) { + throw new Error(`failed to get ast for file ${currentFile}`); + } + foundSoFar.set(typeName, { + typeSpan: declText, + sourceFile: currentFile.slice(7), + ast: ast, + }); + + const language = getFullLanguageName(currentFile); + const query = await getQueryForFile( + currentFile, + path.join( + __dirname, + "queries", + "relevant-types-queries", + `${language}-extract-identifiers.scm` + ) + ); + if (!query) { + throw new Error( + `failed to get query for file ${currentFile} and language ${language}` + ); + } + + const identifiers = query.captures(ast.rootNode); + + for (const { name, node } of identifiers) { + if (!foundSoFar.has(node.text)) { + try { + const typeDefinitionResult = + await this.ide.gotoTypeDefinition({ + filepath: currentFile, + position: { + character: node.startPosition.column, + line: startLine + node.startPosition.row, + }, + }); + + if (typeDefinitionResult.length != 0) { + const tdLocation = typeDefinitionResult[0]; + + let content = ""; + + if (foundContents.has(tdLocation.filepath)) { + content = foundContents.get(tdLocation.filepath)!; + } else { + content = await fs.readFile(tdLocation.filepath, "utf8"); + foundContents.set(tdLocation.filepath, content); + } + + const ast = await getAst(tdLocation.filepath, content); + if (!ast) { + throw new Error( + `failed to get ast for file ${tdLocation.filepath}` + ); + } + const decl = findEnclosingTypeDeclaration( + content, + tdLocation.range.start.line, + tdLocation.range.start.character, + ast + ); + if (!decl) { + // throw new Error(`failed to get decl for file ${tdLocation.uri}`); + console.error(`failed to get decl for file ${tdLocation.filepath}`); + } + + if (decl) { + await this.extractRelevantTypesHelper( + decl.fullText, + node.text, + tdLocation.range.start.line, + foundSoFar, + tdLocation.filepath, + foundContents, + ); + } else { + // console.log("decl not found"); + } + } else { + // console.log("td not found"); + } + } catch (err) { + console.log(err); + } + } else { + } + } + } + } + + private async extractRelevantHeaders(): Promise { } From 4e97c922d5d2968b8f9513865c346af77df705a7 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:54:19 -0700 Subject: [PATCH 07/31] move queries to extensions/vscode --- .../queries/hole-queries/typescript.ts | 36 ------------------- .../typescript-get-toplevel-headers.ts | 22 ------------ .../typescript-extract-identifiers.ts | 10 ------ ...ript-find-typedecl-given-typeidentifier.ts | 11 ------ .../hole-queries/typescript.scm | 0 .../typescript-get-toplevel-headers.scm | 0 .../typescript-extract-identifiers.scm | 0 ...ipt-find-typedecl-given-typeidentifier.scm | 0 8 files changed, 79 deletions(-) delete mode 100644 core/autocomplete/context/static-context/queries/hole-queries/typescript.ts delete mode 100644 core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts delete mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts delete mode 100644 core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts rename {core/autocomplete/context/static-context/queries => extensions/vscode/tree-sitter/static-context-queries}/hole-queries/typescript.scm (100%) rename {core/autocomplete/context/static-context/queries => extensions/vscode/tree-sitter/static-context-queries}/relevant-headers-queries/typescript-get-toplevel-headers.scm (100%) rename {core/autocomplete/context/static-context/queries => extensions/vscode/tree-sitter/static-context-queries}/relevant-types-queries/typescript-extract-identifiers.scm (100%) rename {core/autocomplete/context/static-context/queries => extensions/vscode/tree-sitter/static-context-queries}/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm (100%) diff --git a/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts b/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts deleted file mode 100644 index b0b4ae8ab..000000000 --- a/core/autocomplete/context/static-context/queries/hole-queries/typescript.ts +++ /dev/null @@ -1,36 +0,0 @@ -export const TYPESCRIPT_HOLE_QUERY = `;; Capture the variable/function name -(variable_declarator - name: (identifier) @function.name - type: (type_annotation - (function_type) @function.type)) - -;; Capture the full parameter list -(function_type - parameters: (formal_parameters) @function.params) - -;; Capture the type identifiers used in the parameters -(formal_parameters - (required_parameter - type: (type_annotation - (type_identifier) @param.type)) - (required_parameter - type: (type_annotation - (type_identifier) @param.type))) - -;; Capture the return type of the function -(function_type - return_type: (type_identifier) @return.type) - -;; Capture any parse errors (e.g., the '?? ') -(ERROR) @error.node - -;; Capture the entire function declaration line -(lexical_declaration) @function.decl - -;; Matches import declarations like: import { A, B } from "module"; -(import_statement - (import_clause - (named_imports - (import_specifier - name: (identifier) @import.name))) - source: (string) @import.source)`; diff --git a/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts b/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts deleted file mode 100644 index bd0213af7..000000000 --- a/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.ts +++ /dev/null @@ -1,22 +0,0 @@ -export const TYPESCRIPT_GET_TOPLEVEL_HEADERS = `;; Match top-level 'var', 'let', or 'const' declarations -(lexical_declaration - (variable_declarator - name: (identifier) @top.var.name - type: (type_annotation - (_) @top.var.type))) @top.var.decl - -(variable_declaration - (variable_declarator - name: (identifier) @top.var.name - type: (type_annotation - (_) @top.var.type))) @top.var.decl - -;; Match function declarations -(function_declaration - name: (identifier) @top.fn.name - parameters: (formal_parameters - (required_parameter - pattern: (identifier) @top.fn.param.name - type: (type_annotation (_) @top.fn.param.type)))* - - return_type: (type_annotation (_) @top.fn.type)?) @top.fn.decl` diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts deleted file mode 100644 index 6e76a0a78..000000000 --- a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const TYPESCRIPT_EXTRACT_IDENTIFIERS = `;; Capture the type alias name (left-hand side) -; (type_alias_declaration -; name: (type_identifier) @type.name) - -;; Capture all identifiers on the right-hand side (value), recursively -; (type_alias_declaration -; value: (_) @type.value) - -;; Match all identifiers inside the type value — deeply nested -(type_identifier) @type.identifier`; diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts b/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts deleted file mode 100644 index 4e1eabd7f..000000000 --- a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const TYPESCRIPT_FIND_TYPEDECL_GIVEN_TYPEIDENTIFIER = `(type_alias_declaration - name: (type_identifier) @type.identifier - value: (_) @type.value) - -(interface_declaration - name: (type_identifier) @type.identifier - body: (_) @type.value) - -(enum_declaration - name: (type_identifier) @type.identifier - body: (_) @type.value)`; diff --git a/core/autocomplete/context/static-context/queries/hole-queries/typescript.scm b/extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm similarity index 100% rename from core/autocomplete/context/static-context/queries/hole-queries/typescript.scm rename to extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm diff --git a/core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm b/extensions/vscode/tree-sitter/static-context-queries/relevant-headers-queries/typescript-get-toplevel-headers.scm similarity index 100% rename from core/autocomplete/context/static-context/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm rename to extensions/vscode/tree-sitter/static-context-queries/relevant-headers-queries/typescript-get-toplevel-headers.scm diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm b/extensions/vscode/tree-sitter/static-context-queries/relevant-types-queries/typescript-extract-identifiers.scm similarity index 100% rename from core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-extract-identifiers.scm rename to extensions/vscode/tree-sitter/static-context-queries/relevant-types-queries/typescript-extract-identifiers.scm diff --git a/core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm b/extensions/vscode/tree-sitter/static-context-queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm similarity index 100% rename from core/autocomplete/context/static-context/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm rename to extensions/vscode/tree-sitter/static-context-queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm From 97788f2b9db43b906147fdbd9f251eae57cdab43 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:54:53 -0700 Subject: [PATCH 08/31] fix path to query --- .../static-context/tree-sitter-utils.ts | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/core/autocomplete/context/static-context/tree-sitter-utils.ts b/core/autocomplete/context/static-context/tree-sitter-utils.ts index 12872e17f..c7a9a20a3 100644 --- a/core/autocomplete/context/static-context/tree-sitter-utils.ts +++ b/core/autocomplete/context/static-context/tree-sitter-utils.ts @@ -66,12 +66,7 @@ export async function extractTopLevelDecls(currentFile: string, givenParser?: Pa const query = await getQueryForFile( currentFile, - path.join( - __dirname, - "queries", - "relevant-headers-queries", - `${language}-get-toplevel-headers.scm` - ) + `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm` ); if (!query) { throw new Error( @@ -95,12 +90,7 @@ export async function extractTopLevelDeclsWithFormatting(currentFile: string, gi const query = await getQueryForFile( currentFile, - path.join( - __dirname, - "queries", - "relevant-headers-queries", - `${language}-get-toplevel-headers.scm` - ) + `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm` ); if (!query) { throw new Error( @@ -162,3 +152,58 @@ export async function extractTopLevelDeclsWithFormatting(currentFile: string, gi return results; } + +export function extractFunctionTypeFromDecl(match: Parser.QueryMatch): string { + let paramsNode: Parser.SyntaxNode | undefined = undefined; + let returnNode: Parser.SyntaxNode | undefined = undefined; + + for (const capture of match.captures) { + if (capture.name === "top.fn.param.type") { + paramsNode = capture.node; + } else if (capture.name === "top.fn.type") { + returnNode = capture.node; + } + } + + if (!paramsNode) { + console.error(`extractFunctionTypeFromDecl: ${paramsNode} not found`); + throw new Error(`extractFunctionTypeFromDecl: ${paramsNode} not found`); + } + + if (!returnNode) { + console.error(`extractFunctionTypeFromDecl: ${returnNode} not found`); + throw new Error(`extractFunctionTypeFromDecl: ${returnNode} not found`); + } + + return `(${paramsNode!.text}) => ${returnNode!.text}`; +} + +export function unwrapToBaseType(node: Parser.SyntaxNode): Parser.SyntaxNode { + if ( + [ + "function_type", + "tuple_type", + "type_identifier", + "predefined_type", + ].includes(node.type) + ) { + return node; + } + + for (const child of node.namedChildren) { + const unwrapped = unwrapToBaseType(child!); + if ( + unwrapped !== child || + [ + "function_type", + "tuple_type", + "type_identifier", + "predefined_type", + ].includes(unwrapped.type) + ) { + return unwrapped; + } + } + + return node; +} From 408038275dbfd27adf9692469e095ff5e8d27d22 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:55:28 -0700 Subject: [PATCH 09/31] update types --- core/autocomplete/templating/filtering.ts | 17 +++++++++++++---- core/autocomplete/templating/formatting.ts | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/autocomplete/templating/filtering.ts b/core/autocomplete/templating/filtering.ts index 7f69398c6..e3eb6f1fe 100644 --- a/core/autocomplete/templating/filtering.ts +++ b/core/autocomplete/templating/filtering.ts @@ -3,6 +3,7 @@ import { SnippetPayload } from "../snippets"; import { AutocompleteCodeSnippet, AutocompleteSnippet, + AutocompleteStaticSnippet, } from "../snippets/types"; import { HelperVars } from "../util/HelperVars"; @@ -30,9 +31,9 @@ const shuffleArray = (array: T[]): T[] => { }; function filterSnippetsAlreadyInCaretWindow( - snippets: AutocompleteCodeSnippet[], + snippets: (AutocompleteCodeSnippet | AutocompleteStaticSnippet)[], caretWindow: string, -): AutocompleteCodeSnippet[] { +): (AutocompleteCodeSnippet | AutocompleteStaticSnippet)[] { return snippets.filter( (s) => s.content.trim() !== "" && !caretWindow.includes(s.content.trim()), ); @@ -49,7 +50,11 @@ export const getSnippets = ( diff: payload.diffSnippets, base: shuffleArray( filterSnippetsAlreadyInCaretWindow( - [...payload.rootPathSnippets, ...payload.importDefinitionSnippets], + [ + ...payload.rootPathSnippets, + ...payload.importDefinitionSnippets, + ...payload.staticSnippet, + ], helper.prunedCaretWindow, ), ), @@ -98,7 +103,11 @@ export const getSnippets = ( defaultPriority: 99, // make sure it's the last one to be processed, but still possible to override snippets: shuffleArray( filterSnippetsAlreadyInCaretWindow( - [...payload.rootPathSnippets, ...payload.importDefinitionSnippets], + [ + ...payload.rootPathSnippets, + ...payload.importDefinitionSnippets, + ...payload.staticSnippet, + ], helper.prunedCaretWindow, ), ), diff --git a/core/autocomplete/templating/formatting.ts b/core/autocomplete/templating/formatting.ts index 2a91ad438..583873c2d 100644 --- a/core/autocomplete/templating/formatting.ts +++ b/core/autocomplete/templating/formatting.ts @@ -5,6 +5,7 @@ import { AutocompleteDiffSnippet, AutocompleteSnippet, AutocompleteSnippetType, + AutocompleteStaticSnippet, } from "../snippets/types"; import { HelperVars } from "../util/HelperVars"; @@ -51,6 +52,12 @@ const formatDiffSnippet = ( return snippet; }; +const formatStaticSnippet = ( + snippet: AutocompleteStaticSnippet, +): AutocompleteStaticSnippet => { + return snippet; +}; + const commentifySnippet = ( helper: HelperVars, snippet: AutocompleteSnippet, @@ -81,6 +88,8 @@ export const formatSnippets = ( return formatDiffSnippet(snippet); case AutocompleteSnippetType.Clipboard: return formatClipboardSnippet(snippet, workspaceDirs); + case AutocompleteSnippetType.Static: + return formatStaticSnippet(snippet); } }) .map((item) => { From 4e9690e058b9dfd275a92bafd46483addca83a25 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:55:42 -0700 Subject: [PATCH 10/31] move types from snippets to static --- core/autocomplete/context/static-context/types.ts | 15 ++++++++++++--- core/autocomplete/snippets/types.ts | 10 ++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/autocomplete/context/static-context/types.ts b/core/autocomplete/context/static-context/types.ts index 03f1f839d..2400c2a7a 100644 --- a/core/autocomplete/context/static-context/types.ts +++ b/core/autocomplete/context/static-context/types.ts @@ -2,12 +2,12 @@ import { Tree } from "web-tree-sitter"; import { Range } from "../../.."; export interface TypeSpanAndSourceFile { - typeSpan: string, - sourceFile: string, + typeSpan: string; + sourceFile: string; } export interface TypeSpanAndSourceFileAndAst extends TypeSpanAndSourceFile { - ast: Tree + ast: Tree; } export interface HoleContext { @@ -21,3 +21,12 @@ export interface HoleContext { export type RelevantTypes = Map; export type RelevantHeaders = Set; +export type Filepath = string; +export type RelevantType = string; +export type RelevantHeader = string; + +export interface StaticContext { + holeType: string; + relevantTypes: Map; + relevantHeaders: Map; +} diff --git a/core/autocomplete/snippets/types.ts b/core/autocomplete/snippets/types.ts index 3c2cddcb6..c486c0106 100644 --- a/core/autocomplete/snippets/types.ts +++ b/core/autocomplete/snippets/types.ts @@ -2,6 +2,7 @@ export enum AutocompleteSnippetType { Code = "code", Diff = "diff", Clipboard = "clipboard", + Static = "static", } interface BaseAutocompleteSnippet { @@ -23,15 +24,8 @@ export interface AutocompleteClipboardSnippet extends BaseAutocompleteSnippet { copiedAt: string; } -type Filepath = string; -type RelevantType = string; -type RelevantHeader = string; - export interface AutocompleteStaticSnippet extends BaseAutocompleteSnippet { - type: AutocompleteSnippetType.Code; - holeType: string, - relevantTypes: Map, - relevantHeaders: Map + type: AutocompleteSnippetType.Static; } export type AutocompleteSnippet = From a2c1c6312e722ca6673c3815de4f13a002283eb0 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:55:53 -0700 Subject: [PATCH 11/31] conform to interface --- core/autocomplete/context/ContextRetrievalService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/autocomplete/context/ContextRetrievalService.ts b/core/autocomplete/context/ContextRetrievalService.ts index c21473d65..8cf63d8b9 100644 --- a/core/autocomplete/context/ContextRetrievalService.ts +++ b/core/autocomplete/context/ContextRetrievalService.ts @@ -77,7 +77,7 @@ export class ContextRetrievalService { public async getStaticContextSnippets( helper: HelperVars - ): Promise { + ): Promise { return this.staticContextService.getContext(helper); } } From 29f9c726dd306af47ae78b5def6cdb074c0e227a Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 19:56:02 -0700 Subject: [PATCH 12/31] static contextualization works --- .../static-context/StaticContextService.ts | 681 +++++++++++++++--- core/autocomplete/snippets/getAllSnippets.ts | 8 +- 2 files changed, 592 insertions(+), 97 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index 465be3456..4b9b41917 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -1,12 +1,29 @@ import * as fs from "fs/promises"; -import { IDE, Position } from "../../.."; -import { AutocompleteCodeSnippet, AutocompleteStaticSnippet } from "../../snippets/types"; -import { HelperVars } from "../../util/HelperVars"; -import { HoleContext, RelevantHeaders, RelevantTypes, TypeSpanAndSourceFileAndAst } from "./types"; -import { getAst } from "../../util/ast"; -import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; import path from "path"; -import { findEnclosingTypeDeclaration } from "./tree-sitter-utils"; +import Parser from "web-tree-sitter"; +import { IDE, Position } from "../../.."; +import { localPathOrUriToPath } from "../../../util/pathToUri"; +import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; +import { + AutocompleteSnippetType, + AutocompleteStaticSnippet, +} from "../../snippets/types"; +import { getAst } from "../../util/ast"; +import { HelperVars } from "../../util/HelperVars"; +import { + extractFunctionTypeFromDecl, + extractTopLevelDecls, + findEnclosingTypeDeclaration, + unwrapToBaseType, +} from "./tree-sitter-utils"; +import { + HoleContext, + RelevantHeaders, + RelevantTypes, + StaticContext, + TypeSpanAndSourceFile, + TypeSpanAndSourceFileAndAst, +} from "./types"; export class StaticContextService { private readonly ide: IDE; @@ -15,9 +32,58 @@ export class StaticContextService { this.ide = ide; } + public logAutocompleteStaticSnippet( + ctx: StaticContext, + label = "Static Snippet", + ) { + console.log(`=== ${label} ===`); + console.log("Hole Type:", ctx.holeType); + + console.log(`\nRelevant Types (${ctx.relevantTypes.size} files):`); + ctx.relevantTypes.forEach((types, filepath) => { + console.log(` 📁 ${filepath}`); + types.forEach((type) => console.log(` • ${type}`)); + }); + + console.log(`\nRelevant Headers (${ctx.relevantHeaders.size} files):`); + ctx.relevantHeaders.forEach((headers, filepath) => { + console.log(` 📁 ${filepath}`); + headers.forEach((header) => console.log(` • ${header}`)); + }); + } + + public static formatAutocompleteStaticSnippet(ctx: StaticContext): string { + let output = `AutocompleteStaticSnippet:\n`; + output += ` holeType: ${ctx.holeType}\n`; + + output += ` relevantTypes:\n`; + if (ctx.relevantTypes.size === 0) { + output += ` (none)\n`; + } else { + ctx.relevantTypes.forEach((types, filepath) => { + output += ` ${filepath}: [${types.join(", ")}]\n`; + }); + } + + output += ` relevantHeaders:\n`; + if (ctx.relevantHeaders.size === 0) { + output += ` (none)\n`; + } else { + ctx.relevantHeaders.forEach((headers, filepath) => { + output += ` ${filepath}: [${headers.join(", ")}]\n`; + }); + } + + return output; + } + public async getContext( - helper: HelperVars - ): Promise { + helper: HelperVars, + ): Promise { + const start = Date.now(); + const tsFiles = await this.getTypeScriptFilesFromWorkspaces( + helper.workspaceUris, + ); // Get the three contexts holeContext, relevantTypes, relevantHeaders. const holeContext = await this.getHoleContext(helper.filepath, helper.pos); @@ -29,22 +95,23 @@ export class StaticContextService { new Map(), ); - let repo: string[] = []; - if (this.language === "typescript") { - repo = getAllTSFiles(this.repoPath); - } else if (this.language === "ocaml") { - repo = getAllOCamlFiles(this.repoPath); - } + // if (this.language === "typescript") { + // repo = getAllTSFiles(this.repoPath); + // } else if (this.language === "ocaml") { + // repo = getAllOCamlFiles(this.repoPath); + // } + // const relevantHeaders = await this.extractRelevantHeaders( - repo, + tsFiles, relevantTypes, holeContext.functionTypeSpan, - holeContext.functionName, - this.repoPath ); - const relevantTypesToReturn: Map = new Map(); + const relevantTypesToReturn: Map = new Map< + string, + string[] + >(); relevantTypes.forEach(({ typeSpan: v, sourceFile: src }, _) => { if (relevantTypesToReturn.has(src)) { const updated = relevantTypesToReturn.get(src)!; @@ -53,10 +120,12 @@ export class StaticContextService { } else { relevantTypesToReturn.set(src, [v]); } - }) + }); - - const relevantHeadersToReturn: Map = new Map(); + const relevantHeadersToReturn: Map = new Map< + string, + string[] + >(); relevantHeaders.forEach(({ typeSpan: v, sourceFile: src }) => { if (relevantHeadersToReturn.has(src)) { const updated = relevantHeadersToReturn.get(src)!; @@ -67,25 +136,38 @@ export class StaticContextService { } else { relevantHeadersToReturn.set(src, [v]); } - }) + }); - return { - holeType: "" - relevantTypes: "" - relevantHeaders: "" + const ctx = { + holeType: holeContext.functionTypeSpan, + relevantTypes: relevantTypesToReturn, + relevantHeaders: relevantHeadersToReturn, }; + const end = Date.now(); + + this.logAutocompleteStaticSnippet(ctx); + + console.log(end - start); + + return [ + { + type: AutocompleteSnippetType.Static, + content: StaticContextService.formatAutocompleteStaticSnippet(ctx), + }, + ]; } private async getHoleContext( sketchFilePath: string, - cursorPosition: Position + cursorPosition: Position, ): Promise { // We need to inject the hole @ to trigger a treesitter error node. + sketchFilePath = localPathOrUriToPath(sketchFilePath); const sketchFileContent = await fs.readFile(sketchFilePath, "utf8"); const injectedContent = this.insertAtPosition( sketchFileContent, cursorPosition, - "@;" + "@;", ); // The hole's position is cursorPosition. @@ -98,11 +180,11 @@ export class StaticContextService { const language = getFullLanguageName(sketchFilePath); const query = await getQueryForFile( sketchFilePath, - path.join(`./queries/hole-queries/${language}.scm`) + `static-context-queries/hole-queries/${language}.scm`, ); if (!query) { throw new Error( - `failed to get query for file ${sketchFilePath} and language ${language}` + `getHoleContext: failed to get query for file ${sketchFilePath} and language ${language}`, ); } @@ -190,96 +272,425 @@ export class StaticContextService { const language = getFullLanguageName(currentFile); const query = await getQueryForFile( currentFile, - path.join( - __dirname, - "queries", - "relevant-types-queries", - `${language}-extract-identifiers.scm` - ) + `static-context-queries/relevant-types-queries/${language}-extract-identifiers.scm`, ); if (!query) { throw new Error( - `failed to get query for file ${currentFile} and language ${language}` + `failed to get query for file ${currentFile} and language ${language}`, ); } const identifiers = query.captures(ast.rootNode); for (const { name, node } of identifiers) { - if (!foundSoFar.has(node.text)) { - try { - const typeDefinitionResult = - await this.ide.gotoTypeDefinition({ - filepath: currentFile, - position: { - character: node.startPosition.column, - line: startLine + node.startPosition.row, - }, - }); + if (foundSoFar.has(node.text)) continue; - if (typeDefinitionResult.length != 0) { - const tdLocation = typeDefinitionResult[0]; + try { + const typeDefinitionResult = await this.ide.gotoTypeDefinition({ + filepath: currentFile, + position: { + character: node.startPosition.column, + line: startLine + node.startPosition.row, + }, + }); - let content = ""; + if (typeDefinitionResult.length > 0) { + const tdLocation = typeDefinitionResult[0]; - if (foundContents.has(tdLocation.filepath)) { - content = foundContents.get(tdLocation.filepath)!; - } else { - content = await fs.readFile(tdLocation.filepath, "utf8"); - foundContents.set(tdLocation.filepath, content); - } + let content = ""; - const ast = await getAst(tdLocation.filepath, content); - if (!ast) { - throw new Error( - `failed to get ast for file ${tdLocation.filepath}` - ); - } - const decl = findEnclosingTypeDeclaration( - content, - tdLocation.range.start.line, - tdLocation.range.start.character, - ast - ); - if (!decl) { - // throw new Error(`failed to get decl for file ${tdLocation.uri}`); - console.error(`failed to get decl for file ${tdLocation.filepath}`); - } - - if (decl) { - await this.extractRelevantTypesHelper( - decl.fullText, - node.text, - tdLocation.range.start.line, - foundSoFar, - tdLocation.filepath, - foundContents, - ); - } else { - // console.log("decl not found"); - } + if (foundContents.has(tdLocation.filepath)) { + content = foundContents.get(tdLocation.filepath)!; } else { - // console.log("td not found"); + content = await fs.readFile( + localPathOrUriToPath(tdLocation.filepath), + "utf8", + ); + foundContents.set(tdLocation.filepath, content); } - } catch (err) { - console.log(err); + + const ast = await getAst(tdLocation.filepath, content); + if (!ast) { + throw new Error( + `failed to get ast for file ${tdLocation.filepath}`, + ); + } + const decl = findEnclosingTypeDeclaration( + content, + tdLocation.range.start.line, + tdLocation.range.start.character, + ast, + ); + if (!decl) { + // throw new Error(`failed to get decl for file ${tdLocation.uri}`); + console.error( + `failed to get decl for file ${tdLocation.filepath}`, + ); + } + + if (decl) { + await this.extractRelevantTypesHelper( + decl.fullText, + node.text, + tdLocation.range.start.line, + foundSoFar, + tdLocation.filepath, + foundContents, + ); + } else { + // console.log("decl not found"); + } + } else { + // console.log("td not found"); } - } else { + } catch (err) { + console.log(err); } } } } + private async extractRelevantHeaders( + sources: string[], + relevantTypes: Map, + holeType: string, + ): Promise { + const relevantContext = new Set(); + // NOTE: This is necessary because TypeScript sucks. + // There is no way to compare objects by value, + // so sets of objects starts to accumulate tons of duplicates. + const relevantContextMap = new Map(); + const foundNormalForms = new Map(); - private async extractRelevantHeaders(): Promise { + const targetTypes = await this.generateTargetTypes(relevantTypes, holeType); + for (const source of sources) { + const topLevelDecls = await extractTopLevelDecls(source); + for (const tld of topLevelDecls) { + // pattern 0 is let/const, 1 is var, 2 is fun + // if (!seenDecls.has(JSON.stringify()) { + const originalDeclText = + tld.pattern === 2 + ? tld.captures.find((d) => d.name === "top.fn.decl")!.node.text + : tld.captures.find((d) => d.name === "top.var.decl")!.node.text; + + if (tld.pattern === 2) { + // build a type span + // TODO: this fails sometimes with Cannot read properties of undefined (reading 'text') + // most likely due to my scm query and how I'm not attaching param name along with param type + const funcType = extractFunctionTypeFromDecl(tld); + const wrapped = `type __TMP = ${funcType};`; + + const ast = await getAst("file.ts", wrapped); + if (!ast) { + throw new Error(`failed to generate ast for ${wrapped}`); + } + + console.log(ast.rootNode); + const alias = ast.rootNode.namedChild(0); + console.log(alias); + if (!alias || alias.type !== "type_alias_declaration") { + throw new Error( + "extractRelevantHeaders: Failed to parse type alias", + ); + } + + const valueNode = alias.childForFieldName("value"); + if (!valueNode) throw new Error("No type value found"); + + const baseNode = unwrapToBaseType(valueNode); + + await this.extractRelevantHeadersHelper( + originalDeclText, + baseNode, + targetTypes, + relevantTypes, + relevantContext, + relevantContextMap, + foundNormalForms, + source, + ); + } else { + const varTypNode = tld.captures.find( + (d) => d.name === "top.var.type", + )!.node; + await this.extractRelevantHeadersHelper( + originalDeclText, + varTypNode, + targetTypes, + relevantTypes, + relevantContext, + relevantContextMap, + foundNormalForms, + source, + ); + } + } + } + + for (const v of relevantContextMap.values()) { + relevantContext.add(v); + } + + return relevantContext; } + private async extractRelevantHeadersHelper( + originalDeclText: string, + node: Parser.SyntaxNode, + targetTypes: Set, + relevantTypes: Map, + relevantContext: Set, + relevantContextMap: Map, + foundNormalForms: Map, + source: string, + ) { + for (const typ of targetTypes) { + if ( + await this.isTypeEquivalent(node, typ, relevantTypes, foundNormalForms) + ) { + const ctx = { typeSpan: originalDeclText, sourceFile: source }; + relevantContextMap.set(JSON.stringify(ctx), ctx); + } + + if (node.type === "function_type") { + const retTypeNode = node.namedChildren.find( + (c) => c && c.type === "return_type", + ); + if (retTypeNode) { + await this.extractRelevantHeadersHelper( + originalDeclText, + retTypeNode, + targetTypes, + relevantTypes, + relevantContext, + relevantContextMap, + foundNormalForms, + source, + ); + } + } else if (node.type === "tuple_type") { + for (const c of node.namedChildren) { + await this.extractRelevantHeadersHelper( + originalDeclText, + c!, + targetTypes, + relevantTypes, + relevantContext, + relevantContextMap, + foundNormalForms, + source, + ); + } + } + } + } + + private async generateTargetTypes( + relevantTypes: Map, + holeType: string, + ) { + const targetTypes = new Set(); + // const ast = relevantTypes.get(holeIdentifier)!.ast; + const ast = await getAst("file.ts", `type T = ${holeType};`); + if (!ast) { + throw new Error(`failed to generate ast for ${holeType}`); + } + + const alias = ast.rootNode.namedChild(0); + if (!alias || alias.type !== "type_alias_declaration") { + throw new Error("generateTargetTypes: Failed to parse type alias"); + } + + const valueNode = alias.childForFieldName("value"); + if (!valueNode) throw new Error("No type value found"); + + const baseNode = unwrapToBaseType(valueNode); + targetTypes.add(baseNode); + await this.generateTargetTypesHelper( + relevantTypes, + holeType, + targetTypes, + baseNode, + ); + + return targetTypes; + } + + private async generateTargetTypesHelper( + relevantTypes: Map, + currType: string, + targetTypes: Set, + node: Parser.SyntaxNode | null, + ): Promise { + if (!node) return; + + if (node.type === "function_type") { + const returnType = node.childForFieldName("return_type"); + if (returnType) { + targetTypes.add(returnType); + await this.generateTargetTypesHelper( + relevantTypes, + currType, + targetTypes, + returnType, + ); + } + } + + if (node.type === "tuple_type") { + for (const child of node.namedChildren) { + if (child) { + targetTypes.add(child); + await this.generateTargetTypesHelper( + relevantTypes, + currType, + targetTypes, + child, + ); + } + } + } + + if (relevantTypes.has(node.text)) { + // const ast = relevantTypes.get(node.text)!.ast; + const typeSpan = relevantTypes.get(node.text)?.typeSpan; + + // const ast = await getAst("file.ts", `type T = ${typeSpan}`); + const ast = await getAst("file.ts", typeSpan!); + if (!ast) { + throw new Error(`failed to generate ast for ${typeSpan}`); + } + + const alias = ast.rootNode.namedChild(0); + if (!alias || alias.type !== "type_alias_declaration") { + throw new Error( + "generateTargetTypesHelper: Failed to parse type alias", + ); + } + + const valueNode = alias.childForFieldName("value"); + if (!valueNode) throw new Error("No type value found"); + + const baseNode = unwrapToBaseType(valueNode); + await this.generateTargetTypesHelper( + relevantTypes, + currType, + targetTypes, + baseNode, + ); + } + + // if (node.type === "type_identifier" || node.type === "predefined_type") { + // return [node.text]; + // } + + return; + } + + private async isTypeEquivalent( + node: Parser.SyntaxNode, + typ: Parser.SyntaxNode, + relevantTypes: Map, + foundNormalForms: Map, + ): Promise { + if (!node || !typ) { + return false; + } + let normT1 = ""; + let normT2 = ""; + if (foundNormalForms.has(node.text)) { + // console.log("found t1", true) + normT1 = foundNormalForms.get(node.text)!; + } else { + // console.log("not found t1", false) + normT1 = await this.normalize(node, relevantTypes); + foundNormalForms.set(node.text, normT1); + } + if (foundNormalForms.has(typ.text)) { + // console.log("found t2", true) + normT2 = foundNormalForms.get(typ.text)!; + } else { + // console.log("not found t2", false) + normT2 = await this.normalize(typ, relevantTypes); + foundNormalForms.set(typ.text, normT2); + } + // const normT1 = foundNormalForms.has(t1) ? foundNormalForms.get(t1) : this.normalize2(t1, relevantTypes); + // const normT2 = foundNormalForms.has(t2) ? foundNormalForms.get(t2) : this.normalize2(t2, relevantTypes); + // console.log(`normal forms: ${normT1} {}{} ${normT2}`) + return normT1 === normT2; + } + + private async normalize( + node: Parser.SyntaxNode, + relevantTypes: Map, + ): Promise { + if (!node) return ""; + + switch (node.type) { + case "function_type": { + const params = node.child(0); // formal_parameters + const returnType = + node.childForFieldName("type") || node.namedChildren[1]; // function_type → parameters, =>, return + + const paramTypes = + params?.namedChildren + .map((param) => + this.normalize( + param!.childForFieldName("type")! || + param!.namedChildren.at(-1), + relevantTypes, + ), + ) + .join(", ") || ""; + + const ret = this.normalize(returnType!, relevantTypes); + return `(${paramTypes}) => ${ret}`; + } + + case "tuple_type": { + const elements = node.namedChildren.map((c) => + this.normalize(c!, relevantTypes), + ); + return `[${elements.join(", ")}]`; + } + + case "union_type": { + const parts = node.namedChildren.map((c) => + this.normalize(c!, relevantTypes), + ); + return parts.join(" | "); + } + + case "type_identifier": { + const alias = relevantTypes.get(node.text); + if (!alias) return node.text; + + // Parse the alias's type span + const wrapped = `type __TMP = ${alias};`; + const tree = await getAst("file.ts", wrapped); + const valueNode = tree!.rootNode + .descendantsOfType("type_alias_declaration")[0] + ?.childForFieldName("value"); + + return this.normalize(valueNode!, relevantTypes); + } + + case "predefined_type": + case "number": + case "string": + return node.text; + + default: + // Fallback for types like array, etc. + return node.text; + } + } private insertAtPosition = ( contents: string, - cursorPosition: { line: number, character: number }, - insertText: string + cursorPosition: { line: number; character: number }, + insertText: string, ): string => { const lines = contents.split(/\r?\n/); // Handle both LF and CRLF line endings const { line, character } = cursorPosition; @@ -294,8 +705,90 @@ export class StaticContextService { } // Insert the text - lines[line] = targetLine.slice(0, character) + insertText + targetLine.slice(character); + lines[line] = + targetLine.slice(0, character) + insertText + targetLine.slice(character); return lines.join("\n"); // Reconstruct the file + }; + + private async getTypeScriptFilesFromWorkspaces( + workspaceUris: string[], + ): Promise { + const tsExtensions = [".ts"]; + const allTsFiles: string[] = []; + + for (const workspaceUri of workspaceUris) { + try { + // Convert URI to file path + const folderPath = workspaceUri.startsWith("file://") + ? new URL(workspaceUri).pathname + : workspaceUri; + + const tsFiles = await this.scanDirectoryForTypeScriptFiles( + folderPath, + tsExtensions, + ); + allTsFiles.push(...tsFiles); + } catch (error) { + console.error(`Error scanning workspace ${workspaceUri}:`, error); + } + } + + return allTsFiles; + } + + private async scanDirectoryForTypeScriptFiles( + dirPath: string, + tsExtensions: string[], + ): Promise { + const tsFiles: string[] = []; + + const shouldSkipDirectory = (dirName: string): boolean => { + const skipDirs = [ + "node_modules", + ".git", + ".vscode", + "dist", + "build", + "out", + ".next", + "coverage", + ".nyc_output", + "tmp", + "temp", + ".cache", + ]; + + return skipDirs.includes(dirName) || dirName.startsWith("."); + }; + + async function scanRecursively(currentPath: string): Promise { + try { + const entries = await fs.readdir(currentPath, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = localPathOrUriToPath( + path.join(currentPath, entry.name), + ); + + if (entry.isDirectory()) { + // Skip common directories that typically don't contain source files + if (!shouldSkipDirectory(entry.name)) { + await scanRecursively(fullPath); + } + } else if (entry.isFile()) { + const extension = path.extname(entry.name).toLowerCase(); + if (tsExtensions.includes(extension)) { + tsFiles.push(fullPath); + } + } + } + } catch (error) { + console.error(`Error reading directory ${currentPath}:`, error); + } + } + + await scanRecursively(dirPath); + return tsFiles; } } diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index 3db2c2542..681e20478 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -1,4 +1,3 @@ -import { context } from "esbuild"; import { IDE } from "../../index"; import { findUriInDirs } from "../../util/uri"; import { ContextRetrievalService } from "../context/ContextRetrievalService"; @@ -11,6 +10,7 @@ import { AutocompleteCodeSnippet, AutocompleteDiffSnippet, AutocompleteSnippetType, + AutocompleteStaticSnippet, } from "./types"; const IDE_SNIPPETS_ENABLED = false; // ideSnippets is not used, so it's temporarily disabled @@ -23,6 +23,7 @@ export interface SnippetPayload { recentlyVisitedRangesSnippets: AutocompleteCodeSnippet[]; diffSnippets: AutocompleteDiffSnippet[]; clipboardSnippets: AutocompleteClipboardSnippet[]; + staticSnippet: AutocompleteStaticSnippet[]; } function racePromise(promise: Promise, timeout = 100): Promise { @@ -124,7 +125,7 @@ export const getAllSnippets = async ({ ideSnippets, diffSnippets, clipboardSnippets, - staticSnippets + staticSnippet, ] = await Promise.all([ racePromise(contextRetrievalService.getRootPathSnippets(helper)), racePromise( @@ -135,7 +136,7 @@ export const getAllSnippets = async ({ : [], [], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882, racePromise(getClipboardSnippets(ide)), - racePromise(contextRetrievalService.getStaticContextSnippets(helper)) + contextRetrievalService.getStaticContextSnippets(helper), ]); return { @@ -146,5 +147,6 @@ export const getAllSnippets = async ({ diffSnippets, clipboardSnippets, recentlyVisitedRangesSnippets: helper.input.recentlyVisitedRanges, + staticSnippet, }; }; From 61b389e5fb7947755da3215d31eaebff7cea9569 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 28 Jun 2025 20:14:49 -0700 Subject: [PATCH 13/31] prettier --- .../context/static-context/StaticContextService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index 4b9b41917..6ba954fc7 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -764,7 +764,9 @@ export class StaticContextService { async function scanRecursively(currentPath: string): Promise { try { - const entries = await fs.readdir(currentPath, { withFileTypes: true }); + const entries = await fs.readdir(currentPath, { + withFileTypes: true, + }); for (const entry of entries) { const fullPath = localPathOrUriToPath( From 482ed61a5e9ffd0592b1e65c229299bdb7351ce3 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 08:49:59 -0700 Subject: [PATCH 14/31] resolve merge conflicts --- core/autocomplete/snippets/getAllSnippets.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index 7ba487054..fccc8530b 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -199,6 +199,7 @@ export const getAllSnippets = async ({ [], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882, racePromise(getClipboardSnippets(ide)), racePromise(getSnippetsFromRecentlyOpenedFiles(helper, ide)), // giving this one a little more time to complete + racePromise(contextRetrievalService.getStaticContextSnippets(helper)), ]); return { @@ -210,6 +211,7 @@ export const getAllSnippets = async ({ clipboardSnippets, recentlyVisitedRangesSnippets: helper.input.recentlyVisitedRanges, recentlyOpenedFileSnippets, + staticSnippet, }; }; @@ -234,6 +236,7 @@ export const getAllSnippetsWithoutRace = async ({ diffSnippets, clipboardSnippets, recentlyOpenedFileSnippets, + staticSnippet, ] = await Promise.all([ contextRetrievalService.getRootPathSnippets(helper), contextRetrievalService.getSnippetsFromImportDefinitions(helper), From b0b2de7dff9ddcbdce55f1e8a927a9f5c151453c Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:28:16 -0700 Subject: [PATCH 15/31] add methods for go to type definitions and get signature help --- core/index.d.ts | 118 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 24 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index e173e9a58..5bd5de1ad 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -49,13 +49,13 @@ export interface IndexingProgressUpdate { desc: string; shouldClearIndexes?: boolean; status: - | "loading" - | "indexing" - | "done" - | "failed" - | "paused" - | "disabled" - | "cancelled"; + | "loading" + | "indexing" + | "done" + | "failed" + | "paused" + | "disabled" + | "cancelled"; debugInfo?: string; warnings?: string[]; } @@ -92,7 +92,7 @@ type RequiredLLMOptions = export interface ILLM extends Omit, - Required> { + Required> { get providerName(): string; get underlyingProviderName(): string; @@ -778,10 +778,10 @@ export interface IDE { getCurrentFile(): Promise< | undefined | { - isUntitled: boolean; - path: string; - contents: string; - } + isUntitled: boolean; + path: string; + contents: string; + } >; getPinnedFiles(): Promise; @@ -819,7 +819,8 @@ export interface IDE { // LSP gotoDefinition(location: Location): Promise; - gotoTypeDefinition(location: Location): Promise; + gotoTypeDefinition(location: Location): Promise; // TODO: add to jetbrains + getSignatureHelp(location: Location): Promise; // TODO: add to jetbrains // Callbacks onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void; @@ -989,11 +990,11 @@ export interface CustomCommand { export interface Prediction { type: "content"; content: - | string - | { - type: "text"; - text: string; - }[]; + | string + | { + type: "text"; + text: string; + }[]; } export interface ToolExtras { @@ -1156,6 +1157,7 @@ export interface TabAutocompleteOptions { experimental_includeRecentlyVisitedRanges: boolean | number; experimental_includeRecentlyEditedRanges: boolean | number; experimental_includeDiff: boolean | number; + experimental_enableStaticContextualization: boolean; } export interface StdioOptions { @@ -1355,6 +1357,68 @@ export interface RangeInFileWithNextEditInfo { export type SetCodeToEditPayload = RangeInFileWithContents | FileWithContents; +/** + * Signature help represents the signature of something + * callable. There can be multiple signatures but only one + * active and only one active parameter. + */ +export class SignatureHelp { + /** + * One or more signatures. + */ + signatures: SignatureInformation[]; + + /** + * The active signature. + */ + activeSignature: number; + + /** + * The active parameter of the active signature. + */ + activeParameter: number; +} + +/** + * Represents the signature of something callable. A signature + * can have a label, like a function-name, a doc-comment, and + * a set of parameters. + */ +export class SignatureInformation { + /** + * The label of this signature. Will be shown in + * the UI. + */ + label: string; + + /** + * The parameters of this signature. + */ + parameters: ParameterInformation[]; + + /** + * The index of the active parameter. + * + * If provided, this is used in place of {@linkcode SignatureHelp.activeParameter}. + */ + activeParameter?: number; +} + +/** + * Represents a parameter of a callable-signature. A parameter can + * have a label and a doc-comment. + */ +export class ParameterInformation { + /** + * The label of this signature. + * + * Either a string or inclusive start and exclusive end offsets within its containing + * {@link SignatureInformation.label signature label}. *Note*: A label of type string must be + * a substring of its containing signature information's {@link SignatureInformation.label label}. + */ + label: string | [number, number]; +} + /** * Represents the configuration for a quick action in the Code Lens. * Quick actions are custom commands that can be added to function and class declarations. @@ -1430,6 +1494,12 @@ export interface ExperimentalConfig { * instead of embeddings, FTS, recently edited files, etc. */ codebaseToolCallingOnly?: boolean; + + /** + * If enabled, static contextualization will be used to + * gather context for the model where necessary. + */ + enableStaticContextualization?: boolean; } export interface AnalyticsConfig { @@ -1529,9 +1599,9 @@ export interface Config { embeddingsProvider?: EmbeddingsProviderDescription | ILLM; /** The model that Continue will use for tab autocompletions. */ tabAutocompleteModel?: - | CustomLLM - | JSONModelDescription - | (CustomLLM | JSONModelDescription)[]; + | CustomLLM + | JSONModelDescription + | (CustomLLM | JSONModelDescription)[]; /** Options for tab autocomplete */ tabAutocompleteOptions?: Partial; /** UI styles customization */ @@ -1625,9 +1695,9 @@ export type PackageDetailsSuccess = PackageDetails & { export type PackageDocsResult = { packageInfo: ParsedPackageInfo; } & ( - | { error: string; details?: never } - | { details: PackageDetailsSuccess; error?: never } - ); + | { error: string; details?: never } + | { details: PackageDetailsSuccess; error?: never } +); export interface TerminalOptions { reuseTerminal?: boolean; From f04260a7efac3aeffc92a849fbc7bfdd0df5be33 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:28:32 -0700 Subject: [PATCH 16/31] enable static contextualization when needed --- core/autocomplete/CompletionProvider.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/CompletionProvider.ts b/core/autocomplete/CompletionProvider.ts index 749b44e25..4d4327bcc 100644 --- a/core/autocomplete/CompletionProvider.ts +++ b/core/autocomplete/CompletionProvider.ts @@ -10,7 +10,7 @@ import { BracketMatchingService } from "./filtering/BracketMatchingService.js"; import { CompletionStreamer } from "./generation/CompletionStreamer.js"; import { postprocessCompletion } from "./postprocessing/index.js"; import { shouldPrefilter } from "./prefiltering/index.js"; -import { getAllSnippets } from "./snippets/index.js"; +import { getAllSnippetsWithoutRace } from "./snippets/index.js"; import { renderPrompt } from "./templating/index.js"; import { GetLspDefinitionsFunction } from "./types.js"; import { AutocompleteDebouncer } from "./util/AutocompleteDebouncer.js"; @@ -121,6 +121,11 @@ export class CompletionProvider { ...config?.tabAutocompleteOptions, ...llm.autocompleteOptions, }; + + // Enable static contextualization if defined. + options.experimental_enableStaticContextualization = + config?.experimental?.enableStaticContextualization ?? false; + return options; } @@ -171,7 +176,7 @@ export class CompletionProvider { } const [snippetPayload, workspaceDirs] = await Promise.all([ - getAllSnippets({ + getAllSnippetsWithoutRace({ helper, ide: this.ide, getDefinitionsFromLsp: this.getDefinitionsFromLsp, From 8b03b9a67d9152dee1239c3c653edd31c9346f76 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:28:53 -0700 Subject: [PATCH 17/31] improve usability --- .../static-context/StaticContextService.ts | 90 +++++++++++++++++-- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index 6ba954fc7..fb6919d35 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -85,7 +85,11 @@ export class StaticContextService { helper.workspaceUris, ); // Get the three contexts holeContext, relevantTypes, relevantHeaders. - const holeContext = await this.getHoleContext(helper.filepath, helper.pos); + const holeContext = await this.getHoleContext( + helper.fileContents, + helper.filepath, + helper.pos, + ); const relevantTypes = await this.extractRelevantTypes( holeContext.fullHoverResult, @@ -106,6 +110,8 @@ export class StaticContextService { tsFiles, relevantTypes, holeContext.functionTypeSpan, + helper.pos, + holeContext.returnTypeIsAny, ); const relevantTypesToReturn: Map = new Map< @@ -158,12 +164,13 @@ export class StaticContextService { } private async getHoleContext( + sketchFileContent: string, sketchFilePath: string, cursorPosition: Position, ): Promise { // We need to inject the hole @ to trigger a treesitter error node. sketchFilePath = localPathOrUriToPath(sketchFilePath); - const sketchFileContent = await fs.readFile(sketchFilePath, "utf8"); + // const sketchFileContent = await fs.readFile(sketchFilePath, "utf8"); const injectedContent = this.insertAtPosition( sketchFileContent, cursorPosition, @@ -193,12 +200,14 @@ export class StaticContextService { fullHoverResult: "", functionName: "", functionTypeSpan: "", + returnTypeIsAny: false, range: { start: { line: 0, character: 0 }, - end: { line: 0, character: 52 }, + end: { line: 0, character: 0 }, }, source: `file://${sketchFilePath}`, }; + let paramsTypes = ""; for (const c of captures) { const { name, node } = c; // console.log(`${name} →`, node.text, node.startPosition, node.endPosition); @@ -206,9 +215,25 @@ export class StaticContextService { switch (name) { case "function.decl": { res.fullHoverResult = node.text; + break; } case "function.name": { res.functionName = node.text; + break; + } + case "function.params": { + paramsTypes = node.text; + res.range = { + start: { + line: node.startPosition.row, + character: node.startPosition.column, + }, + end: { + line: node.endPosition.row, + character: node.endPosition.column, + }, + }; + break; } case "function.type": { res.functionTypeSpan = node.text; @@ -222,10 +247,16 @@ export class StaticContextService { character: node.endPosition.column, }, }; + break; } } } + if (res.functionTypeSpan === "") { + res.functionTypeSpan = `${paramsTypes} => any`; + res.returnTypeIsAny = true; + } + return res; } @@ -354,8 +385,11 @@ export class StaticContextService { sources: string[], relevantTypes: Map, holeType: string, + cursorPosition: Position, + returnTypeIsAny: boolean, ): Promise { const relevantContext = new Set(); + if (returnTypeIsAny) return relevantContext; // NOTE: This is necessary because TypeScript sucks. // There is no way to compare objects by value, // so sets of objects starts to accumulate tons of duplicates. @@ -378,7 +412,43 @@ export class StaticContextService { // build a type span // TODO: this fails sometimes with Cannot read properties of undefined (reading 'text') // most likely due to my scm query and how I'm not attaching param name along with param type - const funcType = extractFunctionTypeFromDecl(tld); + let funcType = ""; + try { + funcType = extractFunctionTypeFromDecl(tld); + } catch (err) { + // Most likely is the case that there is no explicit return type annotation. + const sigHelp = await this.ide.getSignatureHelp({ + filepath: source, + position: cursorPosition, + }); + if (!sigHelp) continue; + funcType = sigHelp.signatures[0].label; + + // TODO: This only works for TypeScript. + function convertToArrowType(signature: string): string { + // Handle various function declaration formats. + const patterns = [ + // Standard: functionName(params): returnType. + /^(\w+)\s*\((.*?)\)\s*:\s*(.+)$/, + // With generics: functionName(params): returnType. + /^(\w+)\s*<[^>]*>\s*\((.*?)\)\s*:\s*(.+)$/, + // With modifiers: export function functionName(params): returnType. + /^(?:export\s+)?(?:function\s+)?(\w+)\s*\((.*?)\)\s*:\s*(.+)$/, + ]; + + for (const pattern of patterns) { + const match = signature.match(pattern); + if (match) { + const [, , parameters, returnType] = match; + return `(${parameters}) => ${returnType}`; + } + } + + return signature; + } + + funcType = convertToArrowType(funcType); + } const wrapped = `type __TMP = ${funcType};`; const ast = await getAst("file.ts", wrapped); @@ -386,9 +456,9 @@ export class StaticContextService { throw new Error(`failed to generate ast for ${wrapped}`); } - console.log(ast.rootNode); + // console.log(ast.rootNode); const alias = ast.rootNode.namedChild(0); - console.log(alias); + // console.log(alias); if (!alias || alias.type !== "type_alias_declaration") { throw new Error( "extractRelevantHeaders: Failed to parse type alias", @@ -564,9 +634,11 @@ export class StaticContextService { const alias = ast.rootNode.namedChild(0); if (!alias || alias.type !== "type_alias_declaration") { - throw new Error( - "generateTargetTypesHelper: Failed to parse type alias", - ); + console.error("generateTargetTypesHelper: Failed to parse type alias"); + return; + // throw new Error( + // "generateTargetTypesHelper: Failed to parse type alias", + // ); } const valueNode = alias.childForFieldName("value"); From f1cdd5fb754b0eb5e1d930d44b0dc424749d9c52 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:29:14 -0700 Subject: [PATCH 18/31] prettier check --- .../static-context/tree-sitter-utils.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/core/autocomplete/context/static-context/tree-sitter-utils.ts b/core/autocomplete/context/static-context/tree-sitter-utils.ts index c7a9a20a3..6e751f547 100644 --- a/core/autocomplete/context/static-context/tree-sitter-utils.ts +++ b/core/autocomplete/context/static-context/tree-sitter-utils.ts @@ -1,8 +1,7 @@ import * as fs from "fs/promises"; import Parser from "web-tree-sitter"; -import { getAst } from "../../util/ast"; import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; -import path from "path"; +import { getAst } from "../../util/ast"; export interface TypeDeclarationResult { name: string; @@ -18,7 +17,7 @@ export function findEnclosingTypeDeclaration( sourceCode: string, cursorLine: number, cursorColumn: number, - ast: Parser.Tree + ast: Parser.Tree, ): TypeDeclarationResult | null { const point = { row: cursorLine, column: cursorColumn }; let node = ast.rootNode.descendantForPosition(point); @@ -52,7 +51,10 @@ export function findEnclosingTypeDeclaration( }; } -export async function extractTopLevelDecls(currentFile: string, givenParser?: Parser) { +export async function extractTopLevelDecls( + currentFile: string, + givenParser?: Parser, +) { const ast = await getAst(currentFile, await fs.readFile(currentFile, "utf8")); if (!ast) { throw new Error(`failed to get ast for file ${currentFile}`); @@ -66,17 +68,20 @@ export async function extractTopLevelDecls(currentFile: string, givenParser?: Pa const query = await getQueryForFile( currentFile, - `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm` + `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm`, ); if (!query) { throw new Error( - `failed to get query for file ${currentFile} and language ${language}` + `failed to get query for file ${currentFile} and language ${language}`, ); } return query.matches(ast.rootNode); } -export async function extractTopLevelDeclsWithFormatting(currentFile: string, givenParser?: Parser) { +export async function extractTopLevelDeclsWithFormatting( + currentFile: string, + givenParser?: Parser, +) { const ast = await getAst(currentFile, await fs.readFile(currentFile, "utf8")); if (!ast) { throw new Error(`failed to get ast for file ${currentFile}`); @@ -90,11 +95,11 @@ export async function extractTopLevelDeclsWithFormatting(currentFile: string, gi const query = await getQueryForFile( currentFile, - `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm` + `static-context-queries/relevant-headers-queries/${language}-get-toplevel-headers.scm`, ); if (!query) { throw new Error( - `failed to get query for file ${currentFile} and language ${language}` + `failed to get query for file ${currentFile} and language ${language}`, ); } const matches = query.matches(ast.rootNode); @@ -166,13 +171,21 @@ export function extractFunctionTypeFromDecl(match: Parser.QueryMatch): string { } if (!paramsNode) { - console.error(`extractFunctionTypeFromDecl: ${paramsNode} not found`); - throw new Error(`extractFunctionTypeFromDecl: ${paramsNode} not found`); + console.error( + `extractFunctionTypeFromDecl: paramsNode ${paramsNode} not found`, + ); + throw new Error( + `extractFunctionTypeFromDecl: paramsNode ${paramsNode} not found`, + ); } if (!returnNode) { - console.error(`extractFunctionTypeFromDecl: ${returnNode} not found`); - throw new Error(`extractFunctionTypeFromDecl: ${returnNode} not found`); + console.error( + `extractFunctionTypeFromDecl: returnNode ${returnNode} not found`, + ); + throw new Error( + `extractFunctionTypeFromDecl: returnNode ${returnNode} not found`, + ); } return `(${paramsNode!.text}) => ${returnNode!.text}`; From 0f7a0023770285b777051ce8ebb79aa95fb9528f Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:29:27 -0700 Subject: [PATCH 19/31] check for config enable --- core/autocomplete/snippets/getAllSnippets.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index fccc8530b..079127abc 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -199,7 +199,9 @@ export const getAllSnippets = async ({ [], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882, racePromise(getClipboardSnippets(ide)), racePromise(getSnippetsFromRecentlyOpenedFiles(helper, ide)), // giving this one a little more time to complete - racePromise(contextRetrievalService.getStaticContextSnippets(helper)), + helper.options.experimental_enableStaticContextualization + ? racePromise(contextRetrievalService.getStaticContextSnippets(helper)) + : [], ]); return { @@ -246,7 +248,9 @@ export const getAllSnippetsWithoutRace = async ({ [], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882, getClipboardSnippets(ide), getSnippetsFromRecentlyOpenedFiles(helper, ide), - contextRetrievalService.getStaticContextSnippets(helper), + helper.options.experimental_enableStaticContextualization + ? contextRetrievalService.getStaticContextSnippets(helper) + : [], ]); return { From e7a75a59031c3853cea6f1165ee1bd0bd89b44e3 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:29:45 -0700 Subject: [PATCH 20/31] check for any return type for quick optimization --- core/autocomplete/context/static-context/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/autocomplete/context/static-context/types.ts b/core/autocomplete/context/static-context/types.ts index 2400c2a7a..1aa8b473d 100644 --- a/core/autocomplete/context/static-context/types.ts +++ b/core/autocomplete/context/static-context/types.ts @@ -14,6 +14,7 @@ export interface HoleContext { fullHoverResult: string; functionName: string; functionTypeSpan: string; + returnTypeIsAny: boolean; range: Range; source: string; } From 068b7f28327ffa737679f51824987277278ef7a2 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:30:06 -0700 Subject: [PATCH 21/31] add defs for static contextualization --- core/config/sharedConfig.ts | 5 +++++ core/util/parameters.ts | 1 + gui/src/pages/config/UserSettingsForm.tsx | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/core/config/sharedConfig.ts b/core/config/sharedConfig.ts index 5d7053cf8..87f923f3c 100644 --- a/core/config/sharedConfig.ts +++ b/core/config/sharedConfig.ts @@ -23,6 +23,7 @@ export const sharedConfigSchema = z optInNextEditFeature: z.boolean(), enableExperimentalTools: z.boolean(), codebaseToolCallingOnly: z.boolean(), + enableStaticContextualization: z.boolean(), // `ui` in `ContinueConfig` showSessionTabs: z.boolean(), @@ -192,6 +193,10 @@ export function modifyAnyConfigWithSharedConfig< configCopy.experimental.codebaseToolCallingOnly = sharedConfig.codebaseToolCallingOnly; } + if (sharedConfig.enableStaticContextualization !== undefined) { + configCopy.experimental.enableStaticContextualization = + sharedConfig.enableStaticContextualization; + } return configCopy; } diff --git a/core/util/parameters.ts b/core/util/parameters.ts index cadbe9a47..147c3979a 100644 --- a/core/util/parameters.ts +++ b/core/util/parameters.ts @@ -24,6 +24,7 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = { experimental_includeRecentlyVisitedRanges: true, experimental_includeRecentlyEditedRanges: true, experimental_includeDiff: true, + experimental_enableStaticContextualization: false, }; export const COUNT_COMPLETION_REJECTED_AFTER = 10_000; diff --git a/gui/src/pages/config/UserSettingsForm.tsx b/gui/src/pages/config/UserSettingsForm.tsx index 04405f1be..54783c254 100644 --- a/gui/src/pages/config/UserSettingsForm.tsx +++ b/gui/src/pages/config/UserSettingsForm.tsx @@ -97,6 +97,8 @@ export function UserSettingsForm() { config.experimental?.optInNextEditFeature ?? false; const codebaseToolCallingOnly = config.experimental?.codebaseToolCallingOnly ?? false; + const enableStaticContextualization = + config.experimental?.enableStaticContextualization ?? false; const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; const disableIndexing = config.disableIndexing ?? false; @@ -434,6 +436,17 @@ export function UserSettingsForm() { text="@Codebase: use tool calling only" /> + + handleUpdate({ + enableStaticContextualization: + !enableStaticContextualization, + }) + } + text="Use Static Contextualization" + /> + {hasContinueEmail && ( Date: Sat, 5 Jul 2025 17:30:21 -0700 Subject: [PATCH 22/31] add methods for get signature help --- extensions/vscode/src/VsCodeIde.ts | 17 ++++++- extensions/vscode/src/autocomplete/lsp.ts | 54 ++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 01246e35f..ec68fb065 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -6,7 +6,10 @@ import { EXTENSION_NAME } from "core/control-plane/env"; import * as URI from "uri-js"; import * as vscode from "vscode"; -import { executeGotoProvider } from "./autocomplete/lsp"; +import { + executeGotoProvider, + executeSignatureHelpProvider, +} from "./autocomplete/lsp"; import { Repository } from "./otherExtensions/git"; import { SecretStorage } from "./stubs/SecretStorage"; import { VsCodeIdeUtils } from "./util/ideUtils"; @@ -24,6 +27,7 @@ import type { Location, Problem, RangeInFile, + SignatureHelp, TerminalOptions, Thread, } from "core"; @@ -97,6 +101,17 @@ class VsCodeIde implements IDE { return result; } + async getSignatureHelp(location: Location): Promise { + const result = await executeSignatureHelpProvider({ + uri: vscode.Uri.parse(location.filepath), + line: location.position.line, + character: location.position.character, + name: "vscode.executeSignatureHelpProvider", + }); + + return result; + } + onDidChangeActiveTextEditor(callback: (uri: string) => void): void { vscode.window.onDidChangeActiveTextEditor((editor) => { if (editor) { diff --git a/extensions/vscode/src/autocomplete/lsp.ts b/extensions/vscode/src/autocomplete/lsp.ts index a6900291a..c3d5c11a4 100644 --- a/extensions/vscode/src/autocomplete/lsp.ts +++ b/extensions/vscode/src/autocomplete/lsp.ts @@ -13,7 +13,13 @@ import { intersection } from "core/util/ranges"; import * as URI from "uri-js"; import * as vscode from "vscode"; -import type { IDE, Range, RangeInFile, RangeInFileWithContents } from "core"; +import type { + IDE, + Range, + RangeInFile, + RangeInFileWithContents, + SignatureHelp, +} from "core"; import type Parser from "web-tree-sitter"; type GotoProviderName = @@ -23,6 +29,8 @@ type GotoProviderName = | "vscode.executeImplementationProvider" | "vscode.executeReferenceProvider"; +type SignatureHelpProviderName = "vscode.executeSignatureHelpProvider"; + interface GotoInput { uri: vscode.Uri; line: number; @@ -33,8 +41,19 @@ function gotoInputKey(input: GotoInput) { return `${input.name}${input.uri.toString()}${input.line}${input.character}`; } +interface SignatureHelpInput { + uri: vscode.Uri; + line: number; + character: number; + name: SignatureHelpProviderName; +} +function signatureHelpKey(input: SignatureHelpInput) { + return `${input.name}${input.uri.toString()}${input.line}${input.character}`; +} + const MAX_CACHE_SIZE = 500; const gotoCache = new Map(); +const signatureHelpCache = new Map(); export async function executeGotoProvider( input: GotoInput, @@ -382,3 +401,36 @@ export const getDefinitionsFromLsp: GetLspDefinitionsFunction = async ( return []; } }; + +export async function executeSignatureHelpProvider( + input: SignatureHelpInput, +): Promise { + const cacheKey = signatureHelpKey(input); + const cached = signatureHelpCache.get(cacheKey); + if (cached) { + return cached; + } + + try { + const definitions = (await vscode.commands.executeCommand( + input.name, + input.uri, + new vscode.Position(input.line, input.character), + )) as SignatureHelp; + + // Add to cache + if (signatureHelpCache.size >= MAX_CACHE_SIZE) { + // Remove the oldest item from the cache + const oldestKey = signatureHelpCache.keys().next().value; + if (oldestKey) { + signatureHelpCache.delete(oldestKey); + } + } + signatureHelpCache.set(cacheKey, definitions); + + return definitions; + } catch (e) { + console.warn(`Error executing ${input.name}:`, e); + return null; + } +} From 3edf8097b3eb75f2aca80d8e55ca301558ee8fd5 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:30:37 -0700 Subject: [PATCH 23/31] handle cases where function declarations have no body --- .../hole-queries/typescript.scm | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm b/extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm index e69122b07..02de34466 100644 --- a/extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm +++ b/extensions/vscode/tree-sitter/static-context-queries/hole-queries/typescript.scm @@ -21,7 +21,7 @@ (function_type return_type: (type_identifier) @return.type) -;; Capture any parse errors (e.g., the `??`) +;; Capture any parse errors (e.g., the `@`) (ERROR) @error.node ;; Capture the entire function declaration line @@ -34,3 +34,26 @@ (import_specifier name: (identifier) @import.name))) source: (string) @import.source) + +;; Capture standalone function declarations +(function_declaration + name: (identifier) @function.name) @function.decl + +;; Capture the function signature including parameters and return type +(function_declaration + parameters: (formal_parameters) @function.params + return_type: (type_annotation)? @function.type) + +;; For function expressions or arrow functions +(function_type + parameters: (formal_parameters) @function.params) @function.decl + +;; For arrow functions +(arrow_function + parameters: (formal_parameters) @function.params) @function.decl + +;; For function signatures without a body (like in your example) +(function_signature + name: (identifier) @function.name + parameters: (formal_parameters) @function.params + return_type: (type_annotation)? @function.type) @function.decl From be10c078c7c57789a2c23b29bfdf89648e497547 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 17:52:27 -0700 Subject: [PATCH 24/31] match type definition parity with vscode --- .../continue/IntelliJIde.kt | 8 +++ .../continueintellijextension/types.kt | 64 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt index 2dfc3e3e1..782a878d6 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt @@ -592,6 +592,14 @@ class IntelliJIDE( throw NotImplementedError("gotoDefinition not implemented yet") } + override suspend fun gotoTypeDefinition(location: Location): List { + throw NotImplementedError("gotoTypeDefinition not implemented yet") + } + + override suspend fun getSignatureHelp(location: Location): SignatureHelp? { + throw NotImplementedError("getSignatureHelp not implemented yet") + } + override fun onDidChangeActiveTextEditor(callback: (filepath: String) -> Unit) { throw NotImplementedError("onDidChangeActiveTextEditor not implemented yet") } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt index 5ff9e9454..dd898eca2 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt @@ -63,6 +63,68 @@ data class RangeInFileWithContents( val contents: String ) +/** + * Signature help represents the signature of something + * callable. There can be multiple signatures but only one + * active and only one active parameter. + */ +data class SignatureHelp( + /** + * One or more signatures. + */ + val signatures: List, + + /** + * The active signature. + */ + val activeSignature: Int, + + /** + * The active parameter of the active signature. + */ + val activeParameter: Int +) + +/** + * Represents the signature of something callable. A signature + * can have a label, like a function-name, a doc-comment, and + * a set of parameters. + */ +data class SignatureInformation( + /** + * The label of this signature. Will be shown in + * the UI. + */ + val label: String, + + /** + * The parameters of this signature. + */ + val parameters: List, + + /** + * The index of the active parameter. + * + * If provided, this is used in place of [SignatureHelp.activeParameter]. + */ + val activeParameter: Int? = null +) + +/** + * Represents a parameter of a callable-signature. A parameter can + * have a label and a doc-comment. + */ +data class ParameterInformation( + /** + * The label of this signature. + * + * Either a string or inclusive start and exclusive end offsets within its containing + * [SignatureInformation.label] signature label. *Note*: A label of type string must be + * a substring of its containing signature information's [SignatureInformation.label] label. + */ + val label: String // Note: Kotlin doesn't have union types, so this represents the string case +) + data class ControlPlaneSessionInfo( val accessToken: String, val account: Account @@ -191,6 +253,8 @@ interface IDE { // LSP suspend fun gotoDefinition(location: Location): List + suspend fun gotoTypeDefinition(location: Location): List + suspend fun getSignatureHelp(location: Location): SignatureHelp? // Callbacks fun onDidChangeActiveTextEditor(callback: (filepath: String) -> Unit) From 6a2ede397179b7ee3033e4533f3a772ac556c340 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 20:28:02 -0700 Subject: [PATCH 25/31] add a flag to check if static contextualization was enabled --- packages/config-yaml/src/schemas/data/autocomplete/index.ts | 3 +++ packages/config-yaml/src/schemas/data/autocomplete/v0.2.0.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/config-yaml/src/schemas/data/autocomplete/index.ts b/packages/config-yaml/src/schemas/data/autocomplete/index.ts index 8ae073e2e..4d2a0b91b 100644 --- a/packages/config-yaml/src/schemas/data/autocomplete/index.ts +++ b/packages/config-yaml/src/schemas/data/autocomplete/index.ts @@ -36,6 +36,9 @@ export const autocompleteEventAllSchema = baseDevDataAllSchema.extend({ uniqueId: z.string(), timestamp: z.number(), + // For static contextualization. + enabledStaticContextualization: z.boolean().optional(), + // DEPRECATED - no more nested objects after v0.1.0, all flat values completionOptions: completionOptionsSchema.optional(), disableInFiles: z.array(z.string()).optional(), diff --git a/packages/config-yaml/src/schemas/data/autocomplete/v0.2.0.ts b/packages/config-yaml/src/schemas/data/autocomplete/v0.2.0.ts index 5866b9865..123a05b75 100644 --- a/packages/config-yaml/src/schemas/data/autocomplete/v0.2.0.ts +++ b/packages/config-yaml/src/schemas/data/autocomplete/v0.2.0.ts @@ -38,6 +38,9 @@ export const autocompleteEventSchema_0_2_0 = autocompleteEventAllSchema.pick({ completionId: true, uniqueId: true, + // For static contextualization. + enabledStaticContextualization: true, + // Note objects (completionOptions and disableInfiles) removed from 0.1.0 => 0.2.0 }); From 53b28146ebbbfc282cca74b429dec9d48a7277f2 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Sat, 5 Jul 2025 20:32:06 -0700 Subject: [PATCH 26/31] log static contextualization --- core/autocomplete/CompletionProvider.ts | 9 +++- .../util/AutocompleteLoggingService.ts | 44 +++++++++++-------- core/autocomplete/util/types.ts | 1 + 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/core/autocomplete/CompletionProvider.ts b/core/autocomplete/CompletionProvider.ts index 4d4327bcc..2e3cd320d 100644 --- a/core/autocomplete/CompletionProvider.ts +++ b/core/autocomplete/CompletionProvider.ts @@ -123,8 +123,9 @@ export class CompletionProvider { }; // Enable static contextualization if defined. - options.experimental_enableStaticContextualization = - config?.experimental?.enableStaticContextualization ?? false; + if (config?.experimental?.enableStaticContextualization) { + options.experimental_enableStaticContextualization = true; + } return options; } @@ -263,6 +264,10 @@ export class CompletionProvider { ...helper.options, }; + if (options.experimental_enableStaticContextualization) { + outcome.enabledStaticContextualization = true; + } + ////////// // Save to cache diff --git a/core/autocomplete/util/AutocompleteLoggingService.ts b/core/autocomplete/util/AutocompleteLoggingService.ts index 2e4d19844..4f600a8c5 100644 --- a/core/autocomplete/util/AutocompleteLoggingService.ts +++ b/core/autocomplete/util/AutocompleteLoggingService.ts @@ -105,24 +105,30 @@ export class AutocompleteLoggingService { }); const { prompt, completion, prefix, suffix, ...restOfOutcome } = outcome; - void Telemetry.capture( - "autocomplete", - { - accepted: restOfOutcome.accepted, - cacheHit: restOfOutcome.cacheHit, - completionId: restOfOutcome.completionId, - completionOptions: restOfOutcome.completionOptions, - debounceDelay: restOfOutcome.debounceDelay, - fileExtension: getUriFileExtension(restOfOutcome.filepath), - maxPromptTokens: restOfOutcome.maxPromptTokens, - modelName: restOfOutcome.modelName, - modelProvider: restOfOutcome.modelProvider, - multilineCompletions: restOfOutcome.multilineCompletions, - time: restOfOutcome.time, - useRecentlyEdited: restOfOutcome.useRecentlyEdited, - numLines: restOfOutcome.numLines, - }, - true, - ); + const toLog = { + accepted: restOfOutcome.accepted, + cacheHit: restOfOutcome.cacheHit, + completionId: restOfOutcome.completionId, + completionOptions: restOfOutcome.completionOptions, + debounceDelay: restOfOutcome.debounceDelay, + fileExtension: getUriFileExtension(restOfOutcome.filepath), + maxPromptTokens: restOfOutcome.maxPromptTokens, + modelName: restOfOutcome.modelName, + modelProvider: restOfOutcome.modelProvider, + multilineCompletions: restOfOutcome.multilineCompletions, + time: restOfOutcome.time, + useRecentlyEdited: restOfOutcome.useRecentlyEdited, + numLines: restOfOutcome.numLines, + }; + + outcome.enabledStaticContextualization + ? void Telemetry.capture("autocomplete", { + ...toLog, + enabledStaticContextualization: true, + prefix, + suffix, + prompt, + }) + : void Telemetry.capture("autocomplete", toLog); } } diff --git a/core/autocomplete/util/types.ts b/core/autocomplete/util/types.ts index 3959bff9c..32be50e2f 100644 --- a/core/autocomplete/util/types.ts +++ b/core/autocomplete/util/types.ts @@ -42,4 +42,5 @@ export interface AutocompleteOutcome extends TabAutocompleteOptions { completionId: string; uniqueId: string; timestamp: number; + enabledStaticContextualization?: boolean; } From 031ad9dc0b11d788f327e885160e20a4559fb5f6 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Mon, 7 Jul 2025 18:53:49 -0700 Subject: [PATCH 27/31] move to continue-only feature for internal testing --- gui/src/pages/config/ContinueFeaturesMenu.tsx | 14 +++++++++++++ gui/src/pages/config/UserSettingsForm.tsx | 21 +++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gui/src/pages/config/ContinueFeaturesMenu.tsx b/gui/src/pages/config/ContinueFeaturesMenu.tsx index f3cb738ca..c83b5a334 100644 --- a/gui/src/pages/config/ContinueFeaturesMenu.tsx +++ b/gui/src/pages/config/ContinueFeaturesMenu.tsx @@ -6,6 +6,8 @@ interface ContinueFeaturesMenuProps { handleLogEditingDataToggle: (value: boolean) => void; optInNextEditFeature: boolean; handleOptInNextEditToggle: (value: boolean) => void; + enableStaticContextualization: boolean; + handleEnableStaticContextualizationToggle: (value: boolean) => void; } export function ContinueFeaturesMenu({ @@ -13,6 +15,8 @@ export function ContinueFeaturesMenu({ handleLogEditingDataToggle, optInNextEditFeature, handleOptInNextEditToggle, + enableStaticContextualization, + handleEnableStaticContextualizationToggle, }: ContinueFeaturesMenuProps) { return (
@@ -42,6 +46,16 @@ export function ContinueFeaturesMenu({ onToggle={() => handleOptInNextEditToggle(!optInNextEditFeature)} text="Enable Next Edit Over Autocomplete" /> + + + handleEnableStaticContextualizationToggle( + !enableStaticContextualization, + ) + } + text="Use Static Contextualization" + />
); diff --git a/gui/src/pages/config/UserSettingsForm.tsx b/gui/src/pages/config/UserSettingsForm.tsx index 54783c254..ea6b27cfd 100644 --- a/gui/src/pages/config/UserSettingsForm.tsx +++ b/gui/src/pages/config/UserSettingsForm.tsx @@ -75,6 +75,10 @@ export function UserSettingsForm() { handleUpdate({ optInNextEditFeature: value }); }; + const handleEnableStaticContextualizationToggle = (value: boolean) => { + handleUpdate({ enableStaticContextualization: value }); + }; + useEffect(() => { // Necessary so that reformatted/trimmed values don't cause dirty state setFormPromptPath(promptPath); @@ -436,23 +440,18 @@ export function UserSettingsForm() { text="@Codebase: use tool calling only" /> - - handleUpdate({ - enableStaticContextualization: - !enableStaticContextualization, - }) - } - text="Use Static Contextualization" - /> - {hasContinueEmail && ( )} From 367e6672ca4de6eddf4f79816f8287d803744f13 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Mon, 7 Jul 2025 19:20:17 -0700 Subject: [PATCH 28/31] refactor: :art: format snippets so that it's more model prefix-friendly --- .../static-context/StaticContextService.ts | 32 +++++++++++++++---- core/autocomplete/snippets/types.ts | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index fb6919d35..b955a38ff 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -1,5 +1,6 @@ import * as fs from "fs/promises"; import path from "path"; +import { pathToFileURL } from "url"; import Parser from "web-tree-sitter"; import { IDE, Position } from "../../.."; import { localPathOrUriToPath } from "../../../util/pathToUri"; @@ -153,14 +154,33 @@ export class StaticContextService { this.logAutocompleteStaticSnippet(ctx); - console.log(end - start); + // console.log(end - start); - return [ - { + const snippets: AutocompleteStaticSnippet[] = []; + + snippets.push({ + type: AutocompleteSnippetType.Static, + filepath: pathToFileURL(path.resolve(holeContext.source)).toString(), + content: holeContext.fullHoverResult, + }); + + for (const [filepath, typs] of ctx.relevantTypes.entries()) { + snippets.push({ type: AutocompleteSnippetType.Static, - content: StaticContextService.formatAutocompleteStaticSnippet(ctx), - }, - ]; + filepath: pathToFileURL(path.resolve(filepath)).toString(), + content: typs.join("\n"), + }); + } + + for (const [filepath, headers] of ctx.relevantHeaders.entries()) { + snippets.push({ + type: AutocompleteSnippetType.Static, + filepath: pathToFileURL(path.resolve(filepath)).toString(), + content: headers.join("\n"), + }); + } + + return snippets; } private async getHoleContext( diff --git a/core/autocomplete/snippets/types.ts b/core/autocomplete/snippets/types.ts index c486c0106..be820609b 100644 --- a/core/autocomplete/snippets/types.ts +++ b/core/autocomplete/snippets/types.ts @@ -26,6 +26,7 @@ export interface AutocompleteClipboardSnippet extends BaseAutocompleteSnippet { export interface AutocompleteStaticSnippet extends BaseAutocompleteSnippet { type: AutocompleteSnippetType.Static; + filepath: string; } export type AutocompleteSnippet = From 9472bb1e4562e64e0ab4752aecbf4b3f1cb723bd Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 9 Jul 2025 21:07:31 -0700 Subject: [PATCH 29/31] bug: satisfy IDE --- core/protocol/ide.ts | 3 +++ core/protocol/messenger/messageIde.ts | 9 +++++++++ core/util/filesystem.ts | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index ba4cf4f88..c67b8c94a 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -10,6 +10,7 @@ import type { Problem, Range, RangeInFile, + SignatureHelp, TerminalOptions, Thread, } from "../"; @@ -82,6 +83,8 @@ export type ToIdeFromWebviewOrCoreProtocol = { getFileStats: [{ files: string[] }, FileStatsMap]; gotoDefinition: [{ location: Location }, RangeInFile[]]; + gotoTypeDefinition: [{ location: Location }, RangeInFile[]]; + getSignatureHelp: [{ location: Location }, SignatureHelp | null]; getControlPlaneSessionInfo: [ { silent: boolean; useOnboarding: boolean }, diff --git a/core/protocol/messenger/messageIde.ts b/core/protocol/messenger/messageIde.ts index 30d9b8177..2365117c0 100644 --- a/core/protocol/messenger/messageIde.ts +++ b/core/protocol/messenger/messageIde.ts @@ -13,6 +13,7 @@ import type { Problem, Range, RangeInFile, + SignatureHelp, TerminalOptions, Thread, } from "../.."; @@ -45,6 +46,14 @@ export class MessageIde implements IDE { return this.request("gotoDefinition", { location }); } + async gotoTypeDefinition(location: Location): Promise { + return this.request("gotoTypeDefinition", { location }); + } + + async getSignatureHelp(location: Location): Promise { + return this.request("getSignatureHelp", { location }); + } + onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void { this.on("didChangeActiveTextEditor", (data) => callback(data.filepath)); } diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index f415e5e86..959ea939f 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -13,6 +13,7 @@ import { Problem, Range, RangeInFile, + SignatureHelp, TerminalOptions, Thread, ToastType, @@ -44,6 +45,14 @@ class FileSystemIde implements IDE { return Promise.resolve([]); } + gotoTypeDefinition(location: Location): Promise { + return Promise.resolve([]); + } + + getSignatureHelp(location: Location): Promise { + return Promise.resolve(null); + } + onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void { return; } From 5b1848d2f179e7b078814260b86bfd33ebdd0ef1 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 9 Jul 2025 21:10:02 -0700 Subject: [PATCH 30/31] bump: version --- binary/package-lock.json | 2 ++ packages/config-yaml/package-lock.json | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index 51e6f5cf9..11dd6505b 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -121,6 +121,8 @@ "@babel/preset-env": "^7.24.7", "@biomejs/biome": "1.6.4", "@google/generative-ai": "^0.11.4", + "@shikijs/colorized-brackets": "^3.7.0", + "@shikijs/transformers": "^3.7.0", "@types/diff": "^7.0.1", "@types/follow-redirects": "^1.14.4", "@types/jest": "^29.5.12", diff --git a/packages/config-yaml/package-lock.json b/packages/config-yaml/package-lock.json index 014ecac95..51091ea04 100644 --- a/packages/config-yaml/package-lock.json +++ b/packages/config-yaml/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.95", + "version": "1.0.96", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/config-yaml", - "version": "1.0.95", + "version": "1.0.96", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", From b3e4d368bd457401eff9d5eb0f5713efa1f56b1e Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Thu, 10 Jul 2025 16:57:47 -0700 Subject: [PATCH 31/31] feat: remove logging code to telemetry --- core/autocomplete/util/AutocompleteLoggingService.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/autocomplete/util/AutocompleteLoggingService.ts b/core/autocomplete/util/AutocompleteLoggingService.ts index 4f600a8c5..58b3d2d0d 100644 --- a/core/autocomplete/util/AutocompleteLoggingService.ts +++ b/core/autocomplete/util/AutocompleteLoggingService.ts @@ -125,9 +125,6 @@ export class AutocompleteLoggingService { ? void Telemetry.capture("autocomplete", { ...toLog, enabledStaticContextualization: true, - prefix, - suffix, - prompt, }) : void Telemetry.capture("autocomplete", toLog); }