From 7105be0bee800d9a67cde3271866eacdac57b1d6 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 11 Nov 2024 19:37:24 -0800 Subject: [PATCH 01/86] .instructions file --- .instructions | 1 + core/config/getSystemPromptDotFile.ts | 27 +++++++++++++++++++ core/config/load.ts | 6 +++++ .../continue/IdeProtocolClient.kt | 2 +- extensions/vscode/package-lock.json | 4 +-- .../vscode/src/extension/VsCodeExtension.ts | 12 ++++++--- 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 .instructions create mode 100644 core/config/getSystemPromptDotFile.ts diff --git a/.instructions b/.instructions new file mode 100644 index 000000000..bad5d9689 --- /dev/null +++ b/.instructions @@ -0,0 +1 @@ +Give concise responses. diff --git a/core/config/getSystemPromptDotFile.ts b/core/config/getSystemPromptDotFile.ts new file mode 100644 index 000000000..ae6cd41f2 --- /dev/null +++ b/core/config/getSystemPromptDotFile.ts @@ -0,0 +1,27 @@ +import { IDE } from ".."; + +export const SYSTEM_PROMPT_DOT_FILE = ".instructions"; + +export async function getSystemPromptDotFile(ide: IDE): Promise { + const dirs = await ide.getWorkspaceDirs(); + + let prompts: string[] = []; + const pathSep = await ide.pathSep(); + for (const dir of dirs) { + const dotFile = `${dir}${pathSep}${SYSTEM_PROMPT_DOT_FILE}`; + if (await ide.fileExists(dotFile)) { + try { + const content = await ide.readFile(dotFile); + prompts.push(content); + } catch (e) { + // ignore if file doesn't exist + } + } + } + + if (!prompts.length) { + return null; + } + + return prompts.join("\n\n"); +} diff --git a/core/config/load.ts b/core/config/load.ts index a10948210..226e678f4 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -64,6 +64,7 @@ import { defaultSlashCommandsJetBrains, defaultSlashCommandsVscode, } from "./default"; +import { getSystemPromptDotFile } from "./getSystemPromptDotFile"; import { DEFAULT_PROMPTS_FOLDER, getPromptFiles, @@ -732,6 +733,11 @@ async function loadFullConfigNode( return { errors, config: undefined, configLoadInterrupted: true }; } + const systemPromptDotFile = await getSystemPromptDotFile(ide); + if (systemPromptDotFile) { + serialized.systemMessage = systemPromptDotFile; + } + // Convert serialized to intermediate config let intermediate = await serializedToIntermediateConfig(serialized, ide); diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index b773026bd..c2a35a918 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -105,7 +105,7 @@ class AsyncFileSaveListener(private val ideProtocolClient: IdeProtocolClient) : for (event in events) { if (event.path.endsWith(".continue/config.json") || event.path.endsWith(".continue/config.ts") || event.path.endsWith( ".continue\\config.json" - ) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json") + ) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json") || event.path.endsWith(".continuerc.json") ) { return object : AsyncFileListener.ChangeApplier { override fun afterVfsChange() { diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3f6ace66f..661eca42c 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.226", + "version": "0.9.227", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.226", + "version": "0.9.227", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index f8bc7c556..06e498c55 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -284,7 +284,8 @@ export class VsCodeExtension { if ( filepath.endsWith(".continuerc.json") || - filepath.endsWith(".prompt") + filepath.endsWith(".prompt") || + filepath.endsWith(".instructions") ) { this.configHandler.reloadConfig(); } else if ( @@ -296,14 +297,16 @@ export class VsCodeExtension { } else { // Reindex the file this.core.invoke("index/forceReIndex", { - dirs: [filepath] + dirs: [filepath], }); } }); vscode.workspace.onDidDeleteFiles(async (event) => { this.core.invoke("index/forceReIndex", { - dirs: event.files.map((file) => file.fsPath.split("/").slice(0, -1).join("/")) + dirs: event.files.map((file) => + file.fsPath.split("/").slice(0, -1).join("/"), + ), }); }); @@ -352,7 +355,8 @@ export class VsCodeExtension { // Register a content provider for the readonly virtual documents const documentContentProvider = new (class - implements vscode.TextDocumentContentProvider { + implements vscode.TextDocumentContentProvider + { // emitter and its event onDidChangeEmitter = new vscode.EventEmitter(); onDidChange = this.onDidChangeEmitter.event; From eadc96ebef6653a996dff32095fd87a86703058d Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 12 Nov 2024 13:31:13 -0800 Subject: [PATCH 02/86] feat: php definitions --- .../RootPathContextService.ts | 23 +++++ .../test/RootPathContextService.test.ts | 90 ++++++++++--------- .../root-path-context/test/files/file1.php | 32 +++++++ .../function_definition/php.scm | 10 +++ 4 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 core/autocomplete/context/root-path-context/test/files/file1.php create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index accd4f6df..6f163c265 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -9,6 +9,21 @@ import { AstPath } from "../../util/ast"; import { ImportDefinitionsService } from "../ImportDefinitionsService"; import { AutocompleteSnippet } from "../ranking"; +function getSyntaxTreeString( + node: Parser.SyntaxNode, + indent: string = "", +): string { + let result = ""; + const nodeInfo = `${node.type} [${node.startPosition.row}:${node.startPosition.column} - ${node.endPosition.row}:${node.endPosition.column}]`; + result += `${indent}${nodeInfo}\n`; + + for (const child of node.children) { + result += getSyntaxTreeString(child, indent + " "); + } + + return result; +} + export class RootPathContextService { private cache = new LRUCache({ max: 100, @@ -58,12 +73,17 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: + console.log(getSyntaxTreeString(node)); + query = await getQueryForFile( filepath, `root-path-context-queries/${node.type}`, ); break; } + const type = node.type; + + debugger; if (!query) { return snippets; @@ -115,6 +135,9 @@ export class RootPathContextService { RootPathContextService.TYPES_TO_USE.has(node.type), )) { const key = RootPathContextService.keyFromNode(parentKey, astNode); + const type = astNode.type; + + debugger; const foundInCache = this.cache.get(key); const newSnippets = diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index 196a7b643..f0af54a45 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -1,49 +1,59 @@ import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ - { - nodeType: "function_declaration", - fileName: "file1.ts", - language: "TypeScript", - cursorPosition: { line: 10, character: 24 }, - definitionPositions: [ - { row: 9, column: 34 }, // Person - { row: 9, column: 44 }, // Address - ], - }, - { - nodeType: "method_declaration", - fileName: "file1.ts", - language: "TypeScript", - cursorPosition: { line: 22, character: 30 }, - definitionPositions: [ - { row: 13, column: 29 }, // BaseClass - { row: 13, column: 55 }, // FirstInterface - { row: 13, column: 72 }, // SecondInterface - { row: 21, column: 33 }, // Person - { row: 21, column: 43 }, // Address - ], - }, + // { + // nodeType: "function_declaration", + // fileName: "file1.ts", + // language: "TypeScript", + // cursorPosition: { line: 10, character: 24 }, + // definitionPositions: [ + // { row: 9, column: 34 }, // Person + // { row: 9, column: 44 }, // Address + // ], + // }, + // { + // nodeType: "method_declaration", + // fileName: "file1.ts", + // language: "TypeScript", + // cursorPosition: { line: 22, character: 30 }, + // definitionPositions: [ + // { row: 13, column: 29 }, // BaseClass + // { row: 13, column: 55 }, // FirstInterface + // { row: 13, column: 72 }, // SecondInterface + // { row: 21, column: 33 }, // Person + // { row: 21, column: 43 }, // Address + // ], + // }, + // { + // nodeType: "function_definition", + // fileName: "file1.py", + // language: "Python", + // cursorPosition: { line: 4, character: 25 }, + // definitionPositions: [ + // { row: 3, column: 30 }, // Person + // { row: 3, column: 42 }, // Address + // ], + // }, + // { + // nodeType: "function_definition (inside a class)", + // fileName: "file1.py", + // language: "Python", + // cursorPosition: { line: 12, character: 33 }, + // definitionPositions: [ + // { row: 6, column: 21 }, // BaseClass + // { row: 6, column: 33 }, // Collection + // { row: 11, column: 47 }, // Person + // { row: 11, column: 59 }, // Address + // ], + // }, { nodeType: "function_definition", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 4, character: 25 }, + fileName: "file1.php", + language: "PHP", + cursorPosition: { line: 12, character: 32 }, definitionPositions: [ - { row: 3, column: 30 }, // Person - { row: 3, column: 42 }, // Address - ], - }, - { - nodeType: "function_definition (inside a class)", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 12, character: 33 }, - definitionPositions: [ - { row: 6, column: 21 }, // BaseClass - { row: 6, column: 33 }, // Collection - { row: 11, column: 47 }, // Person - { row: 11, column: 59 }, // Address + { row: 10, column: 26 }, // Person + { row: 10, column: 44 }, // Address ], }, ]; diff --git a/core/autocomplete/context/root-path-context/test/files/file1.php b/core/autocomplete/context/root-path-context/test/files/file1.php new file mode 100644 index 000000000..a72f805e0 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/file1.php @@ -0,0 +1,32 @@ +getAddress(); +} + +class Group extends BaseClass implements FirstInterface, SecondInterface +{ + private array $people; + + public function __construct(array $people) + { + parent::__construct(); + $this->people = $people; + } + + public function getPersonAddress(Person $person): Address + { + return getAddress($person); + } +} + +?> \ No newline at end of file diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm new file mode 100644 index 000000000..3f9303ae1 --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm @@ -0,0 +1,10 @@ +( + (function_definition + parameters: (formal_parameters + (simple_parameter + type: (named_type) @param_type + )* + ) + return_type: (named_type) @return_type + ) +) \ No newline at end of file From 0c74f936a3d1358f5d7d0a5a10ead73c7ac9d59d Mon Sep 17 00:00:00 2001 From: "Johnny.H" Date: Wed, 13 Nov 2024 19:11:02 +0800 Subject: [PATCH 03/86] Fix: https://github.com/continuedev/continue/issues/2896 --- .../activities/ContinuePluginStartupActivity.kt | 4 +--- .../continueintellijextension/continue/CoreMessenger.kt | 9 ++++++++- .../services/ContinuePluginService.kt | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt index 509bc44ce..fa39729fa 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt @@ -71,7 +71,6 @@ private fun getTutorialFileName(): String { } class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { - private val coroutineScope = CoroutineScope(Dispatchers.IO) override fun runActivity(project: Project) { removeShortcutFromAction(getPlatformSpecificKeyStroke("J")) @@ -110,6 +109,7 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { } private fun initializePlugin(project: Project) { + val coroutineScope = CoroutineScope(Dispatchers.IO) val continuePluginService = ServiceManager.getService( project, ContinuePluginService::class.java @@ -234,7 +234,5 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { } override fun dispose() { - // Cleanup resources here - coroutineScope.cancel() } } \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt index aaa6ce28d..178ae4059 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt @@ -19,7 +19,7 @@ class CoreMessenger( private val project: Project, continueCorePath: String, private val ideProtocolClient: IdeProtocolClient, - coroutineScope: CoroutineScope + val coroutineScope: CoroutineScope ) { private var writer: Writer? = null private var reader: BufferedReader? = null @@ -232,4 +232,11 @@ class CoreMessenger( } } } + + fun killSubProcess() { + process?.isAlive?.let { + exitCallbacks.clear() + process?.destroy() + } + } } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinuePluginService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinuePluginService.kt index 7318d2731..87b08f829 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinuePluginService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinuePluginService.kt @@ -34,6 +34,10 @@ class ContinuePluginService(project: Project) : Disposable, DumbAware { override fun dispose() { coroutineScope.cancel() + coreMessenger?.coroutineScope?.let { + it.cancel() + coreMessenger?.killSubProcess() + } } fun sendToWebview( From af26938a9916ae8057e806221fa6b23f03d8232d Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 13 Nov 2024 10:04:34 -0800 Subject: [PATCH 04/86] bugfix: get codeblocks for pretoolbar --- gui/src/components/markdown/StyledMarkdownPreview.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 77158e96a..a86a295c9 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -136,13 +136,12 @@ function processCodeBlocks(tree: any) { node.lang = node.lang.split(".").slice(-1)[0]; } + node.data = node.data || {}; + node.data.hProperties = node.data.hProperties || {}; + node.data.hProperties.codeBlockContent = node.value; + node.data.hProperties.isGeneratingCodeBlock = lastCodeNode === node; + if (node.meta) { - node.data = node.data || {}; - node.data.hProperties = node.data.hProperties || {}; - - node.data.hProperties.isGeneratingCodeBlock = lastCodeNode === node; - node.data.hProperties.codeBlockContent = node.value; - let meta = node.meta.split(" "); node.data.hProperties.filepath = meta[0]; node.data.hProperties.range = meta[1]; From 8da703f74525213dc212efa6b763d4be06dee38b Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 10:23:37 -0800 Subject: [PATCH 05/86] feat: php definitions --- .../RootPathContextService.ts | 12 +- .../test/RootPathContextService.test.ts | 103 ++++++++++-------- .../class_declaration/php.scm | 13 +++ .../method_declaration/php.scm | 10 ++ 4 files changed, 87 insertions(+), 51 deletions(-) create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 6f163c265..9c47138cd 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -43,6 +43,7 @@ export class RootPathContextService { "function_declaration", "function_definition", "method_definition", + "method_declaration", "class_declaration", "class_definition", ]); @@ -73,7 +74,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - console.log(getSyntaxTreeString(node)); + // const type = node.type; + // debugger; + // console.log(getSyntaxTreeString(node)); query = await getQueryForFile( filepath, @@ -83,8 +86,6 @@ export class RootPathContextService { } const type = node.type; - debugger; - if (!query) { return snippets; } @@ -135,9 +136,8 @@ export class RootPathContextService { RootPathContextService.TYPES_TO_USE.has(node.type), )) { const key = RootPathContextService.keyFromNode(parentKey, astNode); - const type = astNode.type; - - debugger; + // const type = astNode.type; + // debugger; const foundInCache = this.cache.get(key); const newSnippets = diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index f0af54a45..4bc099c28 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -1,51 +1,51 @@ import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ - // { - // nodeType: "function_declaration", - // fileName: "file1.ts", - // language: "TypeScript", - // cursorPosition: { line: 10, character: 24 }, - // definitionPositions: [ - // { row: 9, column: 34 }, // Person - // { row: 9, column: 44 }, // Address - // ], - // }, - // { - // nodeType: "method_declaration", - // fileName: "file1.ts", - // language: "TypeScript", - // cursorPosition: { line: 22, character: 30 }, - // definitionPositions: [ - // { row: 13, column: 29 }, // BaseClass - // { row: 13, column: 55 }, // FirstInterface - // { row: 13, column: 72 }, // SecondInterface - // { row: 21, column: 33 }, // Person - // { row: 21, column: 43 }, // Address - // ], - // }, - // { - // nodeType: "function_definition", - // fileName: "file1.py", - // language: "Python", - // cursorPosition: { line: 4, character: 25 }, - // definitionPositions: [ - // { row: 3, column: 30 }, // Person - // { row: 3, column: 42 }, // Address - // ], - // }, - // { - // nodeType: "function_definition (inside a class)", - // fileName: "file1.py", - // language: "Python", - // cursorPosition: { line: 12, character: 33 }, - // definitionPositions: [ - // { row: 6, column: 21 }, // BaseClass - // { row: 6, column: 33 }, // Collection - // { row: 11, column: 47 }, // Person - // { row: 11, column: 59 }, // Address - // ], - // }, + { + nodeType: "function_declaration", + fileName: "file1.ts", + language: "TypeScript", + cursorPosition: { line: 10, character: 24 }, + definitionPositions: [ + { row: 9, column: 34 }, // Person + { row: 9, column: 44 }, // Address + ], + }, + { + nodeType: "method_declaration", + fileName: "file1.ts", + language: "TypeScript", + cursorPosition: { line: 22, character: 30 }, + definitionPositions: [ + { row: 13, column: 29 }, // BaseClass + { row: 13, column: 55 }, // FirstInterface + { row: 13, column: 72 }, // SecondInterface + { row: 21, column: 33 }, // Person + { row: 21, column: 43 }, // Address + ], + }, + { + nodeType: "function_definition", + fileName: "file1.py", + language: "Python", + cursorPosition: { line: 4, character: 25 }, + definitionPositions: [ + { row: 3, column: 30 }, // Person + { row: 3, column: 42 }, // Address + ], + }, + { + nodeType: "function_definition (inside a class)", + fileName: "file1.py", + language: "Python", + cursorPosition: { line: 12, character: 33 }, + definitionPositions: [ + { row: 6, column: 21 }, // BaseClass + { row: 6, column: 33 }, // Collection + { row: 11, column: 47 }, // Person + { row: 11, column: 59 }, // Address + ], + }, { nodeType: "function_definition", fileName: "file1.php", @@ -56,6 +56,19 @@ const TEST_CASES = [ { row: 10, column: 44 }, // Address ], }, + { + nodeType: "function_definition (inside a class)", + fileName: "file1.php", + language: "PHP", + cursorPosition: { line: 26, character: 35 }, + definitionPositions: [ + { row: 15, column: 29 }, // BaseClass + { row: 15, column: 55 }, // FirstInterface + { row: 15, column: 72 }, // SecondInterface + { row: 25, column: 43 }, // Person + { row: 25, column: 61 }, // Address + ], + }, ]; describe("RootPathContextService", () => { diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm new file mode 100644 index 000000000..5e9a9c13e --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm @@ -0,0 +1,13 @@ +( + (class_declaration + (base_clause + (name) @superclass) + ) +) + +( + (class_declaration + (class_interface_clause + (name) @interface) + ) +) \ No newline at end of file diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm new file mode 100644 index 000000000..825324e01 --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm @@ -0,0 +1,10 @@ +( + (method_declaration + (formal_parameters + (simple_parameter + type: (named_type) @param_type + )* + ) + return_type: (named_type) @return_type + ) +) \ No newline at end of file From e0ae4ceb567d7288021259b2cd39ac68d138863b Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 11:11:47 -0800 Subject: [PATCH 06/86] test: go --- .../context/root-path-context/test/files/file1.go | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/autocomplete/context/root-path-context/test/files/file1.go diff --git a/core/autocomplete/context/root-path-context/test/files/file1.go b/core/autocomplete/context/root-path-context/test/files/file1.go new file mode 100644 index 000000000..94eec171c --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/file1.go @@ -0,0 +1,9 @@ +package main + +import ( + "core/autocomplete/context/root-path-context/test/files/models" +) + +func getAddress(user *models.User) *models.Address { + return user.Address +} \ No newline at end of file From a9e97fef9aab7cb4bf71812250d8340eab183076 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 11:15:46 -0800 Subject: [PATCH 07/86] fix uniqueId --- core/llm/llms/stubs/ContinueProxy.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index 0d04f77f5..97dec3a35 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -13,13 +13,14 @@ class ContinueProxy extends OpenAI { static providerName: ModelProvider = "continue-proxy"; static defaultOptions: Partial = { useLegacyCompletionsEndpoint: false, - requestOptions: { - headers: { - "x-continue-unique-id": Telemetry.uniqueId, - }, - }, }; + protected _getHeaders() { + const headers: any = super._getHeaders(); + headers["x-continue-unique-id"] = Telemetry.uniqueId; + return headers; + } + supportsCompletions(): boolean { return false; } From bf65b1ebbdd3b0913d141e9f60a11414088bc78f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 11:33:09 -0800 Subject: [PATCH 08/86] feat: go definitions --- .../test/RootPathContextService.test.ts | 12 +++++++++++- .../function_declaration/go.scm | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index 4bc099c28..58da8982a 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -57,7 +57,7 @@ const TEST_CASES = [ ], }, { - nodeType: "function_definition (inside a class)", + nodeType: "method_declaration", fileName: "file1.php", language: "PHP", cursorPosition: { line: 26, character: 35 }, @@ -69,6 +69,16 @@ const TEST_CASES = [ { row: 25, column: 61 }, // Address ], }, + { + nodeType: "function_declaration", + fileName: "file1.go", + language: "Go", + cursorPosition: { line: 7, character: 21 }, + definitionPositions: [ + { row: 6, column: 33 }, // models.User + { row: 6, column: 50 }, // models.Address + ], + }, ]; describe("RootPathContextService", () => { diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm new file mode 100644 index 000000000..482f50841 --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm @@ -0,0 +1,12 @@ +( + (function_declaration + (parameter_list + (parameter_declaration + type: (_) @param_type + )* + ) + ; Optional return type node before the block + ([_] @return_type)? + (block) + ) +) \ No newline at end of file From 28db3b683b34ae6f0ba87914f6bc95793c84adb5 Mon Sep 17 00:00:00 2001 From: Dmitry Sebastyansky Date: Wed, 13 Nov 2024 23:05:25 +0300 Subject: [PATCH 09/86] Fix an edge case when stop token is not filtered out. --- .../streamTransforms/charStream.test.ts | 16 ++++++++++++++++ .../filtering/streamTransforms/charStream.ts | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/autocomplete/filtering/streamTransforms/charStream.test.ts b/core/autocomplete/filtering/streamTransforms/charStream.test.ts index 7ab8923fc..b466ae3cd 100644 --- a/core/autocomplete/filtering/streamTransforms/charStream.test.ts +++ b/core/autocomplete/filtering/streamTransforms/charStream.test.ts @@ -157,4 +157,20 @@ describe("stopAtStopTokens", () => { expect(output.join("")).toBe("Hello world!"); }); + + it("should handle stop token when remaining buffer is smaller than maximum stop token length", async () => { + const mockStream = createMockStream(["Hello world!STOP"]); + const stopTokens: string[] = [ + "STOP", + "STOP_TOKEN_THAT_IS_LARGER_THAN_BUFFER", + ]; + const result = stopAtStopTokens(mockStream, stopTokens); + + const output = []; + for await (const char of result) { + output.push(char); + } + + expect(output.join("")).toBe("Hello world!"); + }); }); diff --git a/core/autocomplete/filtering/streamTransforms/charStream.ts b/core/autocomplete/filtering/streamTransforms/charStream.ts index 79fc33a0d..9f37e1f58 100644 --- a/core/autocomplete/filtering/streamTransforms/charStream.ts +++ b/core/autocomplete/filtering/streamTransforms/charStream.ts @@ -70,7 +70,8 @@ export async function* noFirstCharNewline(stream: AsyncGenerator) { * 2. Otherwise, buffers incoming chunks and checks for stop tokens. * 3. Yields characters one by one if no stop token is found at the start of the buffer. * 4. Stops yielding and returns if a stop token is encountered. - * 5. After the stream ends, yields any remaining buffered characters. + * 5. After the stream ends, filters encountered stop tokens in remaining buffer. + * 6. Yields any remaining buffered characters. */ export async function* stopAtStopTokens( stream: AsyncGenerator, @@ -106,6 +107,10 @@ export async function* stopAtStopTokens( } } } + // Filter out the possible stop tokens from remaining buffer + stopTokens.forEach((token) => { + buffer = buffer.replace(token, ""); + }); // Yield any remaining characters in the buffer for (const char of buffer) { From c6e827661919110ac67d486577579df48c6aa028 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 16:46:07 -0800 Subject: [PATCH 10/86] move prompts to .continue/prompts --- core/promptFiles/v2/createNewPromptFile.ts | 57 +++++++++++----------- core/promptFiles/v2/getPromptFiles.ts | 12 +++-- core/util/pathModule.ts | 13 +++++ core/util/paths.ts | 2 +- gui/src/components/find/FindWidget.tsx | 8 +-- 5 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 core/util/pathModule.ts diff --git a/core/promptFiles/v2/createNewPromptFile.ts b/core/promptFiles/v2/createNewPromptFile.ts index a8ea87109..21ff3c7c1 100644 --- a/core/promptFiles/v2/createNewPromptFile.ts +++ b/core/promptFiles/v2/createNewPromptFile.ts @@ -1,46 +1,42 @@ -import path from "path"; - import { IDE } from "../.."; import { GlobalContext } from "../../util/GlobalContext"; - -import { DEFAULT_PROMPTS_FOLDER_V2 } from "./getPromptFiles"; +import { getPathModuleForIde } from "../../util/pathModule"; const FIRST_TIME_DEFAULT_PROMPT_FILE = `# This is an example ".prompt" file # It is used to define and reuse prompts within Continue -# Continue will automatically create a context provider for each prompt in the .prompts folder +# Each .prompt file can be accessed by typing "@prompts" in the Chat input # A prompt file consists of two parts: # 1. Everything above the "---" is YAML. Here you can set "temperature", "description", and other options # 2. Everything below the "---" is the prompt body -# If you don't want to set any options, you don't need to include the "---" +# If you do not want to set any options, you do not need to include the "---" # In the body, you can reference: -# 1. Files, using either absolute or relative (based on the workspace root) paths - # e.g. @README.md - # e.g. @src/test/test.py - # e.g. @/Users/me/Desktop/my-project/src/test/test.py -# 2. URLs - # e.g. https://example.com -# 3. Some context providers, like - # e.g. @currentFile - # e.g. @os - # e.g. @repo-map +# 1. Files, using either absolute or relative paths (based on the workspace root) + # @README.md + # @src/test/test.py + # @/Users/me/Desktop/my-project/src/test/test.py +# 2. URLs, for example + # @https://example.com +# 3. Context providers, for example + # @currentFile + # @os + # @repo-map # To learn more, see the full .prompt file reference: https://docs.continue.dev/features/prompt-files name: Example + +# For example, here is how you would write a .prompt +name: Example description: Example prompt file -version: 2 ---- -@README.md - -Please reference the above README.md file to understand the current project. -`; - -const DEFAULT_PROMPT_FILE = `version: 2 --- -`; +Here is information about the current repo: + +@README.md`; + +const DEFAULT_PROMPT_FILE = ""; export async function createNewPromptFileV2( ide: IDE, @@ -52,9 +48,11 @@ export async function createNewPromptFileV2( "No workspace directories found. Make sure you've opened a folder in your IDE.", ); } - const baseDir = path.join( + const pathModule = await getPathModuleForIde(ide); + + const baseDir = pathModule.join( workspaceDirs[0], - promptPath ?? DEFAULT_PROMPTS_FOLDER_V2, + promptPath ?? pathModule.join(".continue", "prompts"), ); // Find the first available filename @@ -62,7 +60,10 @@ export async function createNewPromptFileV2( let promptFilePath: string; do { const suffix = counter === 0 ? "" : `-${counter}`; - promptFilePath = path.join(baseDir, `new-prompt-file${suffix}.prompt`); + promptFilePath = pathModule.join( + baseDir, + `new-prompt-file${suffix}.prompt`, + ); counter++; } while (await ide.fileExists(promptFilePath)); diff --git a/core/promptFiles/v2/getPromptFiles.ts b/core/promptFiles/v2/getPromptFiles.ts index c78068899..0353746be 100644 --- a/core/promptFiles/v2/getPromptFiles.ts +++ b/core/promptFiles/v2/getPromptFiles.ts @@ -1,7 +1,6 @@ -import path from "path"; - import { IDE } from "../.."; import { walkDir } from "../../indexing/walkDir"; +import { getPathModuleForIde } from "../../util/pathModule"; import { readAllGlobalPromptFiles } from "../../util/paths"; async function getPromptFilesFromDir( @@ -27,20 +26,23 @@ async function getPromptFilesFromDir( } } -export const DEFAULT_PROMPTS_FOLDER_V2 = ".prompts"; - export async function getAllPromptFilesV2( ide: IDE, overridePromptFolder?: string, ): Promise<{ path: string; content: string }[]> { const workspaceDirs = await ide.getWorkspaceDirs(); let promptFiles: { path: string; content: string }[] = []; + const pathModule = await getPathModuleForIde(ide); + promptFiles = ( await Promise.all( workspaceDirs.map((dir) => getPromptFilesFromDir( ide, - path.join(dir, overridePromptFolder ?? DEFAULT_PROMPTS_FOLDER_V2), + pathModule.join( + dir, + overridePromptFolder ?? pathModule.join(".continue", "prompts"), + ), ), ), ) diff --git a/core/util/pathModule.ts b/core/util/pathModule.ts new file mode 100644 index 000000000..8b06ab56c --- /dev/null +++ b/core/util/pathModule.ts @@ -0,0 +1,13 @@ +import { PlatformPath, posix, win32 } from "node:path"; +import { IDE } from ".."; + +export type PathSep = "/" | "\\"; + +function getPathModuleFromPathSep(pathSep: PathSep): PlatformPath { + return pathSep === "/" ? posix : win32; +} + +export async function getPathModuleForIde(ide: IDE): Promise { + const pathSep = await ide.pathSep(); + return getPathModuleFromPathSep(pathSep as PathSep); +} diff --git a/core/util/paths.ts b/core/util/paths.ts index f8b70159f..d606f095d 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -327,7 +327,7 @@ export function getPromptLogsPath(): string { } export function getGlobalPromptsPath(): string { - return path.join(getContinueGlobalPath(), ".prompts"); + return path.join(getContinueGlobalPath(), "prompts"); } export function readAllGlobalPromptFiles( diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx index 266a09cd8..60a9bf2a9 100644 --- a/gui/src/components/find/FindWidget.tsx +++ b/gui/src/components/find/FindWidget.tsx @@ -389,7 +389,7 @@ export const useFindWidget = (searchRef: RefObject) => { e.stopPropagation(); previousMatch(); }} - className="h-4 w-4 focus:ring focus:ring-1" + className="h-4 w-4 focus:ring" disabled={matches.length < 2 || active} > @@ -401,7 +401,7 @@ export const useFindWidget = (searchRef: RefObject) => { e.stopPropagation(); nextMatch(); }} - className="h-4 w-4 focus:ring focus:ring-1" + className="h-4 w-4 focus:ring" disabled={matches.length < 2 || active} > @@ -420,7 +420,7 @@ export const useFindWidget = (searchRef: RefObject) => { e.stopPropagation(); setCaseSensitive((curr) => !curr); }} - className="h-5 w-6 rounded-full border text-xs focus:outline-none focus:ring focus:ring-1" + className="h-5 w-6 rounded-full border text-xs focus:outline-none focus:ring" > Aa @@ -428,7 +428,7 @@ export const useFindWidget = (searchRef: RefObject) => { setOpen(false)} - className="focus:ring focus:ring-1" + className="focus:ring" > From bb4f9154ccbb5be7b045c376f249783f76342cea Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 16:54:39 -0800 Subject: [PATCH 11/86] don't require context providers to be in config.json for prompt files --- core/promptFiles/v2/renderPromptFile.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/promptFiles/v2/renderPromptFile.ts b/core/promptFiles/v2/renderPromptFile.ts index bb70b19a2..89b36b0a8 100644 --- a/core/promptFiles/v2/renderPromptFile.ts +++ b/core/promptFiles/v2/renderPromptFile.ts @@ -1,7 +1,7 @@ import { ContextItem, ContextProviderExtras } from "../.."; +import { contextProviderClassFromName } from "../../context/providers"; import URLContextProvider from "../../context/providers/URLContextProvider"; import { getBasename } from "../../util"; - import { getPreambleAndBody } from "./parse"; async function resolveAttachment( @@ -15,6 +15,13 @@ async function resolveAttachment( if (contextProvider) { const items = await contextProvider.getContextItems("", extras); return items; + } else { + // Just instantiate it here + const providerClass = contextProviderClassFromName(name) as any; + if (providerClass) { + const providerInstance = new providerClass({}); + return providerInstance.getContextItems("", extras); + } } // Files From 1e98e366fc2abc16b225bc262a93e1ef10c35f36 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 16:56:56 -0800 Subject: [PATCH 12/86] .continuerules --- core/config/getSystemPromptDotFile.ts | 2 +- extensions/vscode/src/extension/VsCodeExtension.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/config/getSystemPromptDotFile.ts b/core/config/getSystemPromptDotFile.ts index ae6cd41f2..03690dd47 100644 --- a/core/config/getSystemPromptDotFile.ts +++ b/core/config/getSystemPromptDotFile.ts @@ -1,6 +1,6 @@ import { IDE } from ".."; -export const SYSTEM_PROMPT_DOT_FILE = ".instructions"; +export const SYSTEM_PROMPT_DOT_FILE = ".continuerules"; export async function getSystemPromptDotFile(ide: IDE): Promise { const dirs = await ide.getWorkspaceDirs(); diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 06e498c55..06263e356 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -37,6 +37,7 @@ import { VsCodeIde } from "../VsCodeIde"; import { VsCodeMessenger } from "./VsCodeMessenger"; +import { SYSTEM_PROMPT_DOT_FILE } from "core/config/getSystemPromptDotFile"; import type { VsCodeWebviewProtocol } from "../webviewProtocol"; export class VsCodeExtension { @@ -285,7 +286,7 @@ export class VsCodeExtension { if ( filepath.endsWith(".continuerc.json") || filepath.endsWith(".prompt") || - filepath.endsWith(".instructions") + filepath.endsWith(SYSTEM_PROMPT_DOT_FILE) ) { this.configHandler.reloadConfig(); } else if ( From 1296ed6b3f677ccb090afbc788896f824e3a65de Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 17:00:16 -0800 Subject: [PATCH 13/86] bump package.json, update changelog --- .changes/unreleased/Added-20241113-165958.yaml | 4 ++++ .changes/unreleased/Added-20241113-170006.yaml | 4 ++++ extensions/vscode/CHANGELOG.md | 9 +++++++-- extensions/vscode/package.json | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Added-20241113-165958.yaml create mode 100644 .changes/unreleased/Added-20241113-170006.yaml diff --git a/.changes/unreleased/Added-20241113-165958.yaml b/.changes/unreleased/Added-20241113-165958.yaml new file mode 100644 index 000000000..95aaa7c70 --- /dev/null +++ b/.changes/unreleased/Added-20241113-165958.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Added +body: .continuerules file to set system prompt +time: 2024-11-13T16:59:58.544875-08:00 diff --git a/.changes/unreleased/Added-20241113-170006.yaml b/.changes/unreleased/Added-20241113-170006.yaml new file mode 100644 index 000000000..bc254f8d9 --- /dev/null +++ b/.changes/unreleased/Added-20241113-170006.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Added +body: .prompt files v2 +time: 2024-11-13T17:00:06.855468-08:00 diff --git a/extensions/vscode/CHANGELOG.md b/extensions/vscode/CHANGELOG.md index 88925e7f4..8dac5cd8c 100644 --- a/extensions/vscode/CHANGELOG.md +++ b/extensions/vscode/CHANGELOG.md @@ -7,8 +7,6 @@ and is generated by [Changie](https://github.com/miniscruff/changie). Pre-release Changes ### Added -* New Edit mode in sidebar (cmd/ctrl+I) -* Significantly faster and more accurate docs crawler by default * OpenAI predicted outputs support * Improve codebase retrieval with BM25 * Support for Grok from xAI @@ -19,12 +17,19 @@ Pre-release Changes * Improved reference for config.json * New @web context provider * Updates for llama3.2 +* .continuerules file to set system prompt +* .prompt files v2 ### Changed * Improved @docs crawler * Many improvements to make autocomplete more eager ### Fixed * Brought back the Apply button for all code blocks +## 0.8.56 - 2024-11-08 +### Added +* New Edit mode in sidebar (cmd/ctrl+I) +* Significantly faster and more accurate docs crawler by default + ## 0.8.55 - 2024-10-25 ### Added * Web context provider diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 30828f300..2ecfb4768 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.228", + "version": "0.9.229", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From eb5140fa8b286697d049e8f8b9b6cc824d8439b7 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 17:09:24 -0800 Subject: [PATCH 14/86] auto-assign to everyone --- .github/workflows/auto-assign.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-assign.yaml b/.github/workflows/auto-assign.yaml index 3108307e5..dc5388ef3 100644 --- a/.github/workflows/auto-assign.yaml +++ b/.github/workflows/auto-assign.yaml @@ -14,7 +14,7 @@ jobs: uses: pozil/auto-assign-issue@v2 with: repo-token: ${{ secrets.CI_GITHUB_TOKEN }} - assignees: sestinj,Patrick-Erichsen + assignees: sestinj,Patrick-Erichsen,tomasz-stefaniak,RomneyDa numOfAssignee: 1 - name: "Add default labels" uses: actions-ecosystem/action-add-labels@v1 From 430b74951949c5e3a52cf4b01df3f06a5c9ae497 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 15:26:12 -0800 Subject: [PATCH 15/86] improv: more robust definitions for typescript --- .../test/RootPathContextService.test.ts | 25 +- .../test/files/{file1.ts => class.ts} | 18 +- .../root-path-context/test/files/file2.ts | 260 ++++++++++++++++++ .../root-path-context/test/files/functions.ts | 13 + .../test/testCases/typescript.ts | 71 +++++ .../function_declaration/typescript.scm | 36 ++- .../method_definition/typescript.scm | 40 ++- 7 files changed, 421 insertions(+), 42 deletions(-) rename core/autocomplete/context/root-path-context/test/files/{file1.ts => class.ts} (54%) create mode 100644 core/autocomplete/context/root-path-context/test/files/file2.ts create mode 100644 core/autocomplete/context/root-path-context/test/files/functions.ts create mode 100644 core/autocomplete/context/root-path-context/test/testCases/typescript.ts diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index 58da8982a..fe81a0edd 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -1,29 +1,8 @@ +import { TYPESCRIPT_TEST_CASES } from "./testCases/typescript"; import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ - { - nodeType: "function_declaration", - fileName: "file1.ts", - language: "TypeScript", - cursorPosition: { line: 10, character: 24 }, - definitionPositions: [ - { row: 9, column: 34 }, // Person - { row: 9, column: 44 }, // Address - ], - }, - { - nodeType: "method_declaration", - fileName: "file1.ts", - language: "TypeScript", - cursorPosition: { line: 22, character: 30 }, - definitionPositions: [ - { row: 13, column: 29 }, // BaseClass - { row: 13, column: 55 }, // FirstInterface - { row: 13, column: 72 }, // SecondInterface - { row: 21, column: 33 }, // Person - { row: 21, column: 43 }, // Address - ], - }, + ...TYPESCRIPT_TEST_CASES, { nodeType: "function_definition", fileName: "file1.py", diff --git a/core/autocomplete/context/root-path-context/test/files/file1.ts b/core/autocomplete/context/root-path-context/test/files/class.ts similarity index 54% rename from core/autocomplete/context/root-path-context/test/files/file1.ts rename to core/autocomplete/context/root-path-context/test/files/class.ts index ba09c5709..017b592ae 100644 --- a/core/autocomplete/context/root-path-context/test/files/file1.ts +++ b/core/autocomplete/context/root-path-context/test/files/class.ts @@ -7,10 +7,6 @@ import { // @ts-ignore } from "./types"; -function getAddress(person: Person): Address { - return person.address; -} - class Group extends BaseClass implements FirstInterface, SecondInterface { people: Person[]; @@ -20,6 +16,18 @@ class Group extends BaseClass implements FirstInterface, SecondInterface { } getPersonAddress(person: Person): Address { - return getAddress(person); + return person.address; + } + + getHardcodedAddress(): Address { + return { street: "123 Main St", city: "Anytown" }; + } + + addPerson(person: Person) { + this.people = [...this.people, person]; + } + + addPeople(people: Person[]) { + this.people = [...this.people, ...people]; } } diff --git a/core/autocomplete/context/root-path-context/test/files/file2.ts b/core/autocomplete/context/root-path-context/test/files/file2.ts new file mode 100644 index 000000000..124b76bff --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/file2.ts @@ -0,0 +1,260 @@ +// @ts-nocheck +import { IProtocol } from "core/protocol/index.js"; +import { IMessenger, type Message } from "core/util/messenger"; +import { ChildProcessWithoutNullStreams } from "node:child_process"; +import * as fs from "node:fs"; +import net from "node:net"; +import { v4 as uuidv4 } from "uuid"; + +class IPCMessengerBase< + ToProtocol extends IProtocol, + FromProtocol extends IProtocol, +> implements IMessenger +{ + _sendMsg(message: Message) { + throw new Error("Not implemented"); + } + + typeListeners = new Map any)[]>(); + idListeners = new Map any>(); + + private _handleLine(line: string) { + try { + const msg: Message = JSON.parse(line); + if (msg.messageType === undefined || msg.messageId === undefined) { + throw new Error("Invalid message sent: " + JSON.stringify(msg)); + } + + // Call handler and respond with return value + const listeners = this.typeListeners.get(msg.messageType as any); + listeners?.forEach(async (handler) => { + try { + const response = await handler(msg); + if ( + response && + typeof response[Symbol.asyncIterator] === "function" + ) { + for await (const update of response) { + this.send(msg.messageType, update, msg.messageId); + } + this.send(msg.messageType, { done: true }, msg.messageId); + } else { + this.send(msg.messageType, response, msg.messageId); + } + } catch (e: any) { + console.warn(`Error running handler for "${msg.messageType}": `, e); + this._onErrorHandlers.forEach((handler) => { + handler(e); + }); + } + }); + + // Call handler which is waiting for the response, nothing to return + this.idListeners.get(msg.messageId)?.(msg); + } catch (e) { + let truncatedLine = line; + if (line.length > 200) { + truncatedLine = + line.substring(0, 100) + "..." + line.substring(line.length - 100); + } + console.error("Error parsing line: ", truncatedLine, e); + return; + } + } + + private _unfinishedLine: string | undefined = undefined; + protected _handleData(data: Buffer) { + const d = data.toString(); + const lines = d.split(/\r\n/).filter((line) => line.trim() !== ""); + if (lines.length === 0) { + return; + } + + if (this._unfinishedLine) { + lines[0] = this._unfinishedLine + lines[0]; + this._unfinishedLine = undefined; + } + if (!d.endsWith("\r\n")) { + this._unfinishedLine = lines.pop(); + } + lines.forEach((line) => this._handleLine(line)); + } + + private _onErrorHandlers: ((error: Error) => void)[] = []; + + onError(handler: (error: Error) => void) { + this._onErrorHandlers.push(handler); + } + + request( + messageType: T, + data: FromProtocol[T][0], + ): Promise { + const messageId = uuidv4(); + return new Promise((resolve) => { + const handler = (msg: Message) => { + resolve(msg.data); + this.idListeners.delete(messageId); + }; + this.idListeners.set(messageId, handler); + this.send(messageType, data, messageId); + }); + } + + mock(data: any) { + const d = JSON.stringify(data); + this._handleData(Buffer.from(d)); + } + + send( + messageType: T, + data: FromProtocol[T][0], + messageId?: string, + ): string { + messageId = messageId ?? uuidv4(); + const msg: Message = { + messageType: messageType as string, + data, + messageId, + }; + this._sendMsg(msg); + return messageId; + } + + invoke( + messageType: T, + data: ToProtocol[T][0], + ): ToProtocol[T][1] { + return this.typeListeners.get(messageType)?.[0]?.({ + messageId: uuidv4(), + messageType: messageType as string, + data, + }); + } + + on( + messageType: T, + handler: ( + message: Message, + ) => Promise | ToProtocol[T][1], + ): void { + if (!this.typeListeners.has(messageType)) { + this.typeListeners.set(messageType, []); + } + this.typeListeners.get(messageType)?.push(handler); + } +} + +export class IpcMessenger< + ToProtocol extends IProtocol, + FromProtocol extends IProtocol, + > + extends IPCMessengerBase + implements IMessenger +{ + constructor() { + super(); + console.log("Setup"); + process.stdin.on("data", (data) => { + // console.log("[info] Received data: ", data.toString()); + this._handleData(data); + }); + process.stdout.on("close", () => { + fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`); + console.log("[info] Exiting Continue core..."); + process.exit(1); + }); + process.stdin.on("close", () => { + fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`); + console.log("[info] Exiting Continue core..."); + process.exit(1); + }); + } + _sendMsg(msg: Message) { + const d = JSON.stringify(msg); + // console.log("[info] Sending message: ", d); + process.stdout?.write(d + "\r\n"); + } +} + +export class CoreBinaryMessenger< + ToProtocol extends IProtocol, + FromProtocol extends IProtocol, + > + extends IPCMessengerBase + implements IMessenger +{ + private errorHandler: (error: Error) => void = () => {}; + private messageHandlers: Map< + keyof ToProtocol, + (message: Message) => Promise | any + > = new Map(); + + constructor(private readonly subprocess: ChildProcessWithoutNullStreams) { + super(); + console.log("Setup"); + this.subprocess.stdout.on("data", (data) => { + console.log("[info] Received data from core:", data.toString() + "\n"); + this._handleData(data); + }); + this.subprocess.stdout.on("close", () => { + console.log("[info] Continue core exited"); + }); + this.subprocess.stdin.on("close", () => { + console.log("[info] Continue core exited"); + }); + } + + _sendMsg(msg: Message) { + console.log("[info] Sending message to core:", msg); + const d = JSON.stringify(msg); + this.subprocess.stdin.write(d + "\r\n"); + } +} + +export class CoreBinaryTcpMessenger< + ToProtocol extends IProtocol, + FromProtocol extends IProtocol, + > + extends IPCMessengerBase + implements IMessenger +{ + private port: number = 3000; + private socket: net.Socket | null = null; + + typeListeners = new Map any)[]>(); + idListeners = new Map any>(); + + constructor() { + super(); + const socket = net.createConnection(this.port, "localhost"); + + this.socket = socket; + socket.on("data", (data: Buffer) => { + // console.log("[info] Received data from core:", data.toString() + "\n"); + this._handleData(data); + }); + + socket.on("end", () => { + console.log("Disconnected from server"); + }); + + socket.on("error", (err: any) => { + console.error("Client error:", err); + }); + } + + close() { + this.socket?.end(); + } + + _sendMsg(msg: Message) { + if (this.socket) { + // console.log("[info] Sending message to core:", msg); + const d = JSON.stringify(msg); + this.socket.write(d + "\r\n"); + } else { + console.error("Socket is not connected"); + } + } +} diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts new file mode 100644 index 000000000..8ae6944e9 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -0,0 +1,13 @@ +import { + Address, + Person, + // @ts-ignore +} from "./types"; + +function getAddress(person: Person): Address { + return person.address; +} + +function getFirstAddress(people: Person[]): Address { + return people[0].address; +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts new file mode 100644 index 000000000..2eb589c90 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -0,0 +1,71 @@ +export const TYPESCRIPT_TEST_CASES = [ + { + nodeType: "function_declaration with a param and a return type", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 7, character: 24 }, + definitionPositions: [ + { row: 6, column: 34 }, // Person + { row: 6, column: 44 }, // Address + ], + }, + { + nodeType: "function_declaration with array param", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 11, character: 27 }, + definitionPositions: [ + { row: 10, column: 39 }, // Person + { row: 10, column: 51 }, // Address + ], + }, + { + nodeType: "method_declaration", + fileName: "class.ts", + language: "TypeScript", + cursorPosition: { line: 18, character: 26 }, + definitionPositions: [ + { row: 9, column: 29 }, // BaseClass + { row: 9, column: 55 }, // FirstInterface + { row: 9, column: 72 }, // SecondInterface + { row: 17, column: 33 }, // Person + { row: 17, column: 43 }, // Address + ], + }, + { + nodeType: "method_declaration without arguments", + fileName: "class.ts", + language: "TypeScript", + cursorPosition: { line: 22, character: 54 }, + definitionPositions: [ + { row: 9, column: 29 }, // BaseClass + { row: 9, column: 55 }, // FirstInterface + { row: 9, column: 72 }, // SecondInterface + { row: 21, column: 32 }, // Address + ], + }, + { + nodeType: "method_declaration without return type", + fileName: "class.ts", + language: "TypeScript", + cursorPosition: { line: 26, character: 43 }, + definitionPositions: [ + { row: 9, column: 29 }, // BaseClass + { row: 9, column: 55 }, // FirstInterface + { row: 9, column: 72 }, // SecondInterface + { row: 25, column: 26 }, // Person + ], + }, + { + nodeType: "method_declaration with array type arguments", + fileName: "class.ts", + language: "TypeScript", + cursorPosition: { line: 30, character: 46 }, + definitionPositions: [ + { row: 9, column: 29 }, // BaseClass + { row: 9, column: 55 }, // FirstInterface + { row: 9, column: 72 }, // SecondInterface + { row: 29, column: 26 }, // Person + ], + }, +]; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm index ab10968a3..24dc04e22 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm @@ -1,10 +1,34 @@ +; Pattern for capturing the return type ( - (function_declaration - (formal_parameters - (_ - (type_annotation) @param_type - ) + (function_declaration + (type_annotation) @return_type + ) +) + +; Pattern for parameters with direct type_identifier +( + (function_declaration + (formal_parameters + (_ + (type_annotation + (type_identifier) @param_type ) - (type_annotation) @return_type + ) ) + ) +) + +; Pattern for parameters with one level of nesting +( + (function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) ) \ No newline at end of file diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm index 727db5090..9f8685385 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm @@ -1,10 +1,34 @@ +; Pattern for capturing the return type ( - (method_definition - (formal_parameters - (_ - (type_annotation) @param_type - ) - ) - (type_annotation) @return_type - ) + (method_definition + (type_annotation) @return_type + ) +) + +; Pattern for parameters with direct type_identifier +( + (method_definition + (formal_parameters + (_ + (type_annotation + (type_identifier) @param_type + ) + ) + ) + ) +) + +; Pattern for parameters with one level of nesting +( + (method_definition + (formal_parameters + (_ + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) ) From 41ac57fa408eebb09c90781a4cf8b3092a6191ee Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 17:14:13 -0800 Subject: [PATCH 16/86] test: typescript definitions --- .../root-path-context/test/files/functions.ts | 12 ++++++++++++ .../test/testCases/typescript.ts | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index 8ae6944e9..2b6125a74 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -11,3 +11,15 @@ function getAddress(person: Person): Address { function getFirstAddress(people: Person[]): Address { return people[0].address; } + +function logPerson(person: Person) { + console.log(`Name: ${person.name}, Age: ${person.age}`); +} + +function getHardcodedAddress(): Address { + return { street: "123 Main St", city: "Anytown", zipCode: "12345" }; +} + +function getAddresses(people: Person[]): Address[] { + return people[0].address; +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 2eb589c90..6913cb8d3 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -19,6 +19,24 @@ export const TYPESCRIPT_TEST_CASES = [ { row: 10, column: 51 }, // Address ], }, + { + nodeType: "function_declaration without return type", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 15, character: 58 }, + definitionPositions: [ + { row: 14, column: 33 }, // Person + ], + }, + { + nodeType: "function_declaration without params", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 19, character: 70 }, + definitionPositions: [ + { row: 18, column: 39 }, // Person + ], + }, { nodeType: "method_declaration", fileName: "class.ts", From 0599c52267b68d936ed328e42a99114fcfbf2dde Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 17:22:37 -0800 Subject: [PATCH 17/86] cleanup: remove unused file --- .../root-path-context/test/files/file2.ts | 260 ------------------ 1 file changed, 260 deletions(-) delete mode 100644 core/autocomplete/context/root-path-context/test/files/file2.ts diff --git a/core/autocomplete/context/root-path-context/test/files/file2.ts b/core/autocomplete/context/root-path-context/test/files/file2.ts deleted file mode 100644 index 124b76bff..000000000 --- a/core/autocomplete/context/root-path-context/test/files/file2.ts +++ /dev/null @@ -1,260 +0,0 @@ -// @ts-nocheck -import { IProtocol } from "core/protocol/index.js"; -import { IMessenger, type Message } from "core/util/messenger"; -import { ChildProcessWithoutNullStreams } from "node:child_process"; -import * as fs from "node:fs"; -import net from "node:net"; -import { v4 as uuidv4 } from "uuid"; - -class IPCMessengerBase< - ToProtocol extends IProtocol, - FromProtocol extends IProtocol, -> implements IMessenger -{ - _sendMsg(message: Message) { - throw new Error("Not implemented"); - } - - typeListeners = new Map any)[]>(); - idListeners = new Map any>(); - - private _handleLine(line: string) { - try { - const msg: Message = JSON.parse(line); - if (msg.messageType === undefined || msg.messageId === undefined) { - throw new Error("Invalid message sent: " + JSON.stringify(msg)); - } - - // Call handler and respond with return value - const listeners = this.typeListeners.get(msg.messageType as any); - listeners?.forEach(async (handler) => { - try { - const response = await handler(msg); - if ( - response && - typeof response[Symbol.asyncIterator] === "function" - ) { - for await (const update of response) { - this.send(msg.messageType, update, msg.messageId); - } - this.send(msg.messageType, { done: true }, msg.messageId); - } else { - this.send(msg.messageType, response, msg.messageId); - } - } catch (e: any) { - console.warn(`Error running handler for "${msg.messageType}": `, e); - this._onErrorHandlers.forEach((handler) => { - handler(e); - }); - } - }); - - // Call handler which is waiting for the response, nothing to return - this.idListeners.get(msg.messageId)?.(msg); - } catch (e) { - let truncatedLine = line; - if (line.length > 200) { - truncatedLine = - line.substring(0, 100) + "..." + line.substring(line.length - 100); - } - console.error("Error parsing line: ", truncatedLine, e); - return; - } - } - - private _unfinishedLine: string | undefined = undefined; - protected _handleData(data: Buffer) { - const d = data.toString(); - const lines = d.split(/\r\n/).filter((line) => line.trim() !== ""); - if (lines.length === 0) { - return; - } - - if (this._unfinishedLine) { - lines[0] = this._unfinishedLine + lines[0]; - this._unfinishedLine = undefined; - } - if (!d.endsWith("\r\n")) { - this._unfinishedLine = lines.pop(); - } - lines.forEach((line) => this._handleLine(line)); - } - - private _onErrorHandlers: ((error: Error) => void)[] = []; - - onError(handler: (error: Error) => void) { - this._onErrorHandlers.push(handler); - } - - request( - messageType: T, - data: FromProtocol[T][0], - ): Promise { - const messageId = uuidv4(); - return new Promise((resolve) => { - const handler = (msg: Message) => { - resolve(msg.data); - this.idListeners.delete(messageId); - }; - this.idListeners.set(messageId, handler); - this.send(messageType, data, messageId); - }); - } - - mock(data: any) { - const d = JSON.stringify(data); - this._handleData(Buffer.from(d)); - } - - send( - messageType: T, - data: FromProtocol[T][0], - messageId?: string, - ): string { - messageId = messageId ?? uuidv4(); - const msg: Message = { - messageType: messageType as string, - data, - messageId, - }; - this._sendMsg(msg); - return messageId; - } - - invoke( - messageType: T, - data: ToProtocol[T][0], - ): ToProtocol[T][1] { - return this.typeListeners.get(messageType)?.[0]?.({ - messageId: uuidv4(), - messageType: messageType as string, - data, - }); - } - - on( - messageType: T, - handler: ( - message: Message, - ) => Promise | ToProtocol[T][1], - ): void { - if (!this.typeListeners.has(messageType)) { - this.typeListeners.set(messageType, []); - } - this.typeListeners.get(messageType)?.push(handler); - } -} - -export class IpcMessenger< - ToProtocol extends IProtocol, - FromProtocol extends IProtocol, - > - extends IPCMessengerBase - implements IMessenger -{ - constructor() { - super(); - console.log("Setup"); - process.stdin.on("data", (data) => { - // console.log("[info] Received data: ", data.toString()); - this._handleData(data); - }); - process.stdout.on("close", () => { - fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`); - console.log("[info] Exiting Continue core..."); - process.exit(1); - }); - process.stdin.on("close", () => { - fs.writeFileSync("./error.log", `${new Date().toISOString()}\n`); - console.log("[info] Exiting Continue core..."); - process.exit(1); - }); - } - _sendMsg(msg: Message) { - const d = JSON.stringify(msg); - // console.log("[info] Sending message: ", d); - process.stdout?.write(d + "\r\n"); - } -} - -export class CoreBinaryMessenger< - ToProtocol extends IProtocol, - FromProtocol extends IProtocol, - > - extends IPCMessengerBase - implements IMessenger -{ - private errorHandler: (error: Error) => void = () => {}; - private messageHandlers: Map< - keyof ToProtocol, - (message: Message) => Promise | any - > = new Map(); - - constructor(private readonly subprocess: ChildProcessWithoutNullStreams) { - super(); - console.log("Setup"); - this.subprocess.stdout.on("data", (data) => { - console.log("[info] Received data from core:", data.toString() + "\n"); - this._handleData(data); - }); - this.subprocess.stdout.on("close", () => { - console.log("[info] Continue core exited"); - }); - this.subprocess.stdin.on("close", () => { - console.log("[info] Continue core exited"); - }); - } - - _sendMsg(msg: Message) { - console.log("[info] Sending message to core:", msg); - const d = JSON.stringify(msg); - this.subprocess.stdin.write(d + "\r\n"); - } -} - -export class CoreBinaryTcpMessenger< - ToProtocol extends IProtocol, - FromProtocol extends IProtocol, - > - extends IPCMessengerBase - implements IMessenger -{ - private port: number = 3000; - private socket: net.Socket | null = null; - - typeListeners = new Map any)[]>(); - idListeners = new Map any>(); - - constructor() { - super(); - const socket = net.createConnection(this.port, "localhost"); - - this.socket = socket; - socket.on("data", (data: Buffer) => { - // console.log("[info] Received data from core:", data.toString() + "\n"); - this._handleData(data); - }); - - socket.on("end", () => { - console.log("Disconnected from server"); - }); - - socket.on("error", (err: any) => { - console.error("Client error:", err); - }); - } - - close() { - this.socket?.end(); - } - - _sendMsg(msg: Message) { - if (this.socket) { - // console.log("[info] Sending message to core:", msg); - const d = JSON.stringify(msg); - this.socket.write(d + "\r\n"); - } else { - console.error("Socket is not connected"); - } - } -} From b22ec1259c541ed3926cea8e988091f267962f96 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 17:53:04 -0800 Subject: [PATCH 18/86] improv: capture nested return type identifiers --- .../test/testCases/typescript.ts | 10 ++++++++++ .../function_declaration/typescript.scm | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 6913cb8d3..3aa9050d3 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -37,6 +37,16 @@ export const TYPESCRIPT_TEST_CASES = [ { row: 18, column: 39 }, // Person ], }, + { + nodeType: "function_declaration with array params and array return type", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 23, character: 27 }, + definitionPositions: [ + { row: 22, column: 36 }, // Person + { row: 22, column: 48 }, // Person + ], + }, { nodeType: "method_declaration", fileName: "class.ts", diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm index 24dc04e22..fac63a3d2 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm @@ -1,10 +1,24 @@ -; Pattern for capturing the return type +; Pattern for return type with direct type_identifier ( (function_declaration - (type_annotation) @return_type + (type_annotation + (type_identifier) @return_type + ) ) ) +; Pattern for return type with one level of nesting +( + (function_declaration + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) +) + + ; Pattern for parameters with direct type_identifier ( (function_declaration From bfd9d8e8dd1b1aae5fcdd909e7411497153fde70 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 17:59:27 -0800 Subject: [PATCH 19/86] improv: capture nested return types --- .../root-path-context/test/files/class.ts | 4 ++++ .../test/testCases/typescript.ts | 16 +++++++++++++++- .../method_definition/typescript.scm | 17 +++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/files/class.ts b/core/autocomplete/context/root-path-context/test/files/class.ts index 017b592ae..b2bd4ec78 100644 --- a/core/autocomplete/context/root-path-context/test/files/class.ts +++ b/core/autocomplete/context/root-path-context/test/files/class.ts @@ -30,4 +30,8 @@ class Group extends BaseClass implements FirstInterface, SecondInterface { addPeople(people: Person[]) { this.people = [...this.people, ...people]; } + + getAddresses(people: Person[]): Address[] { + return people.map((person) => person.address); + } } diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 3aa9050d3..2454af54e 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -48,7 +48,7 @@ export const TYPESCRIPT_TEST_CASES = [ ], }, { - nodeType: "method_declaration", + nodeType: "method_declaration with a param and a return type", fileName: "class.ts", language: "TypeScript", cursorPosition: { line: 18, character: 26 }, @@ -96,4 +96,18 @@ export const TYPESCRIPT_TEST_CASES = [ { row: 29, column: 26 }, // Person ], }, + { + nodeType: + "method_declaration with array type arguments and array type return", + fileName: "class.ts", + language: "TypeScript", + cursorPosition: { line: 34, character: 50 }, + definitionPositions: [ + { row: 9, column: 29 }, // BaseClass + { row: 9, column: 55 }, // FirstInterface + { row: 9, column: 72 }, // SecondInterface + { row: 33, column: 29 }, // Person + { row: 33, column: 41 }, // Address + ], + }, ]; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm index 9f8685385..545d11d97 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm @@ -1,7 +1,20 @@ -; Pattern for capturing the return type +; Pattern for return type with direct type_identifier ( (method_definition - (type_annotation) @return_type + (type_annotation + (type_identifier) @return_type + ) + ) +) + +; Pattern for return type with one level of nesting +( + (method_definition + (type_annotation + (_ + (type_identifier) @param_type + ) + ) ) ) From 079a33bba83492646eb829e81d75b14dda6a1fae Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 13 Nov 2024 18:06:54 -0800 Subject: [PATCH 20/86] improv: capture generic return types and arguments --- .../root-path-context/test/files/functions.ts | 7 +++++ .../test/testCases/typescript.ts | 15 +++++++++- .../function_declaration/typescript.scm | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index 2b6125a74..ec6e0dec1 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -23,3 +23,10 @@ function getHardcodedAddress(): Address { function getAddresses(people: Person[]): Address[] { return people[0].address; } + +function logPersonWithAddress(person: Person
): Person
{ + console.log( + `Name: ${person.name}, Age: ${person.age}, Address: ${person.address.street}`, + ); + return person; +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 2454af54e..4dbe61cf2 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -44,7 +44,20 @@ export const TYPESCRIPT_TEST_CASES = [ cursorPosition: { line: 23, character: 27 }, definitionPositions: [ { row: 22, column: 36 }, // Person - { row: 22, column: 48 }, // Person + { row: 22, column: 48 }, // Address + ], + }, + { + nodeType: + "function_declaration with generic params and generic return type", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 14 }, + definitionPositions: [ + { row: 26, column: 44 }, // Person + { row: 26, column: 52 }, // Address + { row: 26, column: 62 }, // Person + { row: 26, column: 70 }, // Address ], }, { diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm index fac63a3d2..52b62f9bd 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm @@ -18,6 +18,18 @@ ) ) +; Pattern for return type with two levels of nesting +( + (function_declaration + (type_annotation + (_ + (_ + (type_identifier) @return_type + ) + ) + ) + ) +) ; Pattern for parameters with direct type_identifier ( @@ -45,4 +57,21 @@ ) ) ) +) + +; Pattern for parameters with two levels of nesting +( + (function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) + ) ) \ No newline at end of file From 9ff547ec371fa9b0cf8905306a6cb657c97230cd Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 13 Nov 2024 23:37:16 -0800 Subject: [PATCH 21/86] bump okhttp version --- extensions/intellij/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/intellij/build.gradle.kts b/extensions/intellij/build.gradle.kts index 4c6aba783..afe24b719 100644 --- a/extensions/intellij/build.gradle.kts +++ b/extensions/intellij/build.gradle.kts @@ -25,7 +25,7 @@ repositories { mavenCentral() } // https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog dependencies { // implementation(libs.annotations) - implementation("com.squareup.okhttp3:okhttp:4.9.2") { + implementation("com.squareup.okhttp3:okhttp:4.12.0") { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") } implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.32") From 48c0caec7b83a222d1a214c3c1b38ff80a8280d1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:46 +0000 Subject: [PATCH 22/86] build(deps): bump @75lb/deep-merge from 1.1.1 to 1.1.2 in /binary Bumps [@75lb/deep-merge](https://github.com/75lb/deep-merge) from 1.1.1 to 1.1.2. - [Commits](https://github.com/75lb/deep-merge/compare/v1.1.1...v1.1.2) --- updated-dependencies: - dependency-name: "@75lb/deep-merge" dependency-type: indirect ... Signed-off-by: dependabot[bot] --- binary/package-lock.json | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index 0d67a4725..056231b31 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -74,7 +74,7 @@ "jsdom": "^24.0.0", "launchdarkly-node-client-sdk": "^3.2.0", "llm-code-highlighter": "^0.0.14", - "lru-cache": "^10.2.2", + "lru-cache": "^11.0.2", "mac-ca": "^3.1.0", "node-fetch": "^3.3.2", "node-html-markdown": "^1.3.0", @@ -99,6 +99,7 @@ "vectordb": "^0.4.20", "web-tree-sitter": "^0.21.0", "win-ca": "^3.5.1", + "wink-nlp-utils": "^2.1.0", "workerpool": "^9.1.3", "yaml": "^2.4.2", "zod": "^3.23.8" @@ -135,12 +136,12 @@ } }, "node_modules/@75lb/deep-merge": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.1.tgz", - "integrity": "sha512-xvgv6pkMGBA6GwdyJbNAnDmfAIR/DfWhrj9jgWh3TY7gRm3KO46x/GPjRg6wJ0nOepwqrNxFfojebh0Df4h4Tw==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.2.tgz", + "integrity": "sha512-08K9ou5VNbheZFxM5tDWoqjA3ImC50DiuuJ2tj1yEPRfkp8lLLg6XAaJ4On+a0yAXor/8ay5gHnAIshRM44Kpw==", "peer": true, "dependencies": { - "lodash.assignwith": "^4.2.0", + "lodash": "^4.17.21", "typical": "^7.1.1" }, "engines": { @@ -5037,10 +5038,10 @@ "node": ">=8" } }, - "node_modules/lodash.assignwith": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.assignwith/-/lodash.assignwith-4.2.0.tgz", - "integrity": "sha512-ZznplvbvtjK2gMvnQ1BR/zqPFZmS6jbK4p+6Up4xcRYA7yMIwxHCfbTcrYxXKzzqLsQ05eJPVznEW3tuwV7k1g==", + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "peer": true }, "node_modules/lodash.camelcase": { From d06f5f105ebd749bb83c60627d82826cfcfcef82 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:46 +0000 Subject: [PATCH 23/86] build(deps-dev): bump braces from 3.0.2 to 3.0.3 in /binary Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] --- binary/package-lock.json | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index 0d67a4725..cf8565b95 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -74,7 +74,7 @@ "jsdom": "^24.0.0", "launchdarkly-node-client-sdk": "^3.2.0", "llm-code-highlighter": "^0.0.14", - "lru-cache": "^10.2.2", + "lru-cache": "^11.0.2", "mac-ca": "^3.1.0", "node-fetch": "^3.3.2", "node-html-markdown": "^1.3.0", @@ -99,6 +99,7 @@ "vectordb": "^0.4.20", "web-tree-sitter": "^0.21.0", "win-ca": "^3.5.1", + "wink-nlp-utils": "^2.1.0", "workerpool": "^9.1.3", "yaml": "^2.4.2", "zod": "^3.23.8" @@ -2749,12 +2750,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -3545,9 +3546,9 @@ "optional": true }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" From 90a31ea2119d388161b7c3f9481b1b8f5a17402f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:51 +0000 Subject: [PATCH 24/86] build(deps): bump micromatch from 4.0.6 to 4.0.8 in /core Bumps [micromatch](https://github.com/micromatch/micromatch) from 4.0.6 to 4.0.8. - [Release notes](https://github.com/micromatch/micromatch/releases) - [Changelog](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/micromatch/compare/4.0.6...4.0.8) --- updated-dependencies: - dependency-name: micromatch dependency-type: indirect ... Signed-off-by: dependabot[bot] --- core/package-lock.json | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index 633d60c99..eb634c849 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -11068,28 +11068,17 @@ } }, "node_modules/micromatch": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.6.tgz", - "integrity": "sha512-Y4Ypn3oujJYxJcMacVgcs92wofTHxp9FzfDpQON4msDefoC0lb3ETvQLOdLcbhSwU1bz8HrL/1sygfBIHudrkQ==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dependencies": { "braces": "^3.0.3", - "picomatch": "^4.0.2" + "picomatch": "^2.3.1" }, "engines": { "node": ">=8.6" } }, - "node_modules/micromatch/node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -12253,7 +12242,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, From fc917238efb144ea08472bc4c2d197b5a4c1668f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:51 +0000 Subject: [PATCH 25/86] build(deps): bump ws and engine.io-client in /core Bumps [ws](https://github.com/websockets/ws) and [engine.io-client](https://github.com/socketio/socket.io). These dependencies needed to be updated together. Updates `ws` from 8.11.0 to 8.18.0 - [Release notes](https://github.com/websockets/ws/releases) - [Commits](https://github.com/websockets/ws/compare/8.11.0...8.18.0) Updates `engine.io-client` from 6.5.3 to 6.5.4 - [Release notes](https://github.com/socketio/socket.io/releases) - [Changelog](https://github.com/socketio/socket.io/blob/main/CHANGELOG.md) - [Commits](https://github.com/socketio/socket.io/commits) --- updated-dependencies: - dependency-name: ws dependency-type: indirect - dependency-name: engine.io-client dependency-type: indirect ... Signed-off-by: dependabot[bot] --- core/package-lock.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index 633d60c99..d81a435f6 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -7331,27 +7331,27 @@ } }, "node_modules/engine.io-client": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.3.tgz", - "integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.4.tgz", + "integrity": "sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==", "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0", + "ws": "~8.17.1", "xmlhttprequest-ssl": "~2.0.0" } }, "node_modules/engine.io-client/node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { From 6128a3d0ec2f277958ca926e48f64421e04624e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:52 +0000 Subject: [PATCH 26/86] build(deps): bump mysql2 from 3.9.7 to 3.11.4 in /core Bumps [mysql2](https://github.com/sidorares/node-mysql2) from 3.9.7 to 3.11.4. - [Release notes](https://github.com/sidorares/node-mysql2/releases) - [Changelog](https://github.com/sidorares/node-mysql2/blob/master/Changelog.md) - [Commits](https://github.com/sidorares/node-mysql2/compare/v3.9.7...v3.11.4) --- updated-dependencies: - dependency-name: mysql2 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- core/package-lock.json | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index 633d60c99..e7ed25ca8 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -5832,6 +5832,14 @@ "node": "*" } }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/aws4": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.0.tgz", @@ -10910,6 +10918,20 @@ "node": "20 || >=22" } }, + "node_modules/lru.min": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.1.tgz", + "integrity": "sha512-FbAj6lXil6t8z4z3j0E5mfRlPzxkySotzUHwRXjlpRh10vc6AI6WN62ehZj82VG7M20rqogJ0GLwar2Xa05a8Q==", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/mac-ca": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/mac-ca/-/mac-ca-3.1.0.tgz", @@ -11293,15 +11315,16 @@ } }, "node_modules/mysql2": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.7.tgz", - "integrity": "sha512-KnJT8vYRcNAZv73uf9zpXqNbvBG7DJrs+1nACsjZP1HMJ1TgXEy8wnNilXAn/5i57JizXKtrUtwDB7HxT9DDpw==", + "version": "3.11.4", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.4.tgz", + "integrity": "sha512-Z2o3tY4Z8EvSRDwknaC40MdZ3+m0sKbpnXrShQLdxPrAvcNli7jLrD2Zd2IzsRMw4eK9Yle500FDmlkIqp+krg==", "dependencies": { + "aws-ssl-profiles": "^1.1.1", "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", "long": "^5.2.1", - "lru-cache": "^8.0.0", + "lru.min": "^1.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" @@ -11310,14 +11333,6 @@ "node": ">= 8.0" } }, - "node_modules/mysql2/node_modules/lru-cache": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", - "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", - "engines": { - "node": ">=16.14" - } - }, "node_modules/named-placeholders": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", From 85e0f1c50c4272b2c7fac8620a2b1abc72bcd851 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 07:41:54 +0000 Subject: [PATCH 27/86] build(deps): bump @75lb/deep-merge from 1.1.1 to 1.1.2 in /core Bumps [@75lb/deep-merge](https://github.com/75lb/deep-merge) from 1.1.1 to 1.1.2. - [Commits](https://github.com/75lb/deep-merge/compare/v1.1.1...v1.1.2) --- updated-dependencies: - dependency-name: "@75lb/deep-merge" dependency-type: indirect ... Signed-off-by: dependabot[bot] --- core/package-lock.json | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index 633d60c99..677fc002f 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -101,12 +101,12 @@ } }, "node_modules/@75lb/deep-merge": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.1.tgz", - "integrity": "sha512-xvgv6pkMGBA6GwdyJbNAnDmfAIR/DfWhrj9jgWh3TY7gRm3KO46x/GPjRg6wJ0nOepwqrNxFfojebh0Df4h4Tw==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.2.tgz", + "integrity": "sha512-08K9ou5VNbheZFxM5tDWoqjA3ImC50DiuuJ2tj1yEPRfkp8lLLg6XAaJ4On+a0yAXor/8ay5gHnAIshRM44Kpw==", "peer": true, "dependencies": { - "lodash.assignwith": "^4.2.0", + "lodash": "^4.17.21", "typical": "^7.1.1" }, "engines": { @@ -10868,12 +10868,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "node_modules/lodash.assignwith": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.assignwith/-/lodash.assignwith-4.2.0.tgz", - "integrity": "sha512-ZznplvbvtjK2gMvnQ1BR/zqPFZmS6jbK4p+6Up4xcRYA7yMIwxHCfbTcrYxXKzzqLsQ05eJPVznEW3tuwV7k1g==", - "peer": true - }, "node_modules/lodash.camelcase": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", From c0f03b9f70a598f58726556876020202df9d0f3b Mon Sep 17 00:00:00 2001 From: Vadim Zhamkov Date: Thu, 14 Nov 2024 17:32:50 +0100 Subject: [PATCH 28/86] Add more models to Nebius provider. Add more models to models list --- gui/src/pages/AddNewModel/configs/models.ts | 93 ++++++++++++++++++- .../pages/AddNewModel/configs/providers.ts | 17 +++- 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/gui/src/pages/AddNewModel/configs/models.ts b/gui/src/pages/AddNewModel/configs/models.ts index 67c3547a7..01293f87a 100644 --- a/gui/src/pages/AddNewModel/configs/models.ts +++ b/gui/src/pages/AddNewModel/configs/models.ts @@ -169,6 +169,19 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["deepseek"], isOpenSource: false, }, + deepseekCoder2Lite: { + title: "DeepSeek Coder 2 Lite", + description: + "DeepSeek-Coder-V2-Lite-Instruct is an open-source code language model that supports 338 programming languages and offers a context length of up to 128,000 tokens.", + params: { + title: "DeepSeek-2-lite", + model: "deepseek-2-lite", + contextLength: 128_000, + }, + icon: "deepseek.png", + providerOptions: ["nebius"], + isOpenSource: true, + }, mistralOs: { title: "Mistral", description: @@ -359,6 +372,18 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["groq"], isOpenSource: false, }, + llama3170bNemotron: { + title: "Llama 3.1 Nemotron 70B", + description: + "Llama-3.1-Nemotron-70B-Instruct is a large language model customized by NVIDIA to improve the helpfulness of LLM generated responses to user queries.", + params: { + title: "Llama 3.1 Nemotron 70B", + model: "llama3.1-70b-nemotron", + contextLength: 128_000, + }, + icon: "meta.png", + isOpenSource: true, + }, llama321bChat: { title: "Llama3.2 1b Chat", description: @@ -628,6 +653,18 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["mistral", "askSage"], isOpenSource: false, }, + mistralNemo: { + title: "Mistral Nemo", + description: + "Mistral Nemo Instruct is a large language model developed by Mistral AI and NVIDIA.", + params: { + title: "Mistral Nemo", + model: "mistral-nemo", + contextLength: 128_000, + }, + icon: "mistral.png", + isOpenSource: true, + }, geminiPro: { title: "Gemini Pro", description: "A highly capable model created by Google DeepMind", @@ -979,7 +1016,6 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["vertexai"], isOpenSource: false, }, - gpt4gov: { title: "GPT-4 gov", description: @@ -1048,6 +1084,61 @@ export const models: { [key: string]: ModelPackage } = { providerOptions: ["xAI"], isOpenSource: false, }, + gemma2_2b: { + title: "Gemma 2 2b IT", + description: + "Gemma 2 IT instruction-tuned language model developed by Google, designed for tasks like question answering, summarization, and reasoning.", + params: { + title: "Gemma 2 2b IT", + model: "gemma2-2b-it", + contextLength: 4000, + }, + isOpenSource: true, + }, + gemma2_9b: { + title: "Gemma 2 9b IT", + description: + "Gemma 2 IT instruction-tuned language model developed by Google, designed for tasks like question answering, summarization, and reasoning.", + params: { + title: "Gemma 2 9b IT", + model: "gemma2-9b-it", + contextLength: 8000, + }, + isOpenSource: true, + }, + phi3mini: { + title: "Microsoft Phi 3 mini", + description: + "Phi 3 Mini is a 3.8-billion-parameter language model developed by Microsoft.", + params: { + title: "Microsoft Phi 3 mini", + model: "phi-3-mini", + contextLength: 4000, + }, + isOpenSource: true, + }, + phi3medium: { + title: "Microsoft Phi 3 medium", + description: + "Phi 3 Medium is a 14-billion-parameter language model developed by Microsoft.", + params: { + title: "Microsoft Phi 3 medium", + model: "phi-3-medium", + contextLength: 128_000, + }, + isOpenSource: true, + }, + olmo7b: { + title: "OLMo 7b", + description: + "OLMo 7B Instruct HF is a 7-billion-parameter language model by the Allen Institute for AI, fine-tuned for question answering tasks.", + params: { + title: "OLMo 7b", + model: "olmo-7b", + contextLength: 2000, + }, + isOpenSource: true, + }, AUTODETECT: { title: "Autodetect", description: diff --git a/gui/src/pages/AddNewModel/configs/providers.ts b/gui/src/pages/AddNewModel/configs/providers.ts index 39613731b..5047fbad0 100644 --- a/gui/src/pages/AddNewModel/configs/providers.ts +++ b/gui/src/pages/AddNewModel/configs/providers.ts @@ -744,7 +744,22 @@ To get started, [register](https://dataplatform.cloud.ibm.com/registration/stepo ], icon: "nebius.png", tags: [ModelProviderTags.RequiresApiKey, ModelProviderTags.OpenSource], - packages: [models.llama31Chat, models.Qwen2Coder, models.mistralOs], + packages: [ + models.llama318bChat, + models.llama3170bChat, + models.llama31405bChat, + models.llama3170bNemotron, + models.mistral8x7b, + models.mistral8x22b, + models.mistralNemo, + models.phi3mini, + models.phi3medium, + models.gemma2_2b, + models.gemma2_9b, + models.Qwen2Coder, + models.deepseekCoder2Lite, + models.olmo7b, + ], apiKeyUrl: "https://studio.nebius.ai/settings/api-keys", }, }; From 39a8e158cf737910cd4950d947bb5e439ec7de6d Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 08:48:44 -0800 Subject: [PATCH 29/86] only override cmd+shift+enter/backspae when diff visible --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3f4123969..24930d980 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 2ecfb4768..1bf96e316 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -331,12 +331,14 @@ { "command": "continue.acceptDiff", "mac": "shift+cmd+enter", - "key": "shift+ctrl+enter" + "key": "shift+ctrl+enter", + "when": "continue.diffVisible" }, { "command": "continue.rejectDiff", "mac": "shift+cmd+backspace", - "key": "shift+ctrl+backspace" + "key": "shift+ctrl+backspace", + "when": "continue.diffVisible" }, { "command": "continue.rejectDiff", From be88863c914d529959f599ba23f04c876f581181 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 10:01:24 -0800 Subject: [PATCH 30/86] bunch of logs --- extensions/vscode/package-lock.json | 4 ++-- gui/src/redux/slices/stateSlice.ts | 28 ++++++++++++++++++++++++++++ gui/src/redux/slices/uiStateSlice.ts | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3f4123969..24930d980 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index e3ce22eb6..f2cbe8dc9 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -83,6 +83,8 @@ export const stateSlice = createSlice({ state, { payload: config }: PayloadAction, ) => { + console.log("setConfig"); + const defaultModelTitle = config.models.find((model) => model.title === state.defaultModelTitle) ?.title || @@ -101,6 +103,8 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction, ) => { + console.log("addPromptCompletionPair"); + if (!state.history.length) { return; } @@ -139,11 +143,14 @@ export const stateSlice = createSlice({ contextItems: ChatHistoryItem["contextItems"]; }>, ) => { + console.log("setContextItemsAtIndex"); if (state.history[index]) { state.history[index].contextItems = contextItems; } }, addContextItems: (state, action: PayloadAction) => { + console.log("addContextItems"); + state.contextItems = state.contextItems.concat(action.payload); }, resubmitAtIndex: ( @@ -155,6 +162,8 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { + console.log("resubmitAtIndex"); + const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -188,6 +197,8 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { + console.log("initNewActiveMessage"); + state.history.push({ message: { role: "user", content: "", id: uuidv4() }, contextItems: state.contextItems, @@ -215,6 +226,7 @@ export const stateSlice = createSlice({ contextItems?: ContextItemWithId[]; }>, ) => { + console.log("setMessageAtIndex"); if (payload.index >= state.history.length) { state.history.push({ message: { ...payload.message, id: uuidv4() }, @@ -246,6 +258,8 @@ export const stateSlice = createSlice({ contextItems: ContextItemWithId[]; }>, ) => { + console.log("addContextItemsAtIndex"); + const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -257,6 +271,8 @@ export const stateSlice = createSlice({ state.active = false; }, streamUpdate: (state, action: PayloadAction) => { + console.log("streamUpdate"); + if (state.history.length) { state.history[state.history.length - 1].message.content += action.payload; @@ -267,6 +283,8 @@ export const stateSlice = createSlice({ { payload }: PayloadAction, ) => { if (payload) { + console.log("newSession"); + state.history = payload.history as any; state.title = payload.title; state.sessionId = payload.sessionId; @@ -285,6 +303,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, ) => { + console.log("deleteContextWithIds"); + const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`; const ids = new Set(payload.ids.map(getKey)); @@ -304,6 +324,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { + console.log("addHighlightedCode"); + let contextItems = [...state.contextItems].map((item) => { return { ...item, editing: false }; }); @@ -367,6 +389,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, ) => { + console.log("setEditingAtIds"); + const ids = payload.ids.map((id) => id.itemId); if (typeof payload.index === "undefined") { @@ -403,6 +427,8 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction<{ title: string; force?: boolean }>, ) => { + console.log("setDefaultModel"); + const model = state.config.models.find( (model) => model.title === payload.title, ); @@ -413,6 +439,8 @@ export const stateSlice = createSlice({ }; }, setSelectedProfileId: (state, { payload }: PayloadAction) => { + console.log("setSelectedProfileId"); + return { ...state, selectedProfileId: payload, diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index 24c4fc194..385964881 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -58,6 +58,7 @@ export const uiStateSlice = createSlice({ state.nextCodeBlockToApplyIndex++; }, updateApplyState: (state, { payload }: PayloadAction) => { + console.log("updateApplyState"); const index = state.applyStates.findIndex( (applyState) => applyState.streamId === payload.streamId, ); From 084fde1e341a3a2de9105c00f037c2975df63c55 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 10:48:22 -0800 Subject: [PATCH 31/86] comment --- gui/src/components/mainInput/handleMetaKeyPress.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gui/src/components/mainInput/handleMetaKeyPress.ts b/gui/src/components/mainInput/handleMetaKeyPress.ts index fd122350f..e01a48715 100644 --- a/gui/src/components/mainInput/handleMetaKeyPress.ts +++ b/gui/src/components/mainInput/handleMetaKeyPress.ts @@ -1,6 +1,6 @@ +import { Editor } from "@tiptap/react"; import { KeyboardEvent } from "react"; import { isWebEnvironment } from "../../util"; -import { Editor } from "@tiptap/react"; const isWebEnv = isWebEnvironment(); @@ -46,6 +46,10 @@ export const handleJetBrainsMetaKeyPress = ( } }; +/** + * We use this for VS Code to fix an .ipynb bug + * And we use it in JetBrains when OSR is turned on + */ export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => { const text = editor.state.doc.textBetween( editor.state.selection.from, From 5de52c8c4f95832caa80cda0275099500e7a20ef Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 10:30:49 -0800 Subject: [PATCH 32/86] test: hardcode gotoDefinition --- .../RootPathContextService.ts | 18 +++++++++--------- core/util/filesystem.ts | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 9c47138cd..2602b5acf 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -90,15 +90,15 @@ export class RootPathContextService { return snippets; } - await Promise.all( - query.matches(node).map(async (match) => { - for (const item of match.captures) { - const endPosition = item.node.endPosition; - const newSnippets = await this.getSnippets(filepath, endPosition); - snippets.push(...newSnippets); - } - }), - ); + const queries = query.matches(node).map(async (match) => { + for (const item of match.captures) { + const endPosition = item.node.endPosition; + const newSnippets = await this.getSnippets(filepath, endPosition); + snippets.push(...newSnippets); + } + }); + + await Promise.all(queries); return snippets; } diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index de71c15e2..42900edb5 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -20,7 +20,7 @@ import { GetGhTokenArgs } from "../protocol/ide.js"; import { getContinueGlobalPath } from "./paths.js"; class FileSystemIde implements IDE { - constructor(private readonly workspaceDir: string) { } + constructor(private readonly workspaceDir: string) {} showToast( type: ToastType, message: string, @@ -36,7 +36,7 @@ class FileSystemIde implements IDE { } gotoDefinition(location: Location): Promise { - throw new Error("Method not implemented."); + return Promise.resolve([]); } onDidChangeActiveTextEditor(callback: (filepath: string) => void): void { return; From 8a4684d762aa8a00c3423612a1a53dc12a208e12 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 10:58:40 -0800 Subject: [PATCH 33/86] bugfix: OSR copy/paste bugs --- core/protocol/ideWebview.ts | 1 + .../toolWindow/ContinueBrowser.kt | 10 ++++---- gui/src/components/mainInput/TipTapEditor.tsx | 23 ++++++++++--------- ...MetaKeyPress.ts => handleMetaKeyIssues.ts} | 15 ++++++++++-- 4 files changed, 32 insertions(+), 17 deletions(-) rename gui/src/components/mainInput/{handleMetaKeyPress.ts => handleMetaKeyIssues.ts} (88%) diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 040f4445d..d34b01d12 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -37,6 +37,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { insertAtCursor: [{ text: string }, void]; copyText: [{ text: string }, void]; "jetbrains/editorInsetHeight": [{ height: number }, void]; + "jetbrains/isOSREnabled": [boolean, void]; "vscode/openMoveRightMarkdown": [undefined, void]; setGitHubAuthToken: [{ token: string }, void]; acceptDiff: [{ filepath: string }, void]; diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 7891a02dc..bd76f910b 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -18,8 +18,6 @@ import kotlinx.coroutines.* import org.cef.CefApp import org.cef.browser.CefBrowser import org.cef.handler.CefLoadHandlerAdapter -import com.intellij.openapi.application.ApplicationInfo -import com.intellij.openapi.util.SystemInfo class ContinueBrowser(val project: Project, url: String) { private val coroutineScope = CoroutineScope( @@ -79,8 +77,8 @@ class ContinueBrowser(val project: Project, url: String) { val browser: JBCefBrowser init { - val enableOSR = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR - this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(enableOSR).build() + val isOSREnabled = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR + this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(isOSREnabled).build() browser.jbCefClient.setProperty( @@ -136,6 +134,10 @@ class ContinueBrowser(val project: Project, url: String) { heightChangeListeners.forEach { it(height) } } + "jetbrains/isOSREnabled" -> { + respond(isOSREnabled) + } + "onLoad" -> { coroutineScope.launch { // Set the colors to match Intellij theme diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index c2646415e..0c5f36dd8 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -60,9 +60,9 @@ import { getSlashCommandDropdownOptions, } from "./getSuggestion"; import { - handleJetBrainsMetaKeyPress, - handleMetaKeyPress, -} from "./handleMetaKeyPress"; + handleJetBrainsOSRMetaKeyIssues, + handleVSCMetaKeyIssues, +} from "./handleMetaKeyIssues"; import { ComboBoxItem } from "./types"; const InputBoxDiv = styled.div<{ border?: string }>` @@ -551,17 +551,18 @@ function TipTapEditor(props: TipTapEditorProps) { * with those key actions. */ const handleKeyDown = async (e: KeyboardEvent) => { - if (!editorFocusedRef?.current) return; - setActiveKey(e.key); - // Handle meta key issues - if (isMetaEquivalentKeyPressed(e)) { - if (isJetBrains()) { - handleJetBrainsMetaKeyPress(e, editor); - } + if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return; - await handleMetaKeyPress(e, editor); + const isOSREnabled = isJetBrains() + ? await ideMessenger.request("jetbrains/isOSREnabled", undefined) + : false; + + if (isOSREnabled) { + handleJetBrainsOSRMetaKeyIssues(e, editor); + } else { + await handleVSCMetaKeyIssues(e, editor); } }; diff --git a/gui/src/components/mainInput/handleMetaKeyPress.ts b/gui/src/components/mainInput/handleMetaKeyIssues.ts similarity index 88% rename from gui/src/components/mainInput/handleMetaKeyPress.ts rename to gui/src/components/mainInput/handleMetaKeyIssues.ts index fd122350f..90a994f60 100644 --- a/gui/src/components/mainInput/handleMetaKeyPress.ts +++ b/gui/src/components/mainInput/handleMetaKeyIssues.ts @@ -4,7 +4,12 @@ import { Editor } from "@tiptap/react"; const isWebEnv = isWebEnvironment(); -export const handleJetBrainsMetaKeyPress = ( +/** + * This handles various keypress issues when OSR is enabled + * @param e + * @param editor + */ +export const handleJetBrainsOSRMetaKeyIssues = ( e: KeyboardEvent, editor: Editor, ) => { @@ -46,7 +51,13 @@ export const handleJetBrainsMetaKeyPress = ( } }; -export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => { +/** + * This handles reported issues with cut/copy/paste in .ipynb files in VSC + */ +export const handleVSCMetaKeyIssues = async ( + e: KeyboardEvent, + editor: Editor, +) => { const text = editor.state.doc.textBetween( editor.state.selection.from, editor.state.selection.to, From 3da4234bd75b7e018e7287332da8cd5b1e8e9828 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 11:33:23 -0800 Subject: [PATCH 34/86] create 'useIsOSREnabled' --- core/protocol/ideWebview.ts | 3 +- .../toolWindow/ContinueBrowser.kt | 2 +- gui/src/components/mainInput/TipTapEditor.tsx | 7 +++-- .../mainInput/handleMetaKeyIssues.ts | 30 ++++--------------- gui/src/hooks/useIsOSREnabled.ts | 21 +++++++++++++ 5 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 gui/src/hooks/useIsOSREnabled.ts diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index d34b01d12..93d2192e9 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -37,7 +37,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { insertAtCursor: [{ text: string }, void]; copyText: [{ text: string }, void]; "jetbrains/editorInsetHeight": [{ height: number }, void]; - "jetbrains/isOSREnabled": [boolean, void]; + "jetbrains/isOSREnabled": [undefined, void]; "vscode/openMoveRightMarkdown": [undefined, void]; setGitHubAuthToken: [{ token: string }, void]; acceptDiff: [{ filepath: string }, void]; @@ -104,6 +104,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { setTheme: [{ theme: any }, void]; setColors: [{ [key: string]: string }, void]; "jetbrains/editorInsetRefresh": [undefined, void]; + "jetbrains/isOSREnabled": [boolean, void]; addApiKey: [undefined, void]; setupLocalConfig: [undefined, void]; incrementFtc: [undefined, void]; diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index bd76f910b..26896906b 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -135,7 +135,7 @@ class ContinueBrowser(val project: Project, url: String) { } "jetbrains/isOSREnabled" -> { - respond(isOSREnabled) + sendToWebview( "jetbrains/isOSREnabled", isOSREnabled) } "onLoad" -> { diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 0c5f36dd8..a68a4fb1d 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -64,6 +64,7 @@ import { handleVSCMetaKeyIssues, } from "./handleMetaKeyIssues"; import { ComboBoxItem } from "./types"; +import useIsOSREnabled from "../../hooks/useIsOSREnabled"; const InputBoxDiv = styled.div<{ border?: string }>` resize: none; @@ -181,6 +182,8 @@ function TipTapEditor(props: TipTapEditorProps) { const inSubmenuRef = useRef(undefined); const inDropdownRef = useRef(false); + const isOSREnabled = useIsOSREnabled(); + const enterSubmenu = async (editor: Editor, providerId: string) => { const contents = editor.getText(); const indexOfAt = contents.lastIndexOf("@"); @@ -555,9 +558,7 @@ function TipTapEditor(props: TipTapEditorProps) { if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return; - const isOSREnabled = isJetBrains() - ? await ideMessenger.request("jetbrains/isOSREnabled", undefined) - : false; + console.log({ isOSREnabled }); if (isOSREnabled) { handleJetBrainsOSRMetaKeyIssues(e, editor); diff --git a/gui/src/components/mainInput/handleMetaKeyIssues.ts b/gui/src/components/mainInput/handleMetaKeyIssues.ts index fb9808728..35fd847c9 100644 --- a/gui/src/components/mainInput/handleMetaKeyIssues.ts +++ b/gui/src/components/mainInput/handleMetaKeyIssues.ts @@ -6,41 +6,21 @@ const isWebEnv = isWebEnvironment(); /** * This handles various keypress issues when OSR is enabled - * @param e - * @param editor */ export const handleJetBrainsOSRMetaKeyIssues = ( e: KeyboardEvent, editor: Editor, ) => { const selection = window.getSelection(); + const alter = e.shiftKey ? "extend" : "move"; const handlers: Record void> = { Backspace: () => handleJetBrainsMetaBackspace(editor), - ArrowLeft: () => - selection.modify( - e.shiftKey ? "extend" : "move", - "backward", - "lineboundary", - ), - ArrowRight: () => - selection.modify( - e.shiftKey ? "extend" : "move", - "forward", - "lineboundary", - ), - ArrowDown: () => - selection.modify( - e.shiftKey ? "extend" : "move", - "forward", - "documentboundary", - ), + ArrowLeft: () => selection.modify(alter, "backward", "lineboundary"), + ArrowRight: () => selection.modify(alter, "forward", "lineboundary"), + ArrowDown: () => selection.modify(alter, "forward", "documentboundary"), ArrowUp: () => { - selection.modify( - e.shiftKey ? "extend" : "move", - "backward", - "documentboundary", - ); + selection.modify(alter, "backward", "documentboundary"); }, }; diff --git a/gui/src/hooks/useIsOSREnabled.ts b/gui/src/hooks/useIsOSREnabled.ts new file mode 100644 index 000000000..f1e71770a --- /dev/null +++ b/gui/src/hooks/useIsOSREnabled.ts @@ -0,0 +1,21 @@ +import { useState, useEffect, useContext } from "react"; +import { isJetBrains } from "../util"; +import { useWebviewListener } from "./useWebviewListener"; +import { IdeMessengerContext } from "../context/IdeMessenger"; + +export default function useIsOSREnabled() { + const [isOSREnabled, setIsOSREnabled] = useState(false); + const ideMessenger = useContext(IdeMessengerContext); + + useWebviewListener("jetbrains/isOSREnabled", async (isOSREnabled) => { + setIsOSREnabled(isOSREnabled); + }); + + useEffect(() => { + if (isJetBrains()) { + ideMessenger.request("jetbrains/isOSREnabled", undefined); + } + }, []); + + return isOSREnabled; +} From f534820b6630809abb1f1398fed672eea841fa2d Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 11:35:54 -0800 Subject: [PATCH 35/86] bump package.json version --- extensions/vscode/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 1bf96e316..e7b6c8271 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.229", + "version": "0.9.230", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From b614c43f8dc791e5a1358dfa77c0de0cc9d845bf Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 11:44:41 -0800 Subject: [PATCH 36/86] warn users when maxTokens too close to contextLength --- core/config/validation.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/config/validation.ts b/core/config/validation.ts index ebcbb623d..062c0eaed 100644 --- a/core/config/validation.ts +++ b/core/config/validation.ts @@ -34,6 +34,18 @@ export function validateConfig(config: SerializedContinueConfig) { message: `Model at index ${index} has an invalid 'provider'.`, }); } + + if (model.contextLength && model.completionOptions?.maxTokens) { + const difference = + model.contextLength - model.completionOptions.maxTokens; + + if (difference < 1000) { + errors.push({ + fatal: false, + message: `Model "${model.title}" has a contextLength of ${model.contextLength} and a maxTokens of ${model.completionOptions.maxTokens}. This leaves only ${difference} tokens for input context and will likely result in your inputs being truncated.`, + }); + } + } }); } From 9b529c99341db92c60a52cb7cd724288cacded2f Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 12:12:51 -0800 Subject: [PATCH 37/86] remove state.contextItems - items per history item --- .../mainInput/CodeBlockComponent.tsx | 7 +- .../components/mainInput/ContextItemsPeek.tsx | 1 - .../components/mainInput/ContinueInputBox.tsx | 1 + gui/src/components/mainInput/TipTapEditor.tsx | 19 +-- gui/src/components/mainInput/resolveInput.ts | 2 + .../markdown/StyledMarkdownPreview.tsx | 8 +- gui/src/hooks/useChatHandler.ts | 46 ++++--- gui/src/hooks/useSetup.ts | 23 ++-- gui/src/pages/gui/Chat.tsx | 2 +- gui/src/redux/slices/stateSlice.ts | 129 +----------------- gui/src/redux/store.ts | 7 +- 11 files changed, 56 insertions(+), 189 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 217fcc293..5d62c6d91 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -12,12 +12,11 @@ export const CodeBlockComponent = ({ editor, updateAttributes, }: any) => { - const dispatch = useDispatch(); const item: ContextItemWithId = node.attrs.item; - const contextItems = useSelector( - (state: RootState) => state.state.contextItems, - ); + // const contextItems = useSelector( + // (state: RootState) => state.state.history[0]?.contextItems[0]?.id, + // ); return ( diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index c2646415e..3353d4462 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -159,6 +159,7 @@ interface TipTapEditorProps { placeholder?: string; header?: React.ReactNode; historyKey: string; + contextItems?: ContextItemWithId[]; } function TipTapEditor(props: TipTapEditorProps) { @@ -222,10 +223,6 @@ function TipTapEditor(props: TipTapEditorProps) { inDropdownRef.current = true; }; - const contextItems = useSelector( - (store: RootState) => store.state.contextItems, - ); - const defaultModel = useSelector(defaultModelSelector); const defaultModelRef = useUpdatingRef(defaultModel); @@ -495,19 +492,7 @@ function TipTapEditor(props: TipTapEditorProps) { content: props.editorState || mainEditorContent || "", onFocus: () => setIsEditorFocused(true), onBlur: () => setIsEditorFocused(false), - onUpdate: ({ editor, transaction }) => { - // If /edit is typed and no context items are selected, select the first - - if (contextItems.length > 0) { - return; - } - - const json = editor.getJSON(); - let codeBlock = json.content?.find((el) => el.type === "codeBlock"); - if (!codeBlock) { - return; - } - }, + // onUpdate editable: !active || props.isMainInput, }); diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 64acba85a..27df6e4aa 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -30,6 +30,7 @@ async function resolveEditorContent( ideMessenger: IIdeMessenger, defaultContextProviders: DefaultContextProvider[], ): Promise<[ContextItemWithId[], RangeInFile[], MessageContent]> { + console.log("resolve editor content start"); let parts: MessagePart[] = []; let contextItemAttrs: MentionAttrs[] = []; const selectedCode: RangeInFile[] = []; @@ -171,6 +172,7 @@ async function resolveEditorContent( parts = [{ type: "text", text: lastPart }]; } } + console.log("resolve editor content end"); return [contextItems, selectedCode, parts]; } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index a86a295c9..64bcecd04 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -15,12 +15,13 @@ import { getFontSize, isJetBrains } from "../../util"; import "./katex.css"; import "./markdown.css"; import { useSelector } from "react-redux"; -import { memoizedContextItemsSelector } from "../../redux/slices/stateSlice"; import { ctxItemToRifWithContents } from "core/commands/util"; import FilenameLink from "./FilenameLink"; import StepContainerPreToolbar from "./StepContainerPreToolbar"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import StepContainerPreActionButtons from "./StepContainerPreActionButtons"; +import { RootState } from "../../redux/store"; +import { ContextItemWithId } from "core"; const StyledMarkdown = styled.div<{ fontSize?: number; @@ -93,6 +94,7 @@ interface StyledMarkdownPreviewProps { className?: string; isRenderingInStepContainer?: boolean; // Currently only used to control the rendering of codeblocks scrollLocked?: boolean; + contextItems?: ContextItemWithId[]; } const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-"; @@ -152,8 +154,6 @@ function processCodeBlocks(tree: any) { const StyledMarkdownPreview = memo(function StyledMarkdownPreview( props: StyledMarkdownPreviewProps, ) { - const contextItems = useSelector(memoizedContextItemsSelector); - const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [remarkMath, () => processCodeBlocks], rehypePlugins: [ @@ -236,7 +236,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( code: ({ node, ...codeProps }) => { const content = getCodeChildrenContent(codeProps.children); - const ctxItem = contextItems.find((ctxItem) => + const ctxItem = props.contextItems?.find((ctxItem) => ctxItem.uri?.value.includes(content), ); diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 2e35acc53..229c03ebc 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -23,7 +23,6 @@ import resolveEditorContent, { import { IIdeMessenger } from "../context/IdeMessenger"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { - addContextItems, addPromptCompletionPair, clearLastResponse, initNewActiveMessage, @@ -50,10 +49,6 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { (store: RootState) => store.state.config.slashCommands || [], ); - const contextItems = useSelector( - (state: RootState) => state.state.contextItems, - ); - const history = useSelector((store: RootState) => store.state.history); const active = useSelector((store: RootState) => store.state.active); const activeRef = useRef(active); @@ -226,26 +221,33 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { .slice(0, 1000) .join("\n"); } - selectedContextItems.unshift({ - content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath( - currentFile.path, - await ideMessenger.ide.getWorkspaceDirs(), - )}\n${currentFileContents}\n\`\`\``, - name: `Active file: ${getBasename(currentFile.path)}`, - description: currentFile.path, - id: { - itemId: currentFile.path, - providerTitle: "file", - }, - uri: { - type: "file", - value: currentFile.path, - }, - }); + if ( + !selectedContextItems.find( + (item) => item.uri?.value === currentFile.path, + ) + ) { + // don't add the file if it's already in the context items + selectedContextItems.unshift({ + content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath( + currentFile.path, + await ideMessenger.ide.getWorkspaceDirs(), + )}\n${currentFileContents}\n\`\`\``, + name: `Active file: ${getBasename(currentFile.path)}`, + description: currentFile.path, + id: { + itemId: currentFile.path, + providerTitle: "file", + }, + uri: { + type: "file", + value: currentFile.path, + }, + }); + } } } - dispatch(addContextItems(contextItems)); + // dispatch(addContextItems(contextItems)); const message: ChatMessage = { role: "user", diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 2fed805da..c7f2a2598 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -21,7 +21,7 @@ import useChatHandler from "./useChatHandler"; import { useWebviewListener } from "./useWebviewListener"; function useSetup(dispatch: Dispatch) { - const [configLoaded, setConfigLoaded] = useState(false); + // const [configLoaded, setConfigLoaded] = useState(false); const ideMessenger = useContext(IdeMessengerContext); @@ -36,7 +36,7 @@ function useSetup(dispatch: Dispatch) { const { config, profileId } = result.content; dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); - setConfigLoaded(true); + // setConfigLoaded(true); setLocalStorage("disableIndexing", config.disableIndexing || false); // Perform any actions needed with the config @@ -49,16 +49,16 @@ function useSetup(dispatch: Dispatch) { // Load config from the IDE useEffect(() => { loadConfig(); - const interval = setInterval(() => { - if (configLoaded) { - clearInterval(interval); - return; - } - loadConfig(); - }, 2_000); + // const interval = setInterval(() => { + // if (configLoaded) { + // clearInterval(interval); + // return; + // } + // loadConfig(); + // }, 2_000); - return () => clearInterval(interval); - }, [configLoaded]); + // return () => clearInterval(interval); + }, []); useEffect(() => { // Override persisted state @@ -116,6 +116,7 @@ function useSetup(dispatch: Dispatch) { }, 1000); useWebviewListener("configUpdate", async () => { + console.log("config update"); await loadConfig(); if (!isJetBrains && !getLocalStorage("disableIndexing")) { diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 78bbcd262..6aaf38092 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -290,7 +290,7 @@ export function Chat() { setLocalStorage("mainTextEntryCounter", 1); } }, - [state.history, state.contextItems, defaultModel, state, streamResponse], + [state.history, defaultModel, state, streamResponse], ); useWebviewListener( diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index f2cbe8dc9..e1b22f8f7 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -15,16 +15,6 @@ import { createSelector } from "reselect"; import { v4 as uuidv4, v4 } from "uuid"; import { RootState } from "../store"; -export const memoizedContextItemsSelector = createSelector( - [(state: RootState) => state.state.history], - (history) => { - return history.reduce((acc, item) => { - acc.push(...item.contextItems); - return acc; - }, []); - }, -); - // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. type ChatHistoryItemWithMessageId = ChatHistoryItem & { @@ -33,7 +23,6 @@ type ChatHistoryItemWithMessageId = ChatHistoryItem & { type State = { history: ChatHistoryItemWithMessageId[]; - contextItems: ContextItemWithId[]; ttsActive: boolean; active: boolean; isGatheringContext: boolean; @@ -49,7 +38,6 @@ type State = { const initialState: State = { history: [], - contextItems: [], ttsActive: false, active: false, isGatheringContext: false, @@ -148,11 +136,6 @@ export const stateSlice = createSlice({ state.history[index].contextItems = contextItems; } }, - addContextItems: (state, action: PayloadAction) => { - console.log("addContextItems"); - - state.contextItems = state.contextItems.concat(action.payload); - }, resubmitAtIndex: ( state, { @@ -182,7 +165,6 @@ export const stateSlice = createSlice({ }); // https://github.com/continuedev/continue/pull/1021 - // state.contextItems = []; state.active = true; }, deleteMessage: (state, action: PayloadAction) => { @@ -201,7 +183,7 @@ export const stateSlice = createSlice({ state.history.push({ message: { role: "user", content: "", id: uuidv4() }, - contextItems: state.contextItems, + contextItems: [], editorState: payload.editorState, }); state.history.push({ @@ -212,8 +194,7 @@ export const stateSlice = createSlice({ }, contextItems: [], }); - // https://github.com/continuedev/continue/pull/1021 - // state.contextItems = []; + state.active = true; }, setMessageAtIndex: ( @@ -290,34 +271,12 @@ export const stateSlice = createSlice({ state.sessionId = payload.sessionId; } else { state.history = []; - state.contextItems = []; state.active = false; state.title = "New Session"; state.sessionId = v4(); state.isInMultifileEdit = false; } }, - deleteContextWithIds: ( - state, - { - payload, - }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, - ) => { - console.log("deleteContextWithIds"); - - const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`; - const ids = new Set(payload.ids.map(getKey)); - - if (payload.index === undefined) { - state.contextItems = state.contextItems.filter( - (item) => !ids.has(getKey(item.id)), - ); - } else { - state.history[payload.index].contextItems = state.history[ - payload.index - ].contextItems.filter((item) => !ids.has(getKey(item.id))); - } - }, addHighlightedCode: ( state, { @@ -325,47 +284,15 @@ export const stateSlice = createSlice({ }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { console.log("addHighlightedCode"); - - let contextItems = [...state.contextItems].map((item) => { + let contextItems = + state.history[state.history.length - 1].contextItems ?? []; + contextItems = contextItems.map((item) => { return { ...item, editing: false }; }); const base = payload.rangeInFileWithContents.filepath .split(/[\\/]/) .pop(); - // Merge if there is overlap - for (let i = 0; i < contextItems.length; i++) { - const item = contextItems[i]; - if (item.description === payload.rangeInFileWithContents.filepath) { - let newStart = payload.rangeInFileWithContents.range.start.line; - let newEnd = payload.rangeInFileWithContents.range.end.line; - let [oldStart, oldEnd] = item.name - .split("(")[1] - .split(")")[0] - .split("-") - .map((x: string) => parseInt(x) - 1); - if (newStart > oldEnd || newEnd < oldStart) { - continue; - } - const startLine = Math.min(newStart, oldStart); - const endLine = Math.max(newEnd, oldEnd); - - // const oldContents = item.content.split("\n"); - // const newContents = - // payload.rangeInFileWithContents.contents.split("\n"); - // const finalContents = []; - - contextItems[i] = { - ...item, - name: `${base} (${startLine + 1}-${endLine + 1})`, - content: payload.rangeInFileWithContents.contents, - editing: true, - editable: true, - }; - return { ...state, contextItems }; - } - } - const lineNums = `(${ payload.rangeInFileWithContents.range.start.line + 1 }-${payload.rangeInFileWithContents.range.end.line + 1})`; @@ -380,48 +307,7 @@ export const stateSlice = createSlice({ editing: true, editable: true, }); - - return { ...state, contextItems }; - }, - setEditingAtIds: ( - state, - { - payload, - }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, - ) => { - console.log("setEditingAtIds"); - - const ids = payload.ids.map((id) => id.itemId); - - if (typeof payload.index === "undefined") { - return { - ...state, - contextItems: state.contextItems.map((item) => { - return { - ...item, - editing: ids.includes(item.id.itemId), - }; - }), - }; - } else { - return { - ...state, - history: state.history.map((step, i) => { - if (i === payload.index) { - return { - ...step, - contextItems: step.contextItems.map((item) => { - return { - ...item, - editing: ids.includes(item.id.itemId), - }; - }), - }; - } - return step; - }), - }; - } + state.history[state.history.length - 1].contextItems = contextItems; }, setDefaultModel: ( state, @@ -454,15 +340,12 @@ export const stateSlice = createSlice({ export const { setContextItemsAtIndex, - addContextItems, addContextItemsAtIndex, setInactive, streamUpdate, newSession, - deleteContextWithIds, resubmitAtIndex, addHighlightedCode, - setEditingAtIds, setDefaultModel, setConfig, setConfigError, diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index a5d0313f4..221d275c9 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -40,12 +40,7 @@ const windowIDTransform = (windowID: string) => ); const saveSubsetFilters = [ - createFilter("state", [ - "history", - "contextItems", - "sessionId", - "defaultModelTitle", - ]), + createFilter("state", ["history", "sessionId", "defaultModelTitle"]), ]; const persistConfig = { From 14b406075cc0db5101c71e7ab42be896eb38428a Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 12:20:37 -0800 Subject: [PATCH 38/86] enable images with azure provider --- core/llm/autodetect.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 17f104a52..bebb8ead1 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -49,7 +49,7 @@ const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [ "mistral", "sambanova", "vertexai", - "watsonx" + "watsonx", ]; const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [ @@ -63,7 +63,8 @@ const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [ "sagemaker", "continue-proxy", "openrouter", - "vertexai" + "vertexai", + "azure", ]; const MODEL_SUPPORTS_IMAGES: string[] = [ @@ -121,7 +122,7 @@ const PARALLEL_PROVIDERS: ModelProvider[] = [ "together", "sambanova", "nebius", - "vertexai" + "vertexai", ]; function llmCanGenerateInParallel( From 00aaba64798ab33a2e4f2407b31fafe49ae62564 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 12:25:33 -0800 Subject: [PATCH 39/86] pass contextItems around a bit more --- gui/src/components/gui/StepContainer.tsx | 1 + .../components/mainInput/CodeBlockComponent.tsx | 14 ++++++++------ .../components/markdown/CodeSnippetPreview.tsx | 1 + .../components/markdown/StyledMarkdownPreview.tsx | 15 ++++++++------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx index 1eba7ee91..22523cfb2 100644 --- a/gui/src/components/gui/StepContainer.tsx +++ b/gui/src/components/gui/StepContainer.tsx @@ -105,6 +105,7 @@ function StepContainer(props: StepContainerProps) { )} diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 5d62c6d91..80c1cec78 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -1,9 +1,9 @@ import { NodeViewWrapper } from "@tiptap/react"; import { ContextItemWithId } from "core"; -import { useDispatch, useSelector } from "react-redux"; import { vscBadgeBackground } from ".."; -import { RootState } from "../../redux/store"; import CodeSnippetPreview from "../markdown/CodeSnippetPreview"; +import { useSelector } from "react-redux"; +import { RootState } from "../../redux/store"; export const CodeBlockComponent = ({ node, @@ -13,15 +13,17 @@ export const CodeBlockComponent = ({ updateAttributes, }: any) => { const item: ContextItemWithId = node.attrs.item; + const contextItems = useSelector( + (store: RootState) => + store.state.history[store.state.history.length - 1].contextItems, + ); + const isFirstContextItem = item.id === contextItems[0].id; - // const contextItems = useSelector( - // (state: RootState) => state.state.history[0]?.contextItems[0]?.id, - // ); return ( diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 64bcecd04..a3da04eb9 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -236,13 +236,14 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( code: ({ node, ...codeProps }) => { const content = getCodeChildrenContent(codeProps.children); - const ctxItem = props.contextItems?.find((ctxItem) => - ctxItem.uri?.value.includes(content), - ); - - if (ctxItem) { - const rif = ctxItemToRifWithContents(ctxItem); - return ; + if (props.contextItems) { + const ctxItem = props.contextItems.find((ctxItem) => + ctxItem.uri?.value.includes(content), + ); + if (ctxItem) { + const rif = ctxItemToRifWithContents(ctxItem); + return ; + } } return {codeProps.children}; From 3e4580d9f9a2dfaf200abfb1b8cdbc99cad60a11 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 12:37:45 -0800 Subject: [PATCH 40/86] fix empty messages bug for all providers --- core/llm/countTokens.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/llm/countTokens.ts b/core/llm/countTokens.ts index 7ae3da1b7..9b30ad4bc 100644 --- a/core/llm/countTokens.ts +++ b/core/llm/countTokens.ts @@ -323,6 +323,27 @@ function pruneChatHistory( return chatHistory; } +function messageIsEmpty(message: ChatMessage): boolean { + if (typeof message.content === "string") { + return message.content.trim() === ""; + } + if (Array.isArray(message.content)) { + return message.content.every( + (item) => !item.imageUrl && item.text?.trim() === "", + ); + } + return false; +} + +function addSpaceToAnyEmptyMessages(messages: ChatMessage[]): ChatMessage[] { + return messages.map((message) => { + if (messageIsEmpty(message)) { + message.content = " "; + } + return message; + }); +} + function compileChatMessages( modelName: string, msgs: ChatMessage[] | undefined, @@ -333,12 +354,14 @@ function compileChatMessages( functions: any[] | undefined = undefined, systemMessage: string | undefined = undefined, ): ChatMessage[] { - const msgsCopy = msgs + let msgsCopy = msgs ? msgs .map((msg) => ({ ...msg })) .filter((msg) => msg.content !== "" && msg.role !== "system") : []; + msgsCopy = addSpaceToAnyEmptyMessages(msgsCopy); + if (prompt) { const promptMsg: ChatMessage = { role: "user", From d977ea8447af00ef6b2a0349b4cbc6ebe34f0987 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 12:59:24 -0800 Subject: [PATCH 41/86] Update ToolTipComponent.kt --- .../continueintellijextension/editor/ToolTipComponent.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToolTipComponent.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToolTipComponent.kt index 30535c4d6..7890ebdba 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToolTipComponent.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToolTipComponent.kt @@ -88,8 +88,8 @@ class ToolTipComponent(editor: Editor, x: Int, y: Int) : val componentHorizontalPadding = 4 val buttonMargin = 4 - addToChatButton = StyledButton("Chat (${cmdCtrlChar}J)") - editButton = StyledButton("Edit (${cmdCtrlChar}I)") + addToChatButton = StyledButton("Chat (${cmdCtrlChar}+J)") + editButton = StyledButton("Edit (${cmdCtrlChar}+I)") addToChatButton.addActionListener { e: ActionEvent? -> focusContinueInput(editor.project) From 87cfdcefa1d02bd53391b572d658024047315850 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 12:59:53 -0800 Subject: [PATCH 42/86] Update TipTapEditor.tsx --- gui/src/components/mainInput/TipTapEditor.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index a68a4fb1d..98f1b79cc 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -558,8 +558,6 @@ function TipTapEditor(props: TipTapEditorProps) { if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return; - console.log({ isOSREnabled }); - if (isOSREnabled) { handleJetBrainsOSRMetaKeyIssues(e, editor); } else { From c9d44a17ee2d8a31400d4964042e6959ea37c0fe Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 11:38:33 -0800 Subject: [PATCH 43/86] improv: expand typescript queries, simplify tests --- .../RootPathContextService.ts | 7 +- .../test/RootPathContextService.test.ts | 110 ++++++------ .../test/files/arrowFunctions.ts | 21 +++ .../root-path-context/test/files/class.ts | 37 ---- .../test/files/classMethods.ts | 27 +++ .../root-path-context/test/files/classes.ts | 3 + .../root-path-context/test/files/functions.ts | 21 +-- .../test/testCases/typescript.ts | 164 ++++++++++++------ .../arrow_function/typescript.scm | 77 ++++++++ .../method_definition/typescript.scm | 30 ++++ 10 files changed, 336 insertions(+), 161 deletions(-) create mode 100644 core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts delete mode 100644 core/autocomplete/context/root-path-context/test/files/class.ts create mode 100644 core/autocomplete/context/root-path-context/test/files/classMethods.ts create mode 100644 core/autocomplete/context/root-path-context/test/files/classes.ts create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 2602b5acf..f279b472d 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -39,6 +39,7 @@ export class RootPathContextService { } private static TYPES_TO_USE = new Set([ + "arrow_function", "program", "function_declaration", "function_definition", @@ -74,9 +75,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - // const type = node.type; - // debugger; - // console.log(getSyntaxTreeString(node)); + const type = node.type; + debugger; + console.log(getSyntaxTreeString(node)); query = await getQueryForFile( filepath, diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index fe81a0edd..f3a7bd097 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -3,61 +3,61 @@ import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ ...TYPESCRIPT_TEST_CASES, - { - nodeType: "function_definition", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 4, character: 25 }, - definitionPositions: [ - { row: 3, column: 30 }, // Person - { row: 3, column: 42 }, // Address - ], - }, - { - nodeType: "function_definition (inside a class)", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 12, character: 33 }, - definitionPositions: [ - { row: 6, column: 21 }, // BaseClass - { row: 6, column: 33 }, // Collection - { row: 11, column: 47 }, // Person - { row: 11, column: 59 }, // Address - ], - }, - { - nodeType: "function_definition", - fileName: "file1.php", - language: "PHP", - cursorPosition: { line: 12, character: 32 }, - definitionPositions: [ - { row: 10, column: 26 }, // Person - { row: 10, column: 44 }, // Address - ], - }, - { - nodeType: "method_declaration", - fileName: "file1.php", - language: "PHP", - cursorPosition: { line: 26, character: 35 }, - definitionPositions: [ - { row: 15, column: 29 }, // BaseClass - { row: 15, column: 55 }, // FirstInterface - { row: 15, column: 72 }, // SecondInterface - { row: 25, column: 43 }, // Person - { row: 25, column: 61 }, // Address - ], - }, - { - nodeType: "function_declaration", - fileName: "file1.go", - language: "Go", - cursorPosition: { line: 7, character: 21 }, - definitionPositions: [ - { row: 6, column: 33 }, // models.User - { row: 6, column: 50 }, // models.Address - ], - }, + // { + // nodeType: "function_definition", + // fileName: "file1.py", + // language: "Python", + // cursorPosition: { line: 4, character: 25 }, + // definitionPositions: [ + // { row: 3, column: 30 }, // Person + // { row: 3, column: 42 }, // Address + // ], + // }, + // { + // nodeType: "function_definition (inside a class)", + // fileName: "file1.py", + // language: "Python", + // cursorPosition: { line: 12, character: 33 }, + // definitionPositions: [ + // { row: 6, column: 21 }, // BaseClass + // { row: 6, column: 33 }, // Collection + // { row: 11, column: 47 }, // Person + // { row: 11, column: 59 }, // Address + // ], + // }, + // { + // nodeType: "function_definition", + // fileName: "file1.php", + // language: "PHP", + // cursorPosition: { line: 12, character: 32 }, + // definitionPositions: [ + // { row: 10, column: 26 }, // Person + // { row: 10, column: 44 }, // Address + // ], + // }, + // { + // nodeType: "method_declaration", + // fileName: "file1.php", + // language: "PHP", + // cursorPosition: { line: 26, character: 35 }, + // definitionPositions: [ + // { row: 15, column: 29 }, // BaseClass + // { row: 15, column: 55 }, // FirstInterface + // { row: 15, column: 72 }, // SecondInterface + // { row: 25, column: 43 }, // Person + // { row: 25, column: 61 }, // Address + // ], + // }, + // { + // nodeType: "function_declaration", + // fileName: "file1.go", + // language: "Go", + // cursorPosition: { line: 7, character: 21 }, + // definitionPositions: [ + // { row: 6, column: 33 }, // models.User + // { row: 6, column: 50 }, // models.Address + // ], + // }, ]; describe("RootPathContextService", () => { diff --git a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts new file mode 100644 index 000000000..02e9d7043 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts @@ -0,0 +1,21 @@ +// @ts-nocheck + +const getAddress = (person: Person): Address => { + // TODO +}; + +const logPerson = (person: Person) => { + // TODO +}; + +const getHardcodedAddress = (): Address => { + // TODO +}; + +const getAddresses = (people: Person[]): Address[] => { + // TODO +}; + +const logPersonWithAddres = (person: Person
): Person
=> { + // TODO +}; diff --git a/core/autocomplete/context/root-path-context/test/files/class.ts b/core/autocomplete/context/root-path-context/test/files/class.ts deleted file mode 100644 index b2bd4ec78..000000000 --- a/core/autocomplete/context/root-path-context/test/files/class.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { - Address, - Person, - BaseClass, - FirstInterface, - SecondInterface, - // @ts-ignore -} from "./types"; - -class Group extends BaseClass implements FirstInterface, SecondInterface { - people: Person[]; - - constructor(people: Person[]) { - super(); - this.people = people; - } - - getPersonAddress(person: Person): Address { - return person.address; - } - - getHardcodedAddress(): Address { - return { street: "123 Main St", city: "Anytown" }; - } - - addPerson(person: Person) { - this.people = [...this.people, person]; - } - - addPeople(people: Person[]) { - this.people = [...this.people, ...people]; - } - - getAddresses(people: Person[]): Address[] { - return people.map((person) => person.address); - } -} diff --git a/core/autocomplete/context/root-path-context/test/files/classMethods.ts b/core/autocomplete/context/root-path-context/test/files/classMethods.ts new file mode 100644 index 000000000..645889b79 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/classMethods.ts @@ -0,0 +1,27 @@ +// @ts-nocheck + +class Group { + getPersonAddress(person: Person): Address { + // TODO + } + + getHardcodedAddress(): Address { + // TODO + } + + addPerson(person: Person) { + // TODO + } + + addPeople(people: Person[]) { + // TODO + } + + getAddresses(people: Person[]): Address[] { + // TODO + } + + logPersonWithAddress(person: Person
): Person
{ + // TODO + } +} diff --git a/core/autocomplete/context/root-path-context/test/files/classes.ts b/core/autocomplete/context/root-path-context/test/files/classes.ts new file mode 100644 index 000000000..2f6b76cda --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/classes.ts @@ -0,0 +1,3 @@ +// @ts-nocheck + +class Group extends BaseClass implements FirstInterface, SecondInterface {} diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index ec6e0dec1..11e2bf76d 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -1,32 +1,25 @@ -import { - Address, - Person, - // @ts-ignore -} from "./types"; +// @ts-nocheck function getAddress(person: Person): Address { - return person.address; + // TODO } function getFirstAddress(people: Person[]): Address { - return people[0].address; + // TODO } function logPerson(person: Person) { - console.log(`Name: ${person.name}, Age: ${person.age}`); + // TODO } function getHardcodedAddress(): Address { - return { street: "123 Main St", city: "Anytown", zipCode: "12345" }; + // TODO } function getAddresses(people: Person[]): Address[] { - return people[0].address; + // TODO } function logPersonWithAddress(person: Person
): Person
{ - console.log( - `Name: ${person.name}, Age: ${person.age}, Address: ${person.address.street}`, - ); - return person; + // TODO } diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 4dbe61cf2..701813a2d 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -1,50 +1,50 @@ -export const TYPESCRIPT_TEST_CASES = [ +const FUNCTIONS = [ { nodeType: "function_declaration with a param and a return type", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 7, character: 24 }, + cursorPosition: { line: 3, character: 9 }, definitionPositions: [ - { row: 6, column: 34 }, // Person - { row: 6, column: 44 }, // Address + { row: 2, column: 34 }, // Person + { row: 2, column: 44 }, // Address ], }, { nodeType: "function_declaration with array param", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 11, character: 27 }, + cursorPosition: { line: 7, character: 9 }, definitionPositions: [ - { row: 10, column: 39 }, // Person - { row: 10, column: 51 }, // Address + { row: 6, column: 39 }, // Person + { row: 6, column: 51 }, // Address ], }, { nodeType: "function_declaration without return type", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 15, character: 58 }, + cursorPosition: { line: 11, character: 9 }, definitionPositions: [ - { row: 14, column: 33 }, // Person + { row: 10, column: 33 }, // Person ], }, { nodeType: "function_declaration without params", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 19, character: 70 }, + cursorPosition: { line: 15, character: 9 }, definitionPositions: [ - { row: 18, column: 39 }, // Person + { row: 14, column: 39 }, // Person ], }, { nodeType: "function_declaration with array params and array return type", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 23, character: 27 }, + cursorPosition: { line: 19, character: 9 }, definitionPositions: [ - { row: 22, column: 36 }, // Person - { row: 22, column: 48 }, // Address + { row: 18, column: 36 }, // Person + { row: 18, column: 48 }, // Address ], }, { @@ -52,75 +52,135 @@ export const TYPESCRIPT_TEST_CASES = [ "function_declaration with generic params and generic return type", fileName: "functions.ts", language: "TypeScript", - cursorPosition: { line: 27, character: 14 }, + cursorPosition: { line: 23, character: 9 }, definitionPositions: [ - { row: 26, column: 44 }, // Person - { row: 26, column: 52 }, // Address - { row: 26, column: 62 }, // Person - { row: 26, column: 70 }, // Address + { row: 22, column: 44 }, // Person + { row: 22, column: 52 }, // Address + { row: 22, column: 62 }, // Person + { row: 22, column: 70 }, // Address + ], + }, +]; + +const ARROW_FUNCTIONS = [ + { + nodeType: "arrow_function with a param and a return type", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 3, character: 9 }, + definitionPositions: [ + { row: 2, column: 34 }, // Person + { row: 2, column: 44 }, // Address ], }, { - nodeType: "method_declaration with a param and a return type", - fileName: "class.ts", + nodeType: "arrow_function without return type", + fileName: "arrowFunctions.ts", language: "TypeScript", - cursorPosition: { line: 18, character: 26 }, + cursorPosition: { line: 7, character: 9 }, definitionPositions: [ - { row: 9, column: 29 }, // BaseClass - { row: 9, column: 55 }, // FirstInterface - { row: 9, column: 72 }, // SecondInterface - { row: 17, column: 33 }, // Person - { row: 17, column: 43 }, // Address + { row: 6, column: 33 }, // Person + ], + }, + { + nodeType: "arrow_function without params", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 11, character: 9 }, + definitionPositions: [ + { row: 10, column: 39 }, // Person + ], + }, + { + nodeType: "arrow_function with array params and array return type", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 15, character: 9 }, + definitionPositions: [ + { row: 14, column: 36 }, // Person + { row: 14, column: 48 }, // Address + ], + }, + { + nodeType: "arrow_function with generic params and generic return type", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 19, character: 9 }, + definitionPositions: [ + { row: 18, column: 43 }, // Person + { row: 18, column: 51 }, // Address + { row: 18, column: 61 }, // Person + { row: 18, column: 69 }, // Address + ], + }, +]; + +const CLASS_METHODS = [ + { + nodeType: "method_declaration with a param and a return type", + fileName: "classMethods.ts", + language: "TypeScript", + cursorPosition: { line: 4, character: 11 }, + definitionPositions: [ + { row: 3, column: 33 }, // Person + { row: 3, column: 43 }, // Address ], }, { nodeType: "method_declaration without arguments", - fileName: "class.ts", + fileName: "classMethods.ts", language: "TypeScript", - cursorPosition: { line: 22, character: 54 }, + cursorPosition: { line: 8, character: 11 }, definitionPositions: [ - { row: 9, column: 29 }, // BaseClass - { row: 9, column: 55 }, // FirstInterface - { row: 9, column: 72 }, // SecondInterface - { row: 21, column: 32 }, // Address + { row: 7, column: 32 }, // Address ], }, { nodeType: "method_declaration without return type", - fileName: "class.ts", + fileName: "classMethods.ts", language: "TypeScript", - cursorPosition: { line: 26, character: 43 }, + cursorPosition: { line: 12, character: 11 }, definitionPositions: [ - { row: 9, column: 29 }, // BaseClass - { row: 9, column: 55 }, // FirstInterface - { row: 9, column: 72 }, // SecondInterface - { row: 25, column: 26 }, // Person + { row: 11, column: 26 }, // Person ], }, { nodeType: "method_declaration with array type arguments", - fileName: "class.ts", + fileName: "classMethods.ts", language: "TypeScript", - cursorPosition: { line: 30, character: 46 }, + cursorPosition: { line: 16, character: 11 }, definitionPositions: [ - { row: 9, column: 29 }, // BaseClass - { row: 9, column: 55 }, // FirstInterface - { row: 9, column: 72 }, // SecondInterface - { row: 29, column: 26 }, // Person + { row: 15, column: 26 }, // Person ], }, { nodeType: "method_declaration with array type arguments and array type return", - fileName: "class.ts", + fileName: "classMethods.ts", language: "TypeScript", - cursorPosition: { line: 34, character: 50 }, + cursorPosition: { line: 20, character: 11 }, definitionPositions: [ - { row: 9, column: 29 }, // BaseClass - { row: 9, column: 55 }, // FirstInterface - { row: 9, column: 72 }, // SecondInterface - { row: 33, column: 29 }, // Person - { row: 33, column: 41 }, // Address + { row: 19, column: 29 }, // Person + { row: 19, column: 41 }, // Address + ], + }, + { + nodeType: + "method_declaration with with generic params and generic return type", + fileName: "classMethods.ts", + language: "TypeScript", + cursorPosition: { line: 24, character: 11 }, + definitionPositions: [ + { row: 23, column: 37 }, // Person + { row: 23, column: 45 }, // Address + { row: 23, column: 55 }, // Person + { row: 23, column: 63 }, // Address ], }, ]; + +export const TYPESCRIPT_TEST_CASES = [ + ...FUNCTIONS, + ...ARROW_FUNCTIONS, + ...CLASS_METHODS, +]; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm new file mode 100644 index 000000000..159ff63f6 --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm @@ -0,0 +1,77 @@ +; Pattern for return type with direct type_identifier +( + (arrow_function + (type_annotation + (type_identifier) @return_type + ) + ) +) + +; Pattern for return type with one level of nesting +( + (arrow_function + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) +) + +; Pattern for return type with two levels of nesting +( + (arrow_function + (type_annotation + (_ + (_ + (type_identifier) @return_type + ) + ) + ) + ) +) + +; Pattern for parameters with direct type_identifier +( + (arrow_function + (formal_parameters + (_ + (type_annotation + (type_identifier) @param_type + ) + ) + ) + ) +) + +; Pattern for parameters with one level of nesting +( + (arrow_function + (formal_parameters + (_ + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) +) + +; Pattern for parameters with two levels of nesting +( + (arrow_function + (formal_parameters + (_ + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) + ) +) \ No newline at end of file diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm index 545d11d97..d5d4c3724 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm @@ -18,6 +18,19 @@ ) ) +; Pattern for return type with two levels of nesting +( + (method_definition + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) +) + ; Pattern for parameters with direct type_identifier ( (method_definition @@ -45,3 +58,20 @@ ) ) ) + +; Pattern for parameters with two levels of nesting +( + (method_definition + (formal_parameters + (_ + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) + ) +) \ No newline at end of file From e595235584629ed214139dc328818e168200ce32 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 13:30:20 -0800 Subject: [PATCH 44/86] state.contextItems --- .../mainInput/CodeBlockComponent.tsx | 12 +++----- gui/src/hooks/useSetup.ts | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 80c1cec78..1ece03733 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -5,19 +5,15 @@ import CodeSnippetPreview from "../markdown/CodeSnippetPreview"; import { useSelector } from "react-redux"; import { RootState } from "../../redux/store"; -export const CodeBlockComponent = ({ - node, - deleteNode, - selected, - editor, - updateAttributes, -}: any) => { +export const CodeBlockComponent = (props: any) => { + const { node, deleteNode, selected, editor, updateAttributes } = props; const item: ContextItemWithId = node.attrs.item; const contextItems = useSelector( (store: RootState) => store.state.history[store.state.history.length - 1].contextItems, ); - const isFirstContextItem = item.id === contextItems[0].id; + const isFirstContextItem = item.id === contextItems[0]?.id; + // const isFirstContextItem = false; return ( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index c7f2a2598..9bdc4d713 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -1,5 +1,5 @@ import { Dispatch } from "@reduxjs/toolkit"; -import { useContext, useEffect, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import { useSelector } from "react-redux"; import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; @@ -14,7 +14,7 @@ import { } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; -import { debounce } from "lodash"; +import { debounce, initial } from "lodash"; import { isJetBrains } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import useChatHandler from "./useChatHandler"; @@ -25,7 +25,8 @@ function useSetup(dispatch: Dispatch) { const ideMessenger = useContext(IdeMessengerContext); - const loadConfig = async () => { + const initialConfigLoad = useRef(false); + const loadConfig = useCallback(async () => { const result = await ideMessenger.request( "config/getSerializedProfileInfo", undefined, @@ -36,7 +37,7 @@ function useSetup(dispatch: Dispatch) { const { config, profileId } = result.content; dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); - // setConfigLoaded(true); + initialConfigLoad.current = true; setLocalStorage("disableIndexing", config.disableIndexing || false); // Perform any actions needed with the config @@ -44,21 +45,21 @@ function useSetup(dispatch: Dispatch) { setLocalStorage("fontSize", config.ui.fontSize); document.body.style.fontSize = `${config.ui.fontSize}px`; } - }; + }, [dispatch, ideMessenger, initialConfigLoad]); // Load config from the IDE useEffect(() => { loadConfig(); - // const interval = setInterval(() => { - // if (configLoaded) { - // clearInterval(interval); - // return; - // } - // loadConfig(); - // }, 2_000); + const interval = setInterval(() => { + if (initialConfigLoad.current) { + clearInterval(interval); + return; + } + loadConfig(); + }, 2_000); - // return () => clearInterval(interval); - }, []); + return () => clearInterval(interval); + }, [initialConfigLoad]); useEffect(() => { // Override persisted state From e74cf2cf64d2907be3aea32633d45db8947db5f2 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 14 Nov 2024 13:35:50 -0800 Subject: [PATCH 45/86] Update gradle.properties --- extensions/intellij/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/intellij/gradle.properties b/extensions/intellij/gradle.properties index 5dba42f8e..be8b0febb 100644 --- a/extensions/intellij/gradle.properties +++ b/extensions/intellij/gradle.properties @@ -3,7 +3,7 @@ pluginGroup=com.github.continuedev.continueintellijextension pluginName=continue-intellij-extension pluginRepositoryUrl=https://github.com/continuedev/continue # SemVer format -> https://semver.org -pluginVersion=0.0.81 +pluginVersion=0.0.82 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild=223 # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension From 5bc757f783fd54cb14842bba665a7bbc8e11cb10 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 13:57:01 -0800 Subject: [PATCH 46/86] minisearch --- gui/src/components/History/index.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index 7ed525626..4aee636bd 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -46,13 +46,20 @@ export function History() { const fetchSessions = async () => { const sessions = await getHistory(); setSessions(sessions); - minisearch.addAll( - sessions.map((session) => ({ - title: session.title, - sessionId: session.sessionId, - id: session.sessionId, - })), - ); + + try { + // Consider adding just last session to existing instead of clearing/adding all + minisearch.removeAll(); + minisearch.addAll( + sessions.map((session) => ({ + title: session.title, + sessionId: session.sessionId, + id: session.sessionId, + })), + ); + } catch (e) { + console.log("error adding sessions to minisearch", e); + } }; fetchSessions(); }, [lastSessionId]); From fbbee8980ae2583e06255f2642122f647abc9ffa Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 14:27:55 -0800 Subject: [PATCH 47/86] files --- .../mainInput/CodeBlockComponent.tsx | 12 +++++------ .../components/mainInput/ContinueInputBox.tsx | 1 - gui/src/components/mainInput/TipTapEditor.tsx | 1 - gui/src/components/mainInput/resolveInput.ts | 2 -- .../markdown/StyledMarkdownPreview.tsx | 2 -- gui/src/hooks/useSetup.ts | 3 +-- gui/src/redux/slices/stateSlice.ts | 21 ------------------- 7 files changed, 7 insertions(+), 35 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 1ece03733..20d700c63 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -8,12 +8,12 @@ import { RootState } from "../../redux/store"; export const CodeBlockComponent = (props: any) => { const { node, deleteNode, selected, editor, updateAttributes } = props; const item: ContextItemWithId = node.attrs.item; - const contextItems = useSelector( - (store: RootState) => - store.state.history[store.state.history.length - 1].contextItems, - ); - const isFirstContextItem = item.id === contextItems[0]?.id; - // const isFirstContextItem = false; + // const contextItems = useSelector( + // (store: RootState) => + // store.state.history[store.state.history.length - 1].contextItems, + // ); + // const isFirstContextItem = item.id === contextItems[0]?.id; + const isFirstContextItem = false; return ( diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index d4aedf0b1..c98a69403 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -140,7 +140,6 @@ function ContinueInputBox(props: ContinueInputBoxProps) { availableContextProviders={availableContextProviders ?? []} availableSlashCommands={availableSlashCommands} historyKey="chat" - contextItems={props.contextItems} /> diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 3353d4462..e3e0feb2e 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -159,7 +159,6 @@ interface TipTapEditorProps { placeholder?: string; header?: React.ReactNode; historyKey: string; - contextItems?: ContextItemWithId[]; } function TipTapEditor(props: TipTapEditorProps) { diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 27df6e4aa..64acba85a 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -30,7 +30,6 @@ async function resolveEditorContent( ideMessenger: IIdeMessenger, defaultContextProviders: DefaultContextProvider[], ): Promise<[ContextItemWithId[], RangeInFile[], MessageContent]> { - console.log("resolve editor content start"); let parts: MessagePart[] = []; let contextItemAttrs: MentionAttrs[] = []; const selectedCode: RangeInFile[] = []; @@ -172,7 +171,6 @@ async function resolveEditorContent( parts = [{ type: "text", text: lastPart }]; } } - console.log("resolve editor content end"); return [contextItems, selectedCode, parts]; } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index a3da04eb9..cd87cb2cd 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -14,13 +14,11 @@ import { import { getFontSize, isJetBrains } from "../../util"; import "./katex.css"; import "./markdown.css"; -import { useSelector } from "react-redux"; import { ctxItemToRifWithContents } from "core/commands/util"; import FilenameLink from "./FilenameLink"; import StepContainerPreToolbar from "./StepContainerPreToolbar"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import StepContainerPreActionButtons from "./StepContainerPreActionButtons"; -import { RootState } from "../../redux/store"; import { ContextItemWithId } from "core"; const StyledMarkdown = styled.div<{ diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 9bdc4d713..effe838dc 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -59,7 +59,7 @@ function useSetup(dispatch: Dispatch) { }, 2_000); return () => clearInterval(interval); - }, [initialConfigLoad]); + }, [initialConfigLoad, loadConfig]); useEffect(() => { // Override persisted state @@ -117,7 +117,6 @@ function useSetup(dispatch: Dispatch) { }, 1000); useWebviewListener("configUpdate", async () => { - console.log("config update"); await loadConfig(); if (!isJetBrains && !getLocalStorage("disableIndexing")) { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index e1b22f8f7..4222b4693 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -71,8 +71,6 @@ export const stateSlice = createSlice({ state, { payload: config }: PayloadAction, ) => { - console.log("setConfig"); - const defaultModelTitle = config.models.find((model) => model.title === state.defaultModelTitle) ?.title || @@ -91,8 +89,6 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction, ) => { - console.log("addPromptCompletionPair"); - if (!state.history.length) { return; } @@ -131,7 +127,6 @@ export const stateSlice = createSlice({ contextItems: ChatHistoryItem["contextItems"]; }>, ) => { - console.log("setContextItemsAtIndex"); if (state.history[index]) { state.history[index].contextItems = contextItems; } @@ -145,8 +140,6 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { - console.log("resubmitAtIndex"); - const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -179,8 +172,6 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { - console.log("initNewActiveMessage"); - state.history.push({ message: { role: "user", content: "", id: uuidv4() }, contextItems: [], @@ -207,7 +198,6 @@ export const stateSlice = createSlice({ contextItems?: ContextItemWithId[]; }>, ) => { - console.log("setMessageAtIndex"); if (payload.index >= state.history.length) { state.history.push({ message: { ...payload.message, id: uuidv4() }, @@ -239,8 +229,6 @@ export const stateSlice = createSlice({ contextItems: ContextItemWithId[]; }>, ) => { - console.log("addContextItemsAtIndex"); - const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -252,8 +240,6 @@ export const stateSlice = createSlice({ state.active = false; }, streamUpdate: (state, action: PayloadAction) => { - console.log("streamUpdate"); - if (state.history.length) { state.history[state.history.length - 1].message.content += action.payload; @@ -264,8 +250,6 @@ export const stateSlice = createSlice({ { payload }: PayloadAction, ) => { if (payload) { - console.log("newSession"); - state.history = payload.history as any; state.title = payload.title; state.sessionId = payload.sessionId; @@ -283,7 +267,6 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { - console.log("addHighlightedCode"); let contextItems = state.history[state.history.length - 1].contextItems ?? []; contextItems = contextItems.map((item) => { @@ -313,8 +296,6 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction<{ title: string; force?: boolean }>, ) => { - console.log("setDefaultModel"); - const model = state.config.models.find( (model) => model.title === payload.title, ); @@ -325,8 +306,6 @@ export const stateSlice = createSlice({ }; }, setSelectedProfileId: (state, { payload }: PayloadAction) => { - console.log("setSelectedProfileId"); - return { ...state, selectedProfileId: payload, From 2761717b3e46b3489eea5b6ce3d9817360d4f1c9 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 13:38:15 -0800 Subject: [PATCH 48/86] test: typescript definitions --- .../test/files/arrowFunctions.ts | 4 ++ .../test/files/classMethods.ts | 4 ++ .../root-path-context/test/files/functions.ts | 4 ++ .../test/testCases/typescript.ts | 37 +++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts index 02e9d7043..42ef247b0 100644 --- a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts +++ b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts @@ -19,3 +19,7 @@ const getAddresses = (people: Person[]): Address[] => { const logPersonWithAddres = (person: Person
): Person
=> { // TODO }; + +const logPersonOrAddress = (person: Person | Address): Person | Address => { + // TODO +}; diff --git a/core/autocomplete/context/root-path-context/test/files/classMethods.ts b/core/autocomplete/context/root-path-context/test/files/classMethods.ts index 645889b79..36224029b 100644 --- a/core/autocomplete/context/root-path-context/test/files/classMethods.ts +++ b/core/autocomplete/context/root-path-context/test/files/classMethods.ts @@ -24,4 +24,8 @@ class Group { logPersonWithAddress(person: Person
): Person
{ // TODO } + + logPersonOrAddress(person: Person | Address): Person | Address { + // TODO + } } diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index 11e2bf76d..4189f4e20 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -23,3 +23,7 @@ function getAddresses(people: Person[]): Address[] { function logPersonWithAddress(person: Person
): Person
{ // TODO } + +function logPersonOrAddress(person: Person | Address): Person | Address { + // TODO +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 701813a2d..9c490ae23 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -60,6 +60,19 @@ const FUNCTIONS = [ { row: 22, column: 70 }, // Address ], }, + { + nodeType: + "function_declaration with union type params and union return type", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 9 }, + definitionPositions: [ + { row: 26, column: 42 }, // Person + { row: 26, column: 52 }, // Address + { row: 26, column: 61 }, // Person + { row: 26, column: 71 }, // Address + ], + }, ]; const ARROW_FUNCTIONS = [ @@ -113,6 +126,18 @@ const ARROW_FUNCTIONS = [ { row: 18, column: 69 }, // Address ], }, + { + nodeType: "arrow_function with union type params and union return type", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 23, character: 9 }, + definitionPositions: [ + { row: 22, column: 42 }, // Person + { row: 22, column: 52 }, // Address + { row: 22, column: 61 }, // Person + { row: 22, column: 71 }, // Address + ], + }, ]; const CLASS_METHODS = [ @@ -177,6 +202,18 @@ const CLASS_METHODS = [ { row: 23, column: 63 }, // Address ], }, + { + nodeType: "method_declaration with union type params and union return type", + fileName: "classMethods.ts", + language: "TypeScript", + cursorPosition: { line: 28, character: 11 }, + definitionPositions: [ + { row: 27, column: 35 }, // Person + { row: 27, column: 45 }, // Address + { row: 27, column: 54 }, // Person + { row: 27, column: 64 }, // Address + ], + }, ]; export const TYPESCRIPT_TEST_CASES = [ From 553c751562afb736fb914549ba3d2c75e5a4b305 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 14:42:19 -0800 Subject: [PATCH 49/86] fix: restore tests --- .../test/RootPathContextService.test.ts | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index f3a7bd097..fe81a0edd 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -3,61 +3,61 @@ import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ ...TYPESCRIPT_TEST_CASES, - // { - // nodeType: "function_definition", - // fileName: "file1.py", - // language: "Python", - // cursorPosition: { line: 4, character: 25 }, - // definitionPositions: [ - // { row: 3, column: 30 }, // Person - // { row: 3, column: 42 }, // Address - // ], - // }, - // { - // nodeType: "function_definition (inside a class)", - // fileName: "file1.py", - // language: "Python", - // cursorPosition: { line: 12, character: 33 }, - // definitionPositions: [ - // { row: 6, column: 21 }, // BaseClass - // { row: 6, column: 33 }, // Collection - // { row: 11, column: 47 }, // Person - // { row: 11, column: 59 }, // Address - // ], - // }, - // { - // nodeType: "function_definition", - // fileName: "file1.php", - // language: "PHP", - // cursorPosition: { line: 12, character: 32 }, - // definitionPositions: [ - // { row: 10, column: 26 }, // Person - // { row: 10, column: 44 }, // Address - // ], - // }, - // { - // nodeType: "method_declaration", - // fileName: "file1.php", - // language: "PHP", - // cursorPosition: { line: 26, character: 35 }, - // definitionPositions: [ - // { row: 15, column: 29 }, // BaseClass - // { row: 15, column: 55 }, // FirstInterface - // { row: 15, column: 72 }, // SecondInterface - // { row: 25, column: 43 }, // Person - // { row: 25, column: 61 }, // Address - // ], - // }, - // { - // nodeType: "function_declaration", - // fileName: "file1.go", - // language: "Go", - // cursorPosition: { line: 7, character: 21 }, - // definitionPositions: [ - // { row: 6, column: 33 }, // models.User - // { row: 6, column: 50 }, // models.Address - // ], - // }, + { + nodeType: "function_definition", + fileName: "file1.py", + language: "Python", + cursorPosition: { line: 4, character: 25 }, + definitionPositions: [ + { row: 3, column: 30 }, // Person + { row: 3, column: 42 }, // Address + ], + }, + { + nodeType: "function_definition (inside a class)", + fileName: "file1.py", + language: "Python", + cursorPosition: { line: 12, character: 33 }, + definitionPositions: [ + { row: 6, column: 21 }, // BaseClass + { row: 6, column: 33 }, // Collection + { row: 11, column: 47 }, // Person + { row: 11, column: 59 }, // Address + ], + }, + { + nodeType: "function_definition", + fileName: "file1.php", + language: "PHP", + cursorPosition: { line: 12, character: 32 }, + definitionPositions: [ + { row: 10, column: 26 }, // Person + { row: 10, column: 44 }, // Address + ], + }, + { + nodeType: "method_declaration", + fileName: "file1.php", + language: "PHP", + cursorPosition: { line: 26, character: 35 }, + definitionPositions: [ + { row: 15, column: 29 }, // BaseClass + { row: 15, column: 55 }, // FirstInterface + { row: 15, column: 72 }, // SecondInterface + { row: 25, column: 43 }, // Person + { row: 25, column: 61 }, // Address + ], + }, + { + nodeType: "function_declaration", + fileName: "file1.go", + language: "Go", + cursorPosition: { line: 7, character: 21 }, + definitionPositions: [ + { row: 6, column: 33 }, // models.User + { row: 6, column: 50 }, // models.Address + ], + }, ]; describe("RootPathContextService", () => { From 067a3a843baf5a0e12bd5b6f21f37a504836286c Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 14:42:42 -0800 Subject: [PATCH 50/86] fix: restore comments --- .../context/root-path-context/RootPathContextService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index f279b472d..b4b742911 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -75,9 +75,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - const type = node.type; - debugger; - console.log(getSyntaxTreeString(node)); + // const type = node.type; + // debugger; + // console.log(getSyntaxTreeString(node)); query = await getQueryForFile( filepath, From ef715a8e4def60037776b55a9acaf2f1dcc4b736 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 14:46:30 -0800 Subject: [PATCH 51/86] remove state.contextItems cleanup --- gui/src/hooks/useSetup.ts | 4 +--- gui/src/redux/slices/uiStateSlice.ts | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index effe838dc..b96c48ed2 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -14,15 +14,13 @@ import { } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; -import { debounce, initial } from "lodash"; +import { debounce } from "lodash"; import { isJetBrains } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import useChatHandler from "./useChatHandler"; import { useWebviewListener } from "./useWebviewListener"; function useSetup(dispatch: Dispatch) { - // const [configLoaded, setConfigLoaded] = useState(false); - const ideMessenger = useContext(IdeMessengerContext); const initialConfigLoad = useRef(false); diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index 385964881..24c4fc194 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -58,7 +58,6 @@ export const uiStateSlice = createSlice({ state.nextCodeBlockToApplyIndex++; }, updateApplyState: (state, { payload }: PayloadAction) => { - console.log("updateApplyState"); const index = state.applyStates.findIndex( (applyState) => applyState.streamId === payload.streamId, ); From 627bbe9d132336e1889f9331d86a4c3c976970e8 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 15:40:08 -0800 Subject: [PATCH 52/86] bugfix: EDT issues w/ diff streaming --- .../editor/DiffStreamHandler.kt | 30 +++++++++++-------- .../editor/InlineEditAction.kt | 2 +- .../editor/VerticalDiffBlock.kt | 9 ++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt index 0a6b33496..6bea5419e 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt @@ -109,14 +109,14 @@ class DiffStreamHandler( } updateProgressHighlighters(type) - - // Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where - // we reach EOF while in a diff block, since we won't encounter a "same" line. - if (curLine.index >= editor.document.lineCount - 1) { - curLine.diffBlock?.onLastDiffLine() - } } catch (e: Exception) { - println("Error handling diff line: ${curLine.index}, $type, $text, ${e.message}") + println( + "Error handling diff line - " + + "Line index: ${curLine.index}, " + + "Line type: $type, " + + "Line text: $text, " + + "Error message: ${e.message}" + ) } } @@ -139,7 +139,7 @@ class DiffStreamHandler( val diffBlock = VerticalDiffBlock( editor, project, curLine.index, ::handleDiffBlockAcceptOrReject ) - + diffBlocks.add(diffBlock) return diffBlock @@ -251,9 +251,12 @@ class DiffStreamHandler( } private fun handleFinishedResponse() { - onFinish() - ApplicationManager.getApplication().invokeLater { + // Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where + // we reach EOF while in a diff block, since we won't encounter a "same" line. + curLine.diffBlock?.onLastDiffLine() + + onFinish() cleanupProgressHighlighters() } } @@ -267,9 +270,12 @@ class DiffStreamHandler( private fun handleDiffLineResponse(parsed: Map<*, *>) { val data = parsed["content"] as Map<*, *> val diffLineType = getDiffLineType(data["type"] as String) + val lineText = data["line"] as String - WriteCommandAction.runWriteCommandAction(project) { - handleDiffLine(diffLineType, data["line"] as String) + ApplicationManager.getApplication().invokeLater { + WriteCommandAction.runWriteCommandAction(project) { + handleDiffLine(diffLineType, lineText) + } } } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index bd1ac8072..3b23640cc 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -48,7 +48,7 @@ fun makeTextArea(): JTextArea { isOpaque = false background = GetTheme().getSecondaryDark() maximumSize = Dimension(400, Short.MAX_VALUE.toInt()) - margin = JBUI.insets(6, 8, 6, 4) + margin = JBUI.insets(6, 8, 2, 4) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) preferredSize = Dimension(400, 75) } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt index 2990b72e8..a84bf7f9b 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt @@ -29,6 +29,7 @@ class VerticalDiffBlock( private val rejectButton: JButton private var deletionInlay: Disposable? = null private var textArea: JTextArea? = null // Used for calculation of the text area height when rendering buttons + private var hasRenderedDiffBlock: Boolean = false private val editorComponentInlaysManager = EditorComponentInlaysManager.from(editor, false) private val greenKey = createTextAttributesKey("CONTINUE_DIFF_NEW_LINE", 0x3000FF00, editor) @@ -81,11 +82,19 @@ class VerticalDiffBlock( } fun onLastDiffLine() { + // Handles the case where we are invoking one last time on last line of diff stream, but the block has + // already been rendered + if (hasRenderedDiffBlock) { + return + } + if (deletedLines.size > 0) { renderDeletedLinesInlay() } renderButtons() + + hasRenderedDiffBlock = true } fun handleReject() { From 550d18d43f7c4e9f86cae006e7f02a7db616beaa Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 15:43:40 -0800 Subject: [PATCH 53/86] Update DiffStreamHandler.kt --- .../continueintellijextension/editor/DiffStreamHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt index 6bea5419e..3f25b87cb 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt @@ -253,7 +253,7 @@ class DiffStreamHandler( private fun handleFinishedResponse() { ApplicationManager.getApplication().invokeLater { // Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where - // we reach EOF while in a diff block, since we won't encounter a "same" line. + // the last line in the diff stream is in the middle of a diff block. curLine.diffBlock?.onLastDiffLine() onFinish() From 576a93ff940b48d6600d5c108f97299f3e15e7c7 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 15:29:18 -0800 Subject: [PATCH 54/86] refactor: group tree sitter queries by language --- .../context/ImportDefinitionsService.ts | 8 +++++-- .../RootPathContextService.ts | 18 ++++++++++----- core/indexing/CodeSnippetsIndex.ts | 22 ++++++++++++++----- core/util/treeSitter.ts | 16 +++++--------- .../cpp.scm => cpp/function_definition.scm} | 0 .../go.scm => go/function_declaration.scm} | 0 .../java.scm => java/method_declaration.scm} | 0 .../php.scm => php/class_declaration.scm} | 0 .../php.scm => php/function_definition.scm} | 0 .../php.scm => php/method_declaration.scm} | 0 .../class_definition.scm} | 0 .../function_definition.scm} | 0 .../arrow_function.scm} | 0 .../class_declaration.scm} | 0 .../function_declaration.scm} | 0 .../method_definition.scm} | 0 16 files changed, 40 insertions(+), 24 deletions(-) rename extensions/vscode/tree-sitter/root-path-context-queries/{function_definition/cpp.scm => cpp/function_definition.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{function_declaration/go.scm => go/function_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{method_declaration/java.scm => java/method_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{class_declaration/php.scm => php/class_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{function_definition/php.scm => php/function_definition.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{method_declaration/php.scm => php/method_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{class_definition/python.scm => python/class_definition.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{function_definition/python.scm => python/function_definition.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{arrow_function/typescript.scm => typescript/arrow_function.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{class_declaration/typescript.scm => typescript/class_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{function_declaration/typescript.scm => typescript/function_declaration.scm} (100%) rename extensions/vscode/tree-sitter/root-path-context-queries/{method_definition/typescript.scm => typescript/method_definition.scm} (100%) diff --git a/core/autocomplete/context/ImportDefinitionsService.ts b/core/autocomplete/context/ImportDefinitionsService.ts index 0df08f096..525834a95 100644 --- a/core/autocomplete/context/ImportDefinitionsService.ts +++ b/core/autocomplete/context/ImportDefinitionsService.ts @@ -2,7 +2,7 @@ import { IDE } from "../.."; import { RangeInFileWithContents } from "../../commands/util"; import { PrecalculatedLruCache } from "../../util/LruCache"; import { - TSQueryType, + getFullLanguageName, getParserForFile, getQueryForFile, } from "../../util/treeSitter"; @@ -47,7 +47,11 @@ export class ImportDefinitionsService { }, ], }); - const query = await getQueryForFile(filepath, TSQueryType.Imports); + const language = getFullLanguageName(filepath); + const query = await getQueryForFile( + filepath, + `import-queries/${language}.scm`, + ); if (!query) { return { imports: {}, diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index b4b742911..7a9d26548 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -4,7 +4,7 @@ import { LRUCache } from "lru-cache"; import Parser from "web-tree-sitter"; import { IDE } from "../../.."; -import { getQueryForFile } from "../../../util/treeSitter"; +import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; import { AstPath } from "../../util/ast"; import { ImportDefinitionsService } from "../ImportDefinitionsService"; import { AutocompleteSnippet } from "../ranking"; @@ -78,10 +78,11 @@ export class RootPathContextService { // const type = node.type; // debugger; // console.log(getSyntaxTreeString(node)); + const language = getFullLanguageName(filepath); query = await getQueryForFile( filepath, - `root-path-context-queries/${node.type}`, + `root-path-context-queries/${language}/${node.type}.scm`, ); break; } @@ -93,9 +94,14 @@ export class RootPathContextService { const queries = query.matches(node).map(async (match) => { for (const item of match.captures) { - const endPosition = item.node.endPosition; - const newSnippets = await this.getSnippets(filepath, endPosition); - snippets.push(...newSnippets); + try { + const endPosition = item.node.endPosition; + const newSnippets = await this.getSnippets(filepath, endPosition); + snippets.push(...newSnippets); + } catch (e) { + debugger; + throw e; + } } }); @@ -151,7 +157,7 @@ export class RootPathContextService { parentKey = key; } - + debugger; return snippets; } } diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 8e1edcc7b..0138817f6 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -3,12 +3,17 @@ import Parser from "web-tree-sitter"; import { getBasename, getLastNPathParts } from "../util/"; import { migrate } from "../util/paths"; import { - TSQueryType, + getFullLanguageName, getParserForFile, getQueryForFile, } from "../util/treeSitter"; -import { DatabaseConnection, SqliteDb, tagToString, truncateSqliteLikePattern } from "./refreshIndex"; +import { + DatabaseConnection, + SqliteDb, + tagToString, + truncateSqliteLikePattern, +} from "./refreshIndex"; import { IndexResultType, MarkCompleteCallback, @@ -31,7 +36,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { relativeExpectedTime: number = 1; artifactId = "codeSnippets"; - constructor(private readonly ide: IDE) { } + constructor(private readonly ide: IDE) {} private static async _createTables(db: DatabaseConnection) { await db.exec(`CREATE TABLE IF NOT EXISTS code_snippets ( @@ -183,7 +188,12 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { } const ast = parser.parse(contents); - const query = await getQueryForFile(filepath, TSQueryType.CodeSnippets); + + const language = getFullLanguageName(filepath); + const query = await getQueryForFile( + filepath, + `code-snippet-queries/${language}.scm`, + ); const matches = query?.matches(ast.rootNode); if (!matches) { @@ -386,7 +396,9 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { const db = await SqliteDb.get(); await CodeSnippetsCodebaseIndex._createTables(db); - const likePatterns = workspaceDirs.map((dir) => truncateSqliteLikePattern(`${dir}%`)); + const likePatterns = workspaceDirs.map((dir) => + truncateSqliteLikePattern(`${dir}%`), + ); const placeholders = likePatterns.map(() => "?").join(" OR path LIKE "); const query = ` diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index b877a251b..707bfdaa6 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -128,15 +128,9 @@ export async function getLanguageForFile( } } -export enum TSQueryType { - CodeSnippets = "code-snippet-queries", - Imports = "import-queries", - // Used in RootPathContextService.ts - FunctionDeclaration = "root-path-context-queries/function_declaration", - MethodDefinition = "root-path-context-queries/method_definition", - FunctionDefinition = "root-path-context-queries/function_definition", - MethodDeclaration = "root-path-context-queries/method_declaration", -} +export const getFullLanguageName = (filepath: string) => { + return supportedLanguages[filepath.split(".").pop() ?? ""]; +}; export async function getQueryForFile( filepath: string, @@ -147,7 +141,7 @@ export async function getQueryForFile( return undefined; } - const fullLangName = supportedLanguages[filepath.split(".").pop() ?? ""]; + // const fullLangName = getFullLanguageName(filepath); const sourcePath = path.join( __dirname, "..", @@ -155,7 +149,7 @@ export async function getQueryForFile( ? ["extensions", "vscode", "tree-sitter"] : ["tree-sitter"]), queryPath, - `${fullLangName}.scm`, + // `${fullLangName}.scm`, ); if (!fs.existsSync(sourcePath)) { return undefined; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/cpp.scm b/extensions/vscode/tree-sitter/root-path-context-queries/cpp/function_definition.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/function_definition/cpp.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/cpp/function_definition.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm b/extensions/vscode/tree-sitter/root-path-context-queries/go/function_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/go.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/go/function_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/java.scm b/extensions/vscode/tree-sitter/root-path-context-queries/java/method_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/java.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/java/method_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/php/class_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/php.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/php/class_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/php/function_definition.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/function_definition/php.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/php/function_definition.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm b/extensions/vscode/tree-sitter/root-path-context-queries/php/method_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/method_declaration/php.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/php/method_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/class_definition/python.scm b/extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/class_definition/python.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_definition/python.scm b/extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/function_definition/python.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/arrow_function.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/arrow_function/typescript.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/typescript/arrow_function.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/class_declaration/typescript.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/function_declaration.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/function_declaration/typescript.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/typescript/function_declaration.scm diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/method_definition.scm similarity index 100% rename from extensions/vscode/tree-sitter/root-path-context-queries/method_definition/typescript.scm rename to extensions/vscode/tree-sitter/root-path-context-queries/typescript/method_definition.scm From 62a4e434f194dc6163faaea647136744c6033056 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 16:00:14 -0800 Subject: [PATCH 55/86] refactor: clean up code --- core/util/treeSitter.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index 707bfdaa6..4fe0d1665 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -141,7 +141,6 @@ export async function getQueryForFile( return undefined; } - // const fullLangName = getFullLanguageName(filepath); const sourcePath = path.join( __dirname, "..", @@ -149,7 +148,6 @@ export async function getQueryForFile( ? ["extensions", "vscode", "tree-sitter"] : ["tree-sitter"]), queryPath, - // `${fullLangName}.scm`, ); if (!fs.existsSync(sourcePath)) { return undefined; From 2bb2e655754cd2f4a6b474cd15169fa16d460836 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 16:33:05 -0800 Subject: [PATCH 56/86] refresh index for files --- core/core.ts | 80 ++++++++++++++----- core/indexing/CodebaseIndexer.ts | 77 ++++++++++++++---- core/protocol/core.ts | 1 + core/protocol/passThrough.ts | 3 +- .../ContinuePluginStartupActivity.kt | 4 +- .../toolWindow/ContinueBrowser.kt | 1 + .../vscode/src/extension/VsCodeExtension.ts | 10 +-- 7 files changed, 133 insertions(+), 43 deletions(-) diff --git a/core/core.ts b/core/core.ts index 6df1482ef..a5514490a 100644 --- a/core/core.ts +++ b/core/core.ts @@ -83,7 +83,7 @@ export class Core { constructor( private readonly messenger: IMessenger, private readonly ide: IDE, - private readonly onWrite: (text: string) => Promise = async () => { }, + private readonly onWrite: (text: string) => Promise = async () => {}, ) { // Ensure .continue directory is created setupInitialDotContinueDirectory(); @@ -174,7 +174,7 @@ export class Core { this.configHandler, ide, getLlm, - (e) => { }, + (e) => {}, (..._) => Promise.resolve([]), ); @@ -684,9 +684,14 @@ export class Core { await codebaseIndexer.clearIndexes(); } - const dirs = data?.dirs ?? await this.ide.getWorkspaceDirs(); + const dirs = data?.dirs ?? (await this.ide.getWorkspaceDirs()); await this.refreshCodebaseIndex(dirs); }); + on("index/forceReIndexFiles", async ({ data }) => { + if (data?.files?.length) { + await this.refreshCodebaseIndexFiles(data.files); + } + }); on("index/setPaused", (msg) => { new GlobalContext().update("indexingPaused", msg.data); this.indexingPauseToken.paused = msg.data; @@ -722,14 +727,29 @@ export class Core { } private indexingCancellationController: AbortController | undefined; + private async sendIndexingTelemetry(update: IndexingProgressUpdate) { + console.debug( + "Indexing failed with error: ", + update.desc, + update.debugInfo, + ); + void Telemetry.capture( + "indexing_error", + { + error: update.desc, + stack: update.debugInfo, + }, + false, + ); + } - private async refreshCodebaseIndex(dirs: string[]) { + private async refreshCodebaseIndex(paths: string[]) { if (this.indexingCancellationController) { this.indexingCancellationController.abort(); } this.indexingCancellationController = new AbortController(); - for await (const update of (await this.codebaseIndexerPromise).refresh( - dirs, + for await (const update of (await this.codebaseIndexerPromise).refreshDirs( + paths, this.indexingCancellationController.signal, )) { let updateToSend = { ...update }; @@ -743,19 +763,41 @@ export class Core { this.indexingState = updateToSend; if (update.status === "failed") { - console.debug( - "Indexing failed with error: ", - update.desc, - update.debugInfo, - ); - void Telemetry.capture( - "indexing_error", - { - error: update.desc, - stack: update.debugInfo, - }, - false, - ); + void this.sendIndexingTelemetry(update); + } + } + + this.messenger.send("refreshSubmenuItems", undefined); + } + + private async refreshCodebaseIndexFiles(files: string[]) { + // Can be cancelled by codebase index but not vice versa + if ( + this.indexingCancellationController && + !this.indexingCancellationController.signal.aborted + ) { + return console.debug( + "Codebase indexing already in progress, skipping indexing of files\n" + + files.join("\n"), + ); + } + this.indexingCancellationController = new AbortController(); + for await (const update of (await this.codebaseIndexerPromise).refreshFiles( + files, + this.indexingCancellationController.signal, + )) { + let updateToSend = { ...update }; + if (update.status === "failed") { + updateToSend.status = "done"; + updateToSend.desc = "Indexing complete"; + updateToSend.progress = 1.0; + } + + void this.messenger.request("indexProgress", updateToSend); + this.indexingState = updateToSend; + + if (update.status === "failed") { + void this.sendIndexingTelemetry(update); } } diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index b4962d182..175e1a062 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -17,6 +17,7 @@ import { RefreshIndexResults, } from "./types.js"; import { walkDirAsync } from "./walkDir.js"; +import { getBasename } from "../util/index.js"; export class PauseToken { constructor(private _paused: boolean) {} @@ -144,13 +145,61 @@ export class CodebaseIndexer { } } - async *refresh( - workspaceDirs: string[], + async *refreshFiles( + files: string[], + abortSignal: AbortSignal, + ): AsyncGenerator { + let progress = 0; + if (files.length === 0) { + yield { + progress: 1, + desc: "Indexing Complete", + status: "done", + }; + } + + const progressPer = 1 / files.length; + try { + for (const file of files) { + yield { + progress, + desc: `Indexing file ${file}...`, + status: "indexing", + }; + await this.refreshFile(file); + + progress += progressPer; + + if (this.pauseToken.paused) { + yield* this.yieldUpdateAndPause(); + } + if (abortSignal.aborted) { + yield { + progress: 1, + desc: "Indexing cancelled", + status: "disabled", + }; + return; + } + } + + yield { + progress: 1, + desc: "Indexing Complete", + status: "done", + }; + } catch (err) { + yield this.handleErrorAndGetProgressUpdate(err); + } + } + + async *refreshDirs( + dirs: string[], abortSignal: AbortSignal, ): AsyncGenerator { let progress = 0; - if (workspaceDirs.length === 0) { + if (dirs.length === 0) { yield { progress, desc: "Nothing to index", @@ -175,11 +224,9 @@ export class CodebaseIndexer { }; } - let completedDirs = 0; - // Wait until Git Extension has loaded to report progress // so we don't appear stuck at 0% while waiting - await this.ide.getRepoName(workspaceDirs[0]); + await this.ide.getRepoName(dirs[0]); yield { progress, @@ -188,16 +235,16 @@ export class CodebaseIndexer { }; const beginTime = Date.now(); - for (const directory of workspaceDirs) { + for (const directory of dirs) { const dirBasename = await this.basename(directory); yield { progress, desc: `Discovering files in ${dirBasename}...`, status: "indexing", }; - const workspaceFiles = []; + const directoryFiles = []; for await (const p of walkDirAsync(directory, this.ide)) { - workspaceFiles.push(p); + directoryFiles.push(p); if (abortSignal.aborted) { yield { progress: 1, @@ -218,7 +265,7 @@ export class CodebaseIndexer { try { for await (const updateDesc of this.indexFiles( directory, - workspaceFiles, + directoryFiles, branch, repoName, )) { @@ -240,7 +287,7 @@ export class CodebaseIndexer { nextLogThreshold += 0.025; this.logProgress( beginTime, - Math.floor(workspaceFiles.length * updateDesc.progress), + Math.floor(directoryFiles.length * updateDesc.progress), updateDesc.progress, ); } @@ -347,18 +394,18 @@ export class CodebaseIndexer { } private async *indexFiles( - workspaceDir: string, - workspaceFiles: string[], + directory: string, + files: string[], branch: string, repoName: string | undefined, ): AsyncGenerator { - const stats = await this.ide.getLastModified(workspaceFiles); + const stats = await this.ide.getLastModified(files); const indexesToBuild = await this.getIndexesToBuild(); let completedIndexCount = 0; let progress = 0; for (const codebaseIndex of indexesToBuild) { const tag: IndexTag = { - directory: workspaceDir, + directory, branch, artifactId: codebaseIndex.artifactId, }; diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 2c9af1433..e30de4673 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -147,6 +147,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { undefined | { dirs?: string[]; shouldClearIndexes?: boolean }, void, ]; + "index/forceReIndexFiles": [undefined | { files?: string[] }, void]; "index/indexingProgressBarInitialized": [undefined, void]; completeOnboarding: [ { diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 1c0f5e962..21ac52c8d 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -41,6 +41,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "stats/getTokensPerModel", "index/setPaused", "index/forceReIndex", + "index/forceReIndexFiles", "index/indexingProgressBarInitialized", "completeOnboarding", "addAutocompleteModel", @@ -60,5 +61,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "isContinueInputFocused", "didChangeAvailableProfiles", "setTTSActive", - "getWebviewHistoryLength" + "getWebviewHistoryLength", ]; diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt index fa39729fa..451baae68 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt @@ -169,8 +169,8 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { // Create a data map if there are any paths to re-index if (allPaths.isNotEmpty()) { - val data = mapOf("dirs" to allPaths) - continuePluginService.coreMessenger?.request("index/forceReIndex", data, null) { _ -> } + val data = mapOf("files" to allPaths) + continuePluginService.coreMessenger?.request("index/forceReIndexFiles", data, null) { _ -> } } } }) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 26896906b..147f153e3 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -58,6 +58,7 @@ class ContinueBrowser(val project: Project, url: String) { "stats/getTokensPerModel", "index/setPaused", "index/forceReIndex", + "index/forceReIndexFiles", "index/indexingProgressBarInitialized", "completeOnboarding", "addAutocompleteModel", diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 06263e356..bb46e7466 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -297,17 +297,15 @@ export class VsCodeExtension { this.core.invoke("index/forceReIndex", undefined); } else { // Reindex the file - this.core.invoke("index/forceReIndex", { - dirs: [filepath], + this.core.invoke("index/forceReIndexFiles", { + files: [filepath], }); } }); vscode.workspace.onDidDeleteFiles(async (event) => { - this.core.invoke("index/forceReIndex", { - dirs: event.files.map((file) => - file.fsPath.split("/").slice(0, -1).join("/"), - ), + this.core.invoke("index/forceReIndexFiles", { + files: event.files.map((file) => file.fsPath), }); }); From ffd2214ec18082ab88d3d07065448351d83a716f Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 17:03:01 -0800 Subject: [PATCH 57/86] Update handler.ts --- .../vscode/src/diff/vertical/handler.ts | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/extensions/vscode/src/diff/vertical/handler.ts b/extensions/vscode/src/diff/vertical/handler.ts index 1ec5a60b6..f2bf20ef6 100644 --- a/extensions/vscode/src/diff/vertical/handler.ts +++ b/extensions/vscode/src/diff/vertical/handler.ts @@ -25,9 +25,12 @@ export class VerticalDiffHandler implements vscode.Disposable { private currentLineIndex: number; private cancelled = false; private newLinesAdded = 0; - private get diffBlocks() { - return this.editorToVerticalDiffCodeLens.get(this.filepath) || []; + private deletionBuffer: string[] = []; + private redDecorationManager: DecorationTypeRangeManager; + private get filepath() { + return this.editor.document.uri.fsPath; } + public insertedInCurrentBlock = 0; public get range(): vscode.Range { const startLine = Math.min(this.startLine, this.endLine); const endLine = Math.max(this.startLine, this.endLine); @@ -77,14 +80,6 @@ export class VerticalDiffHandler implements vscode.Disposable { this.disposables.push(disposable); } - private get filepath() { - return this.editor.document.uri.fsPath; - } - - private deletionBuffer: string[] = []; - private redDecorationManager: DecorationTypeRangeManager; - insertedInCurrentBlock = 0; - private async insertDeletionBuffer() { // Don't remove trailing whitespace line const totalDeletedContent = this.deletionBuffer.join("\n"); @@ -98,13 +93,15 @@ export class VerticalDiffHandler implements vscode.Disposable { } if (this.deletionBuffer.length || this.insertedInCurrentBlock > 0) { - this.diffBlocks.push({ + const blocks = this.editorToVerticalDiffCodeLens.get(this.filepath) || []; + + blocks.push({ start: this.currentLineIndex - this.insertedInCurrentBlock, numRed: this.deletionBuffer.length, numGreen: this.insertedInCurrentBlock, }); - this.editorToVerticalDiffCodeLens.set(this.filepath, this.diffBlocks); + this.editorToVerticalDiffCodeLens.set(this.filepath, blocks); } if (this.deletionBuffer.length === 0) { @@ -271,7 +268,10 @@ export class VerticalDiffHandler implements vscode.Disposable { }, ); - this.options.onStatusUpdate("closed", this.diffBlocks.length); + this.options.onStatusUpdate( + "closed", + this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0, + ); this.cancelled = true; this.refreshCodeLens(); @@ -359,7 +359,10 @@ export class VerticalDiffHandler implements vscode.Disposable { this.refreshCodeLens(); - this.options.onStatusUpdate("done", this.diffBlocks.length); + this.options.onStatusUpdate( + "done", + this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0, + ); // Reject on user typing // const listener = vscode.workspace.onDidChangeTextDocument((e) => { @@ -409,8 +412,11 @@ export class VerticalDiffHandler implements vscode.Disposable { // Shift the codelens objects this.shiftCodeLensObjects(startLine, offset); - const status = this.diffBlocks.length === 0 ? "closed" : undefined; - this.options.onStatusUpdate(status, this.diffBlocks.length); + const numDiffs = + this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0; + + const status = numDiffs === 0 ? "closed" : undefined; + this.options.onStatusUpdate(status, numDiffs); } private shiftCodeLensObjects(startLine: number, offset: number) { @@ -450,6 +456,7 @@ export class VerticalDiffHandler implements vscode.Disposable { } public hasDiffForCurrentFile(): boolean { - return this.diffBlocks.length > 0; + const diffBlocks = this.editorToVerticalDiffCodeLens.get(this.filepath); + return diffBlocks !== undefined && diffBlocks.length > 0; } } From a7a50280833007e8f0a3d908e3dd7544a2557dcb Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 14 Nov 2024 17:03:30 -0800 Subject: [PATCH 58/86] Update StepContainerPreToolbar.tsx --- .../StepContainerPreToolbar.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index ac13c6d54..0fa57fd08 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -2,7 +2,7 @@ import { ChevronDownIcon } from "@heroicons/react/24/outline"; import { debounce } from "lodash"; import { useContext, useEffect, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; -import styled, { keyframes } from "styled-components"; +import styled, { css, keyframes } from "styled-components"; import { v4 as uuidv4 } from "uuid"; import { defaultBorderRadius, lightGray, vscEditorBackground } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; @@ -26,13 +26,18 @@ const fadeInAnimation = keyframes` } `; -const TopDiv = styled.div` +const TopDiv = styled.div<{ active?: boolean }>` outline: 1px solid rgba(153, 153, 152); outline-offset: -0.5px; border-radius: ${defaultBorderRadius}; margin-bottom: 8px !important; background-color: ${vscEditorBackground}; - animation: ${fadeInAnimation} 300ms ease-out forwards; + ${(props) => + props.active + ? "animation: none;" + : css` + animation: ${fadeInAnimation} 300ms ease-out forwards; + `} `; const ToolbarDiv = styled.div<{ isExpanded: boolean }>` @@ -67,6 +72,7 @@ export default function StepContainerPreToolbar( const isMultifileEdit = useSelector( (state: RootState) => state.state.isInMultifileEdit, ); + const active = useSelector((state: RootState) => state.state.active); const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true); const [codeBlockContent, setCodeBlockContent] = useState(""); const isChatActive = useSelector((state: RootState) => state.state.active); @@ -168,7 +174,7 @@ export default function StepContainerPreToolbar( } return ( - +
Date: Thu, 14 Nov 2024 17:14:07 -0800 Subject: [PATCH 59/86] index files - cleanup --- core/core.ts | 8 ++++---- core/indexing/CodebaseIndexer.ts | 9 --------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/core/core.ts b/core/core.ts index a5514490a..63c03a730 100644 --- a/core/core.ts +++ b/core/core.ts @@ -727,7 +727,7 @@ export class Core { } private indexingCancellationController: AbortController | undefined; - private async sendIndexingTelemetry(update: IndexingProgressUpdate) { + private async sendIndexingErrorTelemetry(update: IndexingProgressUpdate) { console.debug( "Indexing failed with error: ", update.desc, @@ -763,11 +763,12 @@ export class Core { this.indexingState = updateToSend; if (update.status === "failed") { - void this.sendIndexingTelemetry(update); + void this.sendIndexingErrorTelemetry(update); } } this.messenger.send("refreshSubmenuItems", undefined); + this.indexingCancellationController = undefined; } private async refreshCodebaseIndexFiles(files: string[]) { @@ -784,7 +785,6 @@ export class Core { this.indexingCancellationController = new AbortController(); for await (const update of (await this.codebaseIndexerPromise).refreshFiles( files, - this.indexingCancellationController.signal, )) { let updateToSend = { ...update }; if (update.status === "failed") { @@ -797,7 +797,7 @@ export class Core { this.indexingState = updateToSend; if (update.status === "failed") { - void this.sendIndexingTelemetry(update); + void this.sendIndexingErrorTelemetry(update); } } diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index 175e1a062..5c70f8bad 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -147,7 +147,6 @@ export class CodebaseIndexer { async *refreshFiles( files: string[], - abortSignal: AbortSignal, ): AsyncGenerator { let progress = 0; if (files.length === 0) { @@ -173,14 +172,6 @@ export class CodebaseIndexer { if (this.pauseToken.paused) { yield* this.yieldUpdateAndPause(); } - if (abortSignal.aborted) { - yield { - progress: 1, - desc: "Indexing cancelled", - status: "disabled", - }; - return; - } } yield { From 6e5301657a7cdcfce7239f491a0ea9a0fc053ab0 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 19:42:46 -0800 Subject: [PATCH 60/86] index files test --- core/indexing/CodebaseIndexer.test.ts | 21 ++++++++++++++++++- .../vscode/src/extension/VsCodeExtension.ts | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/indexing/CodebaseIndexer.test.ts b/core/indexing/CodebaseIndexer.test.ts index 5b59c39fa..ee2f108f7 100644 --- a/core/indexing/CodebaseIndexer.test.ts +++ b/core/indexing/CodebaseIndexer.test.ts @@ -89,7 +89,7 @@ describe("CodebaseIndexer", () => { const abortSignal = abortController.signal; const updates = []; - for await (const update of codebaseIndexer.refresh( + for await (const update of codebaseIndexer.refreshDirs( [TEST_DIR], abortSignal, )) { @@ -98,6 +98,16 @@ describe("CodebaseIndexer", () => { return updates; } + async function refreshIndexFiles(files: string[]) { + const updates = []; + for await (const update of codebaseIndexer.refreshFiles( + files, + )) { + updates.push(update); + } + return updates; + } + async function getAllIndexedFiles() { const files = await testIndex.getIndexedFilesForTags( await testIde.getTags(testIndex.artifactId), @@ -158,6 +168,15 @@ describe("CodebaseIndexer", () => { expect(indexed.some((file) => file.endsWith("main.py"))).toBe(true); }); + test("should successfuly re-index specific files", async () => { + // Could add more specific tests for this but uses similar logic + const before = await getAllIndexedFiles(); + await refreshIndexFiles(before); + + const after = await getAllIndexedFiles(); + expect(after.length).toBe(before.length); + }); + test("should successfully re-index after adding a file", async () => { addToTestDir([["main.rs", TEST_RS]]); diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index bb46e7466..84d0a667c 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -309,6 +309,12 @@ export class VsCodeExtension { }); }); + vscode.workspace.onDidCreateFiles(async (event) => { + this.core.invoke("index/forceReIndexFiles", { + files: event.files.map((file) => file.fsPath), + }); + }); + // When GitHub sign-in status changes, reload config vscode.authentication.onDidChangeSessions(async (e) => { if (e.provider.id === "github") { From 9d40e64169722282972b02c1d4b4bfaa5875eccf Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 20:32:57 -0800 Subject: [PATCH 61/86] docs for prompt files v2 --- .../docs/customize/deep-dives/prompt-files.md | 61 +++++-------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/docs/docs/customize/deep-dives/prompt-files.md b/docs/docs/customize/deep-dives/prompt-files.md index 928e01543..91f3557ea 100644 --- a/docs/docs/customize/deep-dives/prompt-files.md +++ b/docs/docs/customize/deep-dives/prompt-files.md @@ -6,9 +6,9 @@ Prompt files provide a convenient way to standardize common patterns and share a ## Quick start -:::tip[Prompt library] + Below is a quick example of setting up a prompt file to write unit tests using Jest. @@ -17,31 +17,19 @@ Below is a quick example of setting up a prompt file to write unit tests using J 3. Write the following contents to `test.prompt` and save. ``` -temperature: 0.5 -maxTokens: 4096 +name: Rails Project +description: Information about this project --- - -You are an expert programmer - - -{{{ input }}} - -Write unit tests for the above selected code, following each of these instructions: -- Use `jest` -- Properly set up and tear down -- Include important edge cases -- The tests should be complete and sophisticated -- Give the tests just as chat output, don't edit any file -- Don't explain how to set up `jest` +Attached is a summary of the current Ruby on Rails application, including the @Gemfile and database schema in @db/schema.rb ``` Now to use this prompt, you can highlight code and use cmd/ctrl + L to select it in the Continue sidebar. -Then, type "/" to see the list of slash commands and choose the one called "test". Press enter and the LLM will respond given the instructions from your prompt file. +Then, type "@", select "Prompt files", and choose the one called "Rails Project". You can now ask any question as usual and the LLM will have the information from your .prompt file. ## Format -The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to use context providers and built-in variables using [Handlebars syntax](https://handlebarsjs.com/guide/). +The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to reference files, URLs, and context providers. :::info The current state of this format is experimental and subject to change @@ -51,38 +39,19 @@ The current state of this format is experimental and subject to change The "preamble" is everything above the `---` separator, and lets you specify model parameters. It uses YAML syntax and currently supports the following parameters: -- `name` -- `temperature` -- `topP` -- `topK` -- `minP` -- `presencePenalty` -- `frequencyPenalty` -- `mirostat` -- `stop` -- `maxTokens` -- `description` +- `name` - The display title +- `description` - The description you will see in the dropdown +- `version` - Can be either "1" (for legacy prompt files) or "2" (this is the default and does not need to be set) If you don't need any of these parameters, you can leave out the preamble and do not need to include the `---` separator. -### System message +### Context -To add a system message, start the body with `` tags like in the example above and place your system message inside. +Many [context provider](../context-providers.md) can be referenced by typing "@" followed by the name of the context provider. -### Built-in variables - -The following built-in variables are currently available: - -- `{{{ input }}}` - The full text from the input box in the sidebar that is sent along with the slash command -- `{{{ currentFile }}}` - The currently open file in your IDE -- `{{{ ./path/to/file.js }}}` - Any file can be directly referenced - -### Context providers - -Any [context provider](../context-providers.md) that you have added to your config can be referenced using the name of the context provider. Context providers that receive an input are also supported. - -- `{{{ terminal }}}` - The contents of the terminal -- `{{{ url "https://github.com/continuedev/continue" }}}` - The contents of a URL +- `@terminal` - The contents of the terminal +- `@https://github.com/continuedev/continue` - The contents of a URL +- `@src/index.ts` - The contents of a file ## Feedback From a48a150b2024fca63cb50fb09a914a391c0cfce5 Mon Sep 17 00:00:00 2001 From: liuk Date: Fri, 15 Nov 2024 15:22:47 +0800 Subject: [PATCH 62/86] fix: Add ContinuePluginDisposable to avoid memory leaks in Jetbrains --- .../activities/ContinuePluginDisposable.kt | 32 +++++++++++++++++++ .../ContinuePluginStartupActivity.kt | 7 ++-- .../AutocompleteSpinnerWidgetFactory.kt | 3 +- .../continue/IdeProtocolClient.kt | 7 ++-- .../toolWindow/ContinueBrowser.kt | 3 +- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginDisposable.kt diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginDisposable.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginDisposable.kt new file mode 100644 index 000000000..e8d3d0788 --- /dev/null +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginDisposable.kt @@ -0,0 +1,32 @@ +package com.github.continuedev.continueintellijextension.activities + +import com.intellij.openapi.Disposable +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.Service +import com.intellij.openapi.project.Project + +/** + * The service is a parent disposable that represents the entire plugin lifecycle + * and is intended to be used instead of the project/application as a parent disposable, + * ensures that disposables registered using it as parents will be processed when the plugin is unloaded to avoid memory leaks. + * + * @author lk + */ +@Service(Service.Level.APP, Service.Level.PROJECT) +class ContinuePluginDisposable : Disposable { + + override fun dispose() { + } + + companion object { + + fun getInstance(): ContinuePluginDisposable { + return ApplicationManager.getApplication().getService(ContinuePluginDisposable::class.java) + } + + fun getInstance(project: Project): ContinuePluginDisposable { + return project.getService(ContinuePluginDisposable::class.java) + } + + } +} \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt index fa39729fa..969fa12bd 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt @@ -70,7 +70,7 @@ private fun getTutorialFileName(): String { } } -class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { +class ContinuePluginStartupActivity : StartupActivity, DumbAware { override fun runActivity(project: Project) { removeShortcutFromAction(getPlatformSpecificKeyStroke("J")) @@ -225,14 +225,11 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware { EditorFactory.getInstance().eventMulticaster.addSelectionListener( listener, - this@ContinuePluginStartupActivity + ContinuePluginDisposable.getInstance(project) ) val coreMessengerManager = CoreMessengerManager(project, ideProtocolClient, coroutineScope) continuePluginService.coreMessengerManager = coreMessengerManager } } - - override fun dispose() { - } } \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteSpinnerWidgetFactory.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteSpinnerWidgetFactory.kt index 299614665..98be79f74 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteSpinnerWidgetFactory.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteSpinnerWidgetFactory.kt @@ -1,5 +1,6 @@ package com.github.continuedev.continueintellijextension.autocomplete +import com.github.continuedev.continueintellijextension.activities.ContinuePluginDisposable import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings import com.intellij.openapi.Disposable import com.intellij.openapi.components.service @@ -35,7 +36,7 @@ class AutocompleteSpinnerWidget(project: Project) : EditorBasedWidget(project), ) init { - Disposer.register(project, this) + Disposer.register(ContinuePluginDisposable.getInstance(project), this) updateIcon() } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index c2a35a918..c48c8e58b 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -1,5 +1,6 @@ package com.github.continuedev.continueintellijextension.`continue` +import com.github.continuedev.continueintellijextension.activities.ContinuePluginDisposable import com.github.continuedev.continueintellijextension.auth.AuthListener import com.github.continuedev.continueintellijextension.auth.ContinueAuthService import com.github.continuedev.continueintellijextension.constants.getConfigJsPath @@ -132,9 +133,9 @@ class IdeProtocolClient( initIdeProtocol() // Setup config.json / config.ts save listeners - VirtualFileManager.getInstance().addAsyncFileListener(AsyncFileSaveListener(this), object : Disposable { - override fun dispose() {} - }) + VirtualFileManager.getInstance().addAsyncFileListener( + AsyncFileSaveListener(this), ContinuePluginDisposable.getInstance(project) + ) val myPluginId = "com.github.continuedev.continueintellijextension" val pluginDescriptor = diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 26896906b..94556d3f5 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -1,5 +1,6 @@ package com.github.continuedev.continueintellijextension.toolWindow +import com.github.continuedev.continueintellijextension.activities.ContinuePluginDisposable import com.github.continuedev.continueintellijextension.activities.showTutorial import com.github.continuedev.continueintellijextension.constants.MessageTypes import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath @@ -88,7 +89,7 @@ class ContinueBrowser(val project: Project, url: String) { registerAppSchemeHandler() browser.loadURL(url); - Disposer.register(project, browser) + Disposer.register(ContinuePluginDisposable.getInstance(project), browser) // Listen for events sent from browser val myJSQueryOpenInBrowser = JBCefJSQuery.create((browser as JBCefBrowserBase?)!!) From 97bc07453ba067f0438192d8dc6cc1cc9a86d962 Mon Sep 17 00:00:00 2001 From: liuk Date: Fri, 15 Nov 2024 19:10:33 +0800 Subject: [PATCH 63/86] fix: The selected item in inline chat is always the first one --- .../editor/InlineEditAction.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index bd1ac8072..f0862b18e 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -40,6 +40,8 @@ import org.jdesktop.swingx.JXTextArea const val MAIN_FONT_SIZE = 13 +const val DOWN_ARROW = " â–¾" + fun makeTextArea(): JTextArea { val textArea = CustomTextArea(1, 40).apply { @@ -206,7 +208,7 @@ fun openInlineEdit(project: Project?, editor: Editor) { val comboBoxRef = Ref>() fun onEnter() { - val selectedModelStrippedOfCaret = (comboBoxRef.get().selectedItem as String).removeSuffix(" â–¾") + val selectedModelStrippedOfCaret = (comboBoxRef.get().selectedItem as String).removeSuffix(DOWN_ARROW) customPanelRef.get().enter() diffStreamHandler.streamDiffLinesToEditor( textArea.text, prefix, highlighted, suffix, selectedModelStrippedOfCaret @@ -425,7 +427,7 @@ class CustomPanel( } selectedIndex = - continueSettingsService.continueState.lastSelectedInlineEditModel?.let { + if(itemCount == 0) -1 else continueSettingsService.continueState.lastSelectedInlineEditModel?.let { if (modelTitles.isEmpty()) -1 else { val index = modelTitles.indexOf(it) @@ -435,7 +437,7 @@ class CustomPanel( addActionListener { continueSettingsService.continueState.lastSelectedInlineEditModel = - selectedItem as String + (selectedItem as String).removeSuffix(DOWN_ARROW) } } @@ -711,7 +713,7 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { override fun getSelectedItem(): Any? { val item = originalModel.selectedItem - return "$item â–¾" + return "$item$DOWN_ARROW" } override fun addListDataListener(l: ListDataListener?) { From bfb56dd5dd940aee16f6a34d7eab0710673de5ca Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 11:20:19 -0800 Subject: [PATCH 64/86] comment out scroll for now --- gui/src/pages/gui/Chat.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 78bbcd262..7b9fda085 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -159,11 +159,11 @@ export function Chat() { if (active) snapToBottom(); }, [active, snapToBottom]); - useEffect(() => { - setTimeout(() => { - smoothScrollToBottom(); - }, 400); - }, [smoothScrollToBottom, state.sessionId]); + // useEffect(() => { + // setTimeout(() => { + // smoothScrollToBottom(); + // }, 400); + // }, [smoothScrollToBottom, state.sessionId]); useEffect(() => { // Cmd + Backspace to delete current step From 698db54ee0cf5cdb771a7f156d1045bf8ac019cf Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 14 Nov 2024 16:26:24 -0800 Subject: [PATCH 65/86] improv: handle generics in class definitons --- .../root-path-context/test/files/classes.ts | 6 ++ .../test/testCases/typescript.ts | 56 +++++++++++++++++++ .../typescript/class_declaration.scm | 38 +++++++++++-- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/files/classes.ts b/core/autocomplete/context/root-path-context/test/files/classes.ts index 2f6b76cda..8bb829986 100644 --- a/core/autocomplete/context/root-path-context/test/files/classes.ts +++ b/core/autocomplete/context/root-path-context/test/files/classes.ts @@ -1,3 +1,9 @@ // @ts-nocheck +class Group extends BaseClass {} + +class Group implements FirstInterface {} + class Group extends BaseClass implements FirstInterface, SecondInterface {} + +class Group extends BaseClass implements FirstInterface {} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index 9c490ae23..f051668fc 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -216,8 +216,64 @@ const CLASS_METHODS = [ }, ]; +const CLASS_DEFINITIONS = [ + { + nodeType: "class_declaration with base class", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 2, character: 31 }, + definitionPositions: [ + { row: 2, column: 29 }, // BaseClass + ], + }, + { + nodeType: "class_declaration with interface", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 4, character: 39 }, + definitionPositions: [ + { row: 4, column: 37 }, // FirstInterface + ], + }, + { + nodeType: "class_declaration with base class and multiple interfaces", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 6, character: 74 }, + definitionPositions: [ + { row: 6, column: 29 }, // BaseClass + { row: 6, column: 55 }, // FirstInterface + { row: 6, column: 72 }, // SecondInterface + ], + }, + { + nodeType: "class_declaration with base class and multiple interfaces", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 6, character: 74 }, + definitionPositions: [ + { row: 6, column: 29 }, // BaseClass + { row: 6, column: 55 }, // FirstInterface + { row: 6, column: 72 }, // SecondInterface + ], + }, + { + nodeType: "class_declaration with generic base class and generic interface", + fileName: "classes.ts", + language: "TypeScript", + cursorPosition: { line: 8, character: 69 }, + definitionPositions: [ + { row: 8, column: 29 }, // BaseClass + { row: 8, column: 61 }, // FirstInterface + { row: 8, column: 34 }, // User + { row: 8, column: 66 }, // User + ], + }, +]; + export const TYPESCRIPT_TEST_CASES = [ ...FUNCTIONS, ...ARROW_FUNCTIONS, ...CLASS_METHODS, + ...CLASS_DEFINITIONS, ]; diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm index bf38152b7..d164b05a8 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/class_declaration.scm @@ -1,13 +1,21 @@ -( - (class_declaration - (class_heritage - (extends_clause - (identifier) @base-class - ) +; Match a class declaration that extends a base class +; Returns: +; @base-class: The identifier of the base class being extended +; @generic_argument: The type identifier of the generic argument, if present +(class_declaration + (class_heritage + (extends_clause + (identifier) @base-class + (type_arguments + (type_identifier) @generic_argument + )? ) ) ) +; Match a class declaration that implements an interface +; Returns: +; @interface: The type identifier of the interface being implemented ( (class_declaration (class_heritage @@ -16,4 +24,22 @@ ) ) ) +) + +; Match a class declaration that implements a generic interface +; Returns: +; @interface: The type identifier of the generic interface being implemented +; @generic_argument: The type identifier of the generic argument +( + class_declaration + (class_heritage + (implements_clause + (generic_type + (type_identifier) @interface + (type_arguments + (type_identifier) @generic_argument + ) + ) + ) + ) ) \ No newline at end of file From 77d0387e4a8cbc59ef9960234fc3a238966cf5db Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 11:45:29 -0800 Subject: [PATCH 66/86] request -> load etc. --- .../OnboardingCard/components/QuickStartSubmitButton.tsx | 2 +- .../components/OnboardingCard/tabs/OnboardingLocalTab.tsx | 6 +++--- gui/src/components/ProfileSwitcher.tsx | 2 +- gui/src/components/mainInput/MentionList.tsx | 2 +- gui/src/components/mainInput/TutorialCard.tsx | 2 +- gui/src/components/mainInput/getSuggestion.ts | 6 +++--- gui/src/editorInset/EditorInset.tsx | 2 +- gui/src/hooks/useAuth.tsx | 2 +- gui/src/hooks/useCopy.tsx | 2 +- gui/src/hooks/useHistory.tsx | 6 +++--- gui/src/hooks/useIsOSREnabled.ts | 2 +- gui/src/hooks/useSetup.ts | 2 +- gui/src/hooks/useSubmenuContextProviders.tsx | 4 ++-- gui/src/pages/edit/EditInputHeader.tsx | 4 ++-- gui/src/pages/edit/index.tsx | 4 ++-- 15 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gui/src/components/OnboardingCard/components/QuickStartSubmitButton.tsx b/gui/src/components/OnboardingCard/components/QuickStartSubmitButton.tsx index e798bf18a..2113be710 100644 --- a/gui/src/components/OnboardingCard/components/QuickStartSubmitButton.tsx +++ b/gui/src/components/OnboardingCard/components/QuickStartSubmitButton.tsx @@ -41,7 +41,7 @@ function QuickstartSubmitButton() { force: true, }); - if (result.status === "success" && typeof result.content === "string") { + if (result.status === "success") { onComplete(); } else { ideMessenger.post("showToast", [ diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx index 2e4175083..d16587427 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx +++ b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx @@ -57,11 +57,11 @@ function OnboardingLocalTab() { useEffect(() => { const fetchDownloadedModels = async () => { try { - const result = (await ideMessenger.request("llm/listModels", { + const result = await ideMessenger.request("llm/listModels", { title: ONBOARDING_LOCAL_MODEL_TITLE, - })) as any; + }) - if (result.status === "success" && Array.isArray(result.content)) { + if (result.status === "success") { setDownloadedOllamaModels(result.content); setIsOllamaConnected(true); } else { diff --git a/gui/src/components/ProfileSwitcher.tsx b/gui/src/components/ProfileSwitcher.tsx index 4fe8bd72d..601de6782 100644 --- a/gui/src/components/ProfileSwitcher.tsx +++ b/gui/src/components/ProfileSwitcher.tsx @@ -193,7 +193,7 @@ function ProfileSwitcher() { { - ideMessenger.request("didChangeSelectedProfile", { id }); + ideMessenger.post("didChangeSelectedProfile", { id }); }} >
diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 1faee50d4..49e3196de 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -215,7 +215,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { title: "New .prompt file", type: "action", action: () => { - ideMessenger.request("config/newPromptFile", undefined); + ideMessenger.post("config/newPromptFile", undefined); const { tr } = props.editor.view.state; const text = tr.doc.textBetween(0, tr.selection.from); const start = text.lastIndexOf("@"); diff --git a/gui/src/components/mainInput/TutorialCard.tsx b/gui/src/components/mainInput/TutorialCard.tsx index 3a424e257..4e07ead6d 100644 --- a/gui/src/components/mainInput/TutorialCard.tsx +++ b/gui/src/components/mainInput/TutorialCard.tsx @@ -57,7 +57,7 @@ export function TutorialCard({ onClose }: TutorialCardProps) { - ideMessenger.request( + ideMessenger.post( "vscode/openMoveRightMarkdown", undefined, ) diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index 7711562ae..b52328148 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -89,7 +89,7 @@ function getSubActionsForSubmenuItem( label: "Open in new tab", icon: "trash", action: () => { - ideMessenger.request("context/removeDocs", { startUrl: item.id }); + ideMessenger.post("context/removeDocs", { startUrl: item.id }); }, }, ]; @@ -166,7 +166,7 @@ export function getContextProviderDropdownOptions( title: "Add more context providers", type: "action", action: () => { - ideMessenger.request( + ideMessenger.post( "openUrl", "https://docs.continue.dev/customization/context-providers#built-in-context-providers", ); @@ -196,7 +196,7 @@ export function getSlashCommandDropdownOptions( // id: "createPromptFile", // label: "Create Prompt File", // action: () => { - // ideMessenger.request("config/newPromptFile", undefined); + // ideMessenger.post("config/newPromptFile", undefined); // }, // name: "Create Prompt File", // }, diff --git a/gui/src/editorInset/EditorInset.tsx b/gui/src/editorInset/EditorInset.tsx index 4b7b55ab8..7e8e5fde1 100644 --- a/gui/src/editorInset/EditorInset.tsx +++ b/gui/src/editorInset/EditorInset.tsx @@ -35,7 +35,7 @@ function EditorInset() { if (!elementRef.current) return; console.log("Height: ", elementRef.current.clientHeight); - ideMessenger.request("jetbrains/editorInsetHeight", { + ideMessenger.post("jetbrains/editorInsetHeight", { height: elementRef.current.clientHeight, }); }); diff --git a/gui/src/hooks/useAuth.tsx b/gui/src/hooks/useAuth.tsx index 49961df8b..994c8c1e7 100644 --- a/gui/src/hooks/useAuth.tsx +++ b/gui/src/hooks/useAuth.tsx @@ -68,7 +68,7 @@ export function useAuth(): { confirmText="Yes, log out" text={"Are you sure you want to log out of Continue?"} onConfirm={() => { - ideMessenger.request("logoutOfControlPlane", undefined); + ideMessenger.post("logoutOfControlPlane", undefined); }} />, ), diff --git a/gui/src/hooks/useCopy.tsx b/gui/src/hooks/useCopy.tsx index e8d880828..4daa0b933 100644 --- a/gui/src/hooks/useCopy.tsx +++ b/gui/src/hooks/useCopy.tsx @@ -9,7 +9,7 @@ export default function useCopy(text: string | (() => string)) { const copyText = useCallback(() => { const textVal = typeof text === "string" ? text : text(); if (isJetBrains()) { - ideMessenger.request("copyText", { text: textVal }); + ideMessenger.post("copyText", { text: textVal }); } else { navigator.clipboard.writeText(textVal); } diff --git a/gui/src/hooks/useHistory.tsx b/gui/src/hooks/useHistory.tsx index 1d8963b5e..911a2a014 100644 --- a/gui/src/hooks/useHistory.tsx +++ b/gui/src/hooks/useHistory.tsx @@ -121,9 +121,9 @@ function useHistory(dispatch: Dispatch) { if (result.status === "error") { throw new Error(result.error); } - const json = result.content; - dispatch(newSession(json)); - return json; + const persistedSessionInfo = result.content; + dispatch(newSession(persistedSessionInfo)); + return persistedSessionInfo; } async function loadLastSession(): Promise { diff --git a/gui/src/hooks/useIsOSREnabled.ts b/gui/src/hooks/useIsOSREnabled.ts index f1e71770a..10ad04756 100644 --- a/gui/src/hooks/useIsOSREnabled.ts +++ b/gui/src/hooks/useIsOSREnabled.ts @@ -13,7 +13,7 @@ export default function useIsOSREnabled() { useEffect(() => { if (isJetBrains()) { - ideMessenger.request("jetbrains/isOSREnabled", undefined); + ideMessenger.post("jetbrains/isOSREnabled", undefined); } }, []); diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 2fed805da..67b98192f 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -112,7 +112,7 @@ function useSetup(dispatch: Dispatch) { }); const debouncedIndexDocs = debounce(() => { - ideMessenger.request("context/indexDocs", { reIndex: false }); + ideMessenger.post("context/indexDocs", { reIndex: false }); }, 1000); useWebviewListener("configUpdate", async () => { diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx index fc0b0c71a..29abfc1c9 100644 --- a/gui/src/hooks/useSubmenuContextProviders.tsx +++ b/gui/src/hooks/useSubmenuContextProviders.tsx @@ -233,12 +233,12 @@ function useSubmenuContextProviders() { storeFields: ["id", "title", "description"], }); - const result = (await ideMessenger.request( + const result = await ideMessenger.request( "context/loadSubmenuItems", { title: description.title, }, - )) as WebviewMessengerResult<"context/loadSubmenuItems">; + ) if (result.status === "error") { console.error( diff --git a/gui/src/pages/edit/EditInputHeader.tsx b/gui/src/pages/edit/EditInputHeader.tsx index b7b66de8c..8248bbfa6 100644 --- a/gui/src/pages/edit/EditInputHeader.tsx +++ b/gui/src/pages/edit/EditInputHeader.tsx @@ -82,7 +82,7 @@ export function EditInputHeader(editInputHeaderParams: EditInputHeaderParams) { className="h-4 w-4 cursor-pointer px-2" color="red" onClick={() => { - ideMessenger.request("edit/acceptReject", { + ideMessenger.post("edit/acceptReject", { accept: false, onlyFirst: false, filepath: editModeState.highlightedCode.filepath, @@ -95,7 +95,7 @@ export function EditInputHeader(editInputHeaderParams: EditInputHeaderParams) { { - ideMessenger.request("edit/acceptReject", { + ideMessenger.post("edit/acceptReject", { accept: true, onlyFirst: false, filepath: editModeState.highlightedCode.filepath, diff --git a/gui/src/pages/edit/index.tsx b/gui/src/pages/edit/index.tsx index 5b1b71e66..3b708e980 100644 --- a/gui/src/pages/edit/index.tsx +++ b/gui/src/pages/edit/index.tsx @@ -98,7 +98,7 @@ function Edit() { // Reusing the applyState logic which was just the fastest way to get this working useEffect(() => { if (editModeState.editStatus === "done") { - ideMessenger.request("edit/escape", undefined); + ideMessenger.post("edit/escape", undefined); navigate("/"); } }, [editModeState.editStatus]); @@ -180,7 +180,7 @@ function Edit() { ...contextItems.map((item) => item.content), stripImages(userInstructions), ].join("\n\n"); - ideMessenger.request("edit/sendPrompt", { + ideMessenger.post("edit/sendPrompt", { prompt, range: editModeState.highlightedCode, }); From d34da76704b2eb2abac40220eb58154be2b467fc Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 11:46:04 -0800 Subject: [PATCH 67/86] chore: cleanup --- .../context/root-path-context/RootPathContextService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 7a9d26548..85ff5e640 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -157,7 +157,6 @@ export class RootPathContextService { parentKey = key; } - debugger; return snippets; } } From 3595293647b5d7780cfaa8c574400bc71956841f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 11:59:48 -0800 Subject: [PATCH 68/86] test: multiple arguments --- .../test/files/arrowFunctions.ts | 4 +++ .../test/files/classMethods.ts | 4 +++ .../root-path-context/test/files/functions.ts | 4 +++ .../test/testCases/typescript.ts | 30 +++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts index 42ef247b0..aadffe065 100644 --- a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts +++ b/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts @@ -23,3 +23,7 @@ const logPersonWithAddres = (person: Person
): Person
=> { const logPersonOrAddress = (person: Person | Address): Person | Address => { // TODO }; + +const logPersonAndAddress = (person: Person, address: Address) => { + // TODO +}; diff --git a/core/autocomplete/context/root-path-context/test/files/classMethods.ts b/core/autocomplete/context/root-path-context/test/files/classMethods.ts index 36224029b..08f7506a7 100644 --- a/core/autocomplete/context/root-path-context/test/files/classMethods.ts +++ b/core/autocomplete/context/root-path-context/test/files/classMethods.ts @@ -28,4 +28,8 @@ class Group { logPersonOrAddress(person: Person | Address): Person | Address { // TODO } + + logPersonAndAddress(person: Person, address: Address) { + // TODO + } } diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/functions.ts index 4189f4e20..bb9d39c85 100644 --- a/core/autocomplete/context/root-path-context/test/files/functions.ts +++ b/core/autocomplete/context/root-path-context/test/files/functions.ts @@ -27,3 +27,7 @@ function logPersonWithAddress(person: Person
): Person
{ function logPersonOrAddress(person: Person | Address): Person | Address { // TODO } + +function logPersonAndAddress(person: Person, address: Address) { + // TODO +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index f051668fc..dcadb528a 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -73,6 +73,16 @@ const FUNCTIONS = [ { row: 26, column: 71 }, // Address ], }, + { + nodeType: "function_declaration with two arguments", + fileName: "functions.ts", + language: "TypeScript", + cursorPosition: { line: 31, character: 9 }, + definitionPositions: [ + { row: 30, column: 43 }, // Person + { row: 30, column: 61 }, // Address + ], + }, ]; const ARROW_FUNCTIONS = [ @@ -138,6 +148,16 @@ const ARROW_FUNCTIONS = [ { row: 22, column: 71 }, // Address ], }, + { + nodeType: "arrow_function with two arguments", + fileName: "arrowFunctions.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 11 }, + definitionPositions: [ + { row: 26, column: 43 }, // Person + { row: 26, column: 61 }, // Address + ], + }, ]; const CLASS_METHODS = [ @@ -214,6 +234,16 @@ const CLASS_METHODS = [ { row: 27, column: 64 }, // Address ], }, + { + nodeType: "method_declaration with two arguments", + fileName: "classMethods.ts", + language: "TypeScript", + cursorPosition: { line: 32, character: 11 }, + definitionPositions: [ + { row: 31, column: 36 }, // Person + { row: 31, column: 54 }, // Address + ], + }, ]; const CLASS_DEFINITIONS = [ From 5bb95f5a56fe507dce74de15982579e3c1344e5d Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 12:07:08 -0800 Subject: [PATCH 69/86] ide -> webview --- .../src/autocomplete/completionProvider.ts | 4 +++- extensions/vscode/src/commands.ts | 16 ++++++++-------- extensions/vscode/src/diff/vertical/manager.ts | 4 ++-- .../vscode/src/extension/VsCodeExtension.ts | 8 ++++---- .../vscode/src/extension/VsCodeMessenger.ts | 12 ++++++------ .../vscode/src/quickEdit/QuickEditQuickPick.ts | 2 +- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index b6b04297f..0df8e58b1 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -41,7 +41,9 @@ export class ContinueCompletionProvider showFreeTrialLoginMessage( e.message, this.configHandler.reloadConfig.bind(this.configHandler), - () => this.webviewProtocol.request("openOnboardingCard", undefined), + () => { + void this.webviewProtocol.request("openOnboardingCard", undefined) + }, ); return; } diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 4733dee6f..42c10c3c9 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -258,7 +258,7 @@ const commandsMap: ( const modelTitle = getModelByRole(config, "inlineEdit")?.title ?? defaultModelTitle; - sidebar.webviewProtocol.request("incrementFtc", undefined); + void sidebar.webviewProtocol.request("incrementFtc", undefined); await verticalDiffManager.streamEdit( config.experimental?.contextMenuPrompts?.[promptName] ?? fallbackPrompt, @@ -287,7 +287,7 @@ const commandsMap: ( verticalDiffManager.clearForFilepath(fullPath, true); await diffManager.acceptDiff(fullPath); - await sidebar.webviewProtocol.request("setEditStatus", { + void sidebar.webviewProtocol.request("setEditStatus", { status: "done", }); }, @@ -306,7 +306,7 @@ const commandsMap: ( verticalDiffManager.clearForFilepath(fullPath, false); await diffManager.rejectDiff(fullPath); - await sidebar.webviewProtocol.request("setEditStatus", { + void sidebar.webviewProtocol.request("setEditStatus", { status: "done", }); }, @@ -387,12 +387,12 @@ const commandsMap: ( if (historyLength === 0) { hideGUI(); } else { - sidebar.webviewProtocol?.request("focusContinueInput", undefined); + void sidebar.webviewProtocol?.request("focusContinueInput", undefined); } } else { focusGUI(); sidebar.webviewProtocol?.request("focusContinueInput", undefined); - await addHighlightedCodeToContext(sidebar.webviewProtocol); + void addHighlightedCodeToContext(sidebar.webviewProtocol); } }, "continue.focusContinueInputWithoutClear": async () => { @@ -419,7 +419,7 @@ const commandsMap: ( undefined, ); - await addHighlightedCodeToContext(sidebar.webviewProtocol); + void addHighlightedCodeToContext(sidebar.webviewProtocol); } }, "continue.edit": async () => { @@ -596,10 +596,10 @@ const commandsMap: ( prompt: "Enter the Session ID", }); } - sidebar.webviewProtocol?.request("focusContinueSessionId", { sessionId }); + void sidebar.webviewProtocol?.request("focusContinueSessionId", { sessionId }); }, "continue.applyCodeFromChat": () => { - sidebar.webviewProtocol.request("applyCodeFromChat", undefined); + void sidebar.webviewProtocol.request("applyCodeFromChat", undefined); }, "continue.toggleFullScreen": () => { focusGUI(); diff --git a/extensions/vscode/src/diff/vertical/manager.ts b/extensions/vscode/src/diff/vertical/manager.ts index 5c6ca0884..4595ca013 100644 --- a/extensions/vscode/src/diff/vertical/manager.ts +++ b/extensions/vscode/src/diff/vertical/manager.ts @@ -218,7 +218,7 @@ export class VerticalDiffManager { { instant, onStatusUpdate: (status, numDiffs) => - this.webviewProtocol.request("updateApplyState", { + void this.webviewProtocol.request("updateApplyState", { streamId, status, numDiffs, @@ -338,7 +338,7 @@ export class VerticalDiffManager { input, onStatusUpdate: (status, numDiffs) => streamId && - this.webviewProtocol.request("updateApplyState", { + void this.webviewProtocol.request("updateApplyState", { streamId, status, numDiffs, diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 06263e356..480252f17 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -318,14 +318,14 @@ export class VsCodeExtension { } else if (e.provider.id === controlPlaneEnv.AUTH_TYPE) { const sessionInfo = await getControlPlaneSessionInfo(true); this.webviewProtocolPromise.then(async (webviewProtocol) => { - webviewProtocol.request("didChangeControlPlaneSessionInfo", { + void webviewProtocol.request("didChangeControlPlaneSessionInfo", { sessionInfo, }); // To make sure continue-proxy models and anything else requiring it get updated access token this.configHandler.reloadConfig(); }); - this.core.invoke("didChangeControlPlaneSessionInfo", { sessionInfo }); + void this.core.invoke("didChangeControlPlaneSessionInfo", { sessionInfo }); } }); @@ -374,14 +374,14 @@ export class VsCodeExtension { ); this.ide.onDidChangeActiveTextEditor((filepath) => { - this.core.invoke("didChangeActiveTextEditor", { filepath }); + void this.core.invoke("didChangeActiveTextEditor", { filepath }); }); vscode.workspace.onDidChangeConfiguration(async (event) => { if (event.affectsConfiguration(EXTENSION_NAME)) { const settings = this.ide.getIdeSettingsSync(); const webviewProtocol = await this.webviewProtocolPromise; - webviewProtocol.request("didChangeIdeSettings", { + void webviewProtocol.request("didChangeIdeSettings", { settings, }); } diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index b4e9749da..e71bd2bfd 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -48,7 +48,7 @@ export class VsCodeMessenger { message: Message, ) => Promise | FromWebviewProtocol[T][1], ): void { - this.webviewProtocol.on(messageType, handler); + void this.webviewProtocol.on(messageType, handler); } onCore( @@ -153,11 +153,11 @@ export class VsCodeMessenger { }); webviewProtocol.on("acceptDiff", async ({ data: { filepath } }) => { - await vscode.commands.executeCommand("continue.acceptDiff", filepath); + void vscode.commands.executeCommand("continue.acceptDiff", filepath); }); webviewProtocol.on("rejectDiff", async ({ data: { filepath } }) => { - await vscode.commands.executeCommand("continue.rejectDiff", filepath); + void vscode.commands.executeCommand("continue.rejectDiff", filepath); }); this.onWebview("applyToFile", async ({ data }) => { @@ -178,7 +178,7 @@ export class VsCodeMessenger { await this.ide.writeFile(fullPath, data.text); await this.ide.openFile(fullPath); - await webviewProtocol.request("updateApplyState", { + void webviewProtocol.request("updateApplyState", { streamId: data.streamId, status: "done", numDiffs: 0, @@ -203,7 +203,7 @@ export class VsCodeMessenger { editor.edit((builder) => builder.insert(new vscode.Position(0, 0), data.text), ); - await webviewProtocol.request("updateApplyState", { + void webviewProtocol.request("updateApplyState", { streamId: data.streamId, status: "done", numDiffs: 0, @@ -328,7 +328,7 @@ export class VsCodeMessenger { ), ); - this.webviewProtocol.request("setEditStatus", { + void this.webviewProtocol.request("setEditStatus", { status: "accepting", fileAfterEdit, }); diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index 355c02de6..4b59dcbda 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -329,7 +329,7 @@ export class QuickEdit { prompt = this.contextProviderStr + prompt; } - this.webviewProtocol.request("incrementFtc", undefined); + void this.webviewProtocol.request("incrementFtc", undefined); await this.verticalDiffManager.streamEdit( prompt, From 260c13bd66657b9a058a02de2fc0ed05eb085e16 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 12:22:33 -0800 Subject: [PATCH 70/86] core -> ide --- core/context/providers/DocsContextProvider.ts | 2 +- core/indexing/docs/DocsCrawler.ts | 2 +- core/indexing/docs/DocsService.ts | 6 +++--- core/indexing/docs/crawlers/ChromiumCrawler.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index a290589e4..ba2bf29b6 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -92,7 +92,7 @@ class DocsContextProvider extends BaseContextProvider { await docsService.isJetBrainsAndPreIndexedDocsProvider(); if (isJetBrainsAndPreIndexedDocsProvider) { - await extras.ide.showToast( + void extras.ide.showToast( "error", `${DocsService.preIndexedDocsEmbeddingsProvider.id} is configured as ` + "the embeddings provider, but it cannot be used with JetBrains. " + diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index cb9146ab5..599c4202a 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -79,7 +79,7 @@ class DocsCrawler { ); if (didInstall) { - await this.ide.showToast( + void this.ide.showToast( "info", `Successfully installed Chromium! Retrying crawl of: ${startUrl.toString()}`, ); diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 46fedf9d0..470dc6289 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -157,7 +157,7 @@ export default class DocsService { params: {}, }); - await this.ide.showToast( + void this.ide.showToast( "info", "Successfuly added docs context provider", ); @@ -183,7 +183,7 @@ export default class DocsService { while (!(await generator.next()).done) {} } - await this.ide.showToast("info", "Docs indexing completed"); + void this.ide.showToast("info", "Docs indexing completed"); } async list() { @@ -741,7 +741,7 @@ export default class DocsService { if (isJetBrainsAndPreIndexedDocsProvider) { // A bit noisy for teams users whom have no choice if their admin is the one who didn't setup an embeddingsProvider - // this.ide.showToast( + // void this.ide.showToast( // "error", // "The 'transformers.js' embeddings provider currently cannot be used to index " + // "documentation in JetBrains. To enable documentation indexing, you can use " + diff --git a/core/indexing/docs/crawlers/ChromiumCrawler.ts b/core/indexing/docs/crawlers/ChromiumCrawler.ts index ee49270a8..e2feb4c59 100644 --- a/core/indexing/docs/crawlers/ChromiumCrawler.ts +++ b/core/indexing/docs/crawlers/ChromiumCrawler.ts @@ -242,7 +242,7 @@ export class ChromiumInstaller { ChromiumCrawler.setUseChromiumForDocsCrawling(false); - await this.ide.showToast("error", "Failed to install Chromium"); + void this.ide.showToast("error", "Failed to install Chromium"); return false; } From 651f942e92e7f69acaa8c7385a93181e9cc7c594 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 15 Nov 2024 12:22:38 -0800 Subject: [PATCH 71/86] throttle JSDOM parsing --- core/indexing/docs/DocsService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 46fedf9d0..d97b92974 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -254,6 +254,8 @@ export default class DocsService { if (processedPages === maxKnownPages) { maxKnownPages *= 2; } + + await new Promise((resolve) => setTimeout(resolve, 50)); } void Telemetry.capture("docs_pages_crawled", { From f351cf3c3ef9ccb1a6c0ccb93a058e00d4f72367 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 12:28:04 -0800 Subject: [PATCH 72/86] core.messenger audit --- core/core.ts | 2 +- core/util/tts.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/core.ts b/core/core.ts index 6df1482ef..ace3c7913 100644 --- a/core/core.ts +++ b/core/core.ts @@ -149,7 +149,7 @@ export class Core { void this.ide.getWorkspaceDirs().then(async (dirs) => { // Respect pauseCodebaseIndexOnStart user settings if (ideSettings.pauseCodebaseIndexOnStart) { - await this.messenger.request("indexProgress", { + void this.messenger.request("indexProgress", { progress: 1, desc: "Initial Indexing Skipped", status: "paused", diff --git a/core/util/tts.ts b/core/util/tts.ts index 9bde6e57c..efae302c2 100644 --- a/core/util/tts.ts +++ b/core/util/tts.ts @@ -82,10 +82,10 @@ export class TTS { return; } - TTS.messenger.request("setTTSActive", true); + void TTS.messenger.request("setTTSActive", true); TTS.handle?.once("exit", () => { - TTS.messenger.request("setTTSActive", false); + void TTS.messenger.request("setTTSActive", false); }); } From 3bece78be4277aa55bb7b4576594d70159442be1 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 13:12:21 -0800 Subject: [PATCH 73/86] test: generators --- .../test/files/generators.ts | 33 +++++++ .../test/testCases/typescript.ts | 88 +++++++++++++++++++ .../generator_function_declaration.scm | 77 ++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 core/autocomplete/context/root-path-context/test/files/generators.ts create mode 100644 extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm diff --git a/core/autocomplete/context/root-path-context/test/files/generators.ts b/core/autocomplete/context/root-path-context/test/files/generators.ts new file mode 100644 index 000000000..79811b478 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/generators.ts @@ -0,0 +1,33 @@ +// @ts-nocheck + +function* getAddress(person: Person): Address { + // TODO +} + +function* getFirstAddress(people: Person[]): Address { + // TODO +} + +function* logPerson(person: Person) { + // TODO +} + +function* getHardcodedAddress(): Address { + // TODO +} + +function* getAddresses(people: Person[]): Address[] { + // TODO +} + +function* logPersonWithAddress(person: Person
): Person
{ + // TODO +} + +function* logPersonOrAddress(person: Person | Address): Person | Address { + // TODO +} + +function* logPersonAndAddress(person: Person, address: Address) { + // TODO +} diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index dcadb528a..f945a02a9 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -85,6 +85,93 @@ const FUNCTIONS = [ }, ]; +const GENERATORS = [ + { + nodeType: "function_declaration with a param and a return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 3, character: 9 }, + definitionPositions: [ + { row: 2, column: 35 }, // Person + { row: 2, column: 45 }, // Address + ], + }, + { + nodeType: "function_declaration with array param", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 7, character: 9 }, + definitionPositions: [ + { row: 6, column: 40 }, // Person + { row: 6, column: 52 }, // Address + ], + }, + { + nodeType: "function_declaration without return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 11, character: 9 }, + definitionPositions: [ + { row: 10, column: 34 }, // Person + ], + }, + { + nodeType: "function_declaration without params", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 15, character: 9 }, + definitionPositions: [ + { row: 14, column: 40 }, // Person + ], + }, + { + nodeType: "function_declaration with array params and array return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 19, character: 9 }, + definitionPositions: [ + { row: 18, column: 37 }, // Person + { row: 18, column: 49 }, // Address + ], + }, + { + nodeType: + "function_declaration with generic params and generic return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 23, character: 9 }, + definitionPositions: [ + { row: 22, column: 45 }, // Person + { row: 22, column: 53 }, // Address + { row: 22, column: 63 }, // Person + { row: 22, column: 71 }, // Address + ], + }, + { + nodeType: + "function_declaration with union type params and union return type", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 27, character: 9 }, + definitionPositions: [ + { row: 26, column: 43 }, // Person + { row: 26, column: 53 }, // Address + { row: 26, column: 62 }, // Person + { row: 26, column: 72 }, // Address + ], + }, + { + nodeType: "function_declaration with two arguments", + fileName: "generators.ts", + language: "TypeScript", + cursorPosition: { line: 31, character: 9 }, + definitionPositions: [ + { row: 30, column: 44 }, // Person + { row: 30, column: 62 }, // Address + ], + }, +]; + const ARROW_FUNCTIONS = [ { nodeType: "arrow_function with a param and a return type", @@ -303,6 +390,7 @@ const CLASS_DEFINITIONS = [ export const TYPESCRIPT_TEST_CASES = [ ...FUNCTIONS, + ...GENERATORS, ...ARROW_FUNCTIONS, ...CLASS_METHODS, ...CLASS_DEFINITIONS, diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm new file mode 100644 index 000000000..b6417f45c --- /dev/null +++ b/extensions/vscode/tree-sitter/root-path-context-queries/typescript/generator_function_declaration.scm @@ -0,0 +1,77 @@ +; Pattern for return type with direct type_identifier +( + (generator_function_declaration + (type_annotation + (type_identifier) @return_type + ) + ) +) + +; Pattern for return type with one level of nesting +( + (generator_function_declaration + (type_annotation + (_ + (type_identifier) @return_type + ) + ) + ) +) + +; Pattern for return type with two levels of nesting +( + (generator_function_declaration + (type_annotation + (_ + (_ + (type_identifier) @return_type + ) + ) + ) + ) +) + +; Pattern for parameters with direct type_identifier +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (type_identifier) @param_type + ) + ) + ) + ) +) + +; Pattern for parameters with one level of nesting +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) +) + +; Pattern for parameters with two levels of nesting +( + (generator_function_declaration + (formal_parameters + (_ + (type_annotation + (_ + (_ + (type_identifier) @param_type + ) + ) + ) + ) + ) + ) +) \ No newline at end of file From 051aeb7623fd0f4b4b2dfb1a5fb945371ec42b70 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 13:14:40 -0800 Subject: [PATCH 74/86] improv: readability --- .../test/RootPathContextService.test.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index fe81a0edd..78aed69a7 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -61,15 +61,17 @@ const TEST_CASES = [ ]; describe("RootPathContextService", () => { - test.each(TEST_CASES)( - "Should look for correct type definitions when editing inside a $nodeType in $language", - async ({ fileName, cursorPosition, definitionPositions }) => { - await testRootPathContext( - "files", - fileName, - cursorPosition, - definitionPositions, - ); - }, - ); + describe("should look for correct type definitions", () => { + test.each(TEST_CASES)( + "$language: $nodeType", + async ({ fileName, cursorPosition, definitionPositions }) => { + await testRootPathContext( + "files", + fileName, + cursorPosition, + definitionPositions, + ); + }, + ); + }); }); From 3c9071a09b114a019a593a7f241975f419cc4e43 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:10:19 -0800 Subject: [PATCH 75/86] feat: ignore node_modules in js and ts code definitions --- .../RootPathContextService.ts | 42 +++- .../root-path-context/test/testUtils.ts | 1 + core/util/treeSitter.ts | 183 +++++++++++------- 3 files changed, 142 insertions(+), 84 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 85ff5e640..2de5b0ae7 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -4,7 +4,12 @@ import { LRUCache } from "lru-cache"; import Parser from "web-tree-sitter"; import { IDE } from "../../.."; -import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; +import { + getFullLanguageName, + getQueryForFile, + IGNORE_PATH_PATTERNS, + LanguageName, +} from "../../../util/treeSitter"; import { AstPath } from "../../util/ast"; import { ImportDefinitionsService } from "../ImportDefinitionsService"; import { AutocompleteSnippet } from "../ranking"; @@ -40,6 +45,7 @@ export class RootPathContextService { private static TYPES_TO_USE = new Set([ "arrow_function", + "generator_function_declaration", "program", "function_declaration", "function_definition", @@ -68,6 +74,7 @@ export class RootPathContextService { node: Parser.SyntaxNode, ): Promise { const snippets: AutocompleteSnippet[] = []; + const language = getFullLanguageName(filepath); let query: Parser.Query | undefined; switch (node.type) { @@ -75,10 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - // const type = node.type; - // debugger; - // console.log(getSyntaxTreeString(node)); - const language = getFullLanguageName(filepath); + const type = node.type; + console.log(getSyntaxTreeString(node)); + debugger; query = await getQueryForFile( filepath, @@ -95,8 +101,13 @@ export class RootPathContextService { const queries = query.matches(node).map(async (match) => { for (const item of match.captures) { try { + const text = node.text; const endPosition = item.node.endPosition; - const newSnippets = await this.getSnippets(filepath, endPosition); + const newSnippets = await this.getSnippets( + filepath, + endPosition, + language, + ); snippets.push(...newSnippets); } catch (e) { debugger; @@ -107,12 +118,14 @@ export class RootPathContextService { await Promise.all(queries); + debugger; return snippets; } private async getSnippets( filepath: string, endPosition: Parser.Point, + language: LanguageName, ): Promise { const definitions = await this.ide.gotoDefinition({ filepath, @@ -122,10 +135,18 @@ export class RootPathContextService { }, }); const newSnippets = await Promise.all( - definitions.map(async (def) => ({ - ...def, - contents: await this.ide.readRangeInFile(def.filepath, def.range), - })), + definitions + .filter((definition) => { + const isIgnoredPath = IGNORE_PATH_PATTERNS[language]?.some( + (pattern) => pattern.test(definition.filepath), + ); + + return !isIgnoredPath; + }) + .map(async (def) => ({ + ...def, + contents: await this.ide.readRangeInFile(def.filepath, def.range), + })), ); return newSnippets; @@ -157,6 +178,7 @@ export class RootPathContextService { parentKey = key; } + debugger; return snippets; } } diff --git a/core/autocomplete/context/root-path-context/test/testUtils.ts b/core/autocomplete/context/root-path-context/test/testUtils.ts index 9526cacdb..7a5c22aba 100644 --- a/core/autocomplete/context/root-path-context/test/testUtils.ts +++ b/core/autocomplete/context/root-path-context/test/testUtils.ts @@ -84,6 +84,7 @@ export async function testRootPathContext( index + 1, expect.any(String), // filepath argument position, + expect.any(String), // language argument ); }); } diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index 4fe0d1665..9118b80ee 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -3,81 +3,116 @@ import * as path from "node:path"; import Parser, { Language } from "web-tree-sitter"; -export const supportedLanguages: { [key: string]: string } = { - cpp: "cpp", - hpp: "cpp", - cc: "cpp", - cxx: "cpp", - hxx: "cpp", - cp: "cpp", - hh: "cpp", - inc: "cpp", - // Depended on this PR: https://github.com/tree-sitter/tree-sitter-cpp/pull/173 - // ccm: "cpp", - // c++m: "cpp", - // cppm: "cpp", - // cxxm: "cpp", - cs: "c_sharp", - c: "c", - h: "c", - css: "css", - php: "php", - phtml: "php", - php3: "php", - php4: "php", - php5: "php", - php7: "php", - phps: "php", - "php-s": "php", - bash: "bash", - sh: "bash", - json: "json", - ts: "typescript", - mts: "typescript", - cts: "typescript", - tsx: "tsx", - // vue: "vue", // tree-sitter-vue parser is broken - // The .wasm file being used is faulty, and yaml is split line-by-line anyway for the most part - // yaml: "yaml", - // yml: "yaml", - elm: "elm", - js: "javascript", - jsx: "javascript", - mjs: "javascript", - cjs: "javascript", - py: "python", - ipynb: "python", - pyw: "python", - pyi: "python", - el: "elisp", - emacs: "elisp", - ex: "elixir", - exs: "elixir", - go: "go", - eex: "embedded_template", - heex: "embedded_template", - leex: "embedded_template", - html: "html", - htm: "html", - java: "java", - lua: "lua", - ocaml: "ocaml", - ml: "ocaml", - mli: "ocaml", - ql: "ql", - res: "rescript", - resi: "rescript", - rb: "ruby", - erb: "ruby", - rs: "rust", - rdl: "systemrdl", - toml: "toml", - sol: "solidity", +export enum LanguageName { + CPP = "cpp", + C_SHARP = "c_sharp", + C = "c", + CSS = "css", + PHP = "php", + BASH = "bash", + JSON = "json", + TYPESCRIPT = "typescript", + TSX = "tsx", + ELM = "elm", + JAVASCRIPT = "javascript", + PYTHON = "python", + ELISP = "elisp", + ELIXIR = "elixir", + GO = "go", + EMBEDDED_TEMPLATE = "embedded_template", + HTML = "html", + JAVA = "java", + LUA = "lua", + OCAML = "ocaml", + QL = "ql", + RESCRIPT = "rescript", + RUBY = "ruby", + RUST = "rust", + SYSTEMRDL = "systemrdl", + TOML = "toml", + SOLIDITY = "solidity", +} - // jl: "julia", - // swift: "swift", - // kt: "kotlin", - // scala: "scala", +export const supportedLanguages: { [key: string]: LanguageName } = { + cpp: LanguageName.CPP, + hpp: LanguageName.CPP, + cc: LanguageName.CPP, + cxx: LanguageName.CPP, + hxx: LanguageName.CPP, + cp: LanguageName.CPP, + hh: LanguageName.CPP, + inc: LanguageName.CPP, + // Depended on this PR: https://github.com/tree-sitter/tree-sitter-cpp/pull/173 + // ccm: LanguageName.CPP, + // c++m: LanguageName.CPP, + // cppm: LanguageName.CPP, + // cxxm: LanguageName.CPP, + cs: LanguageName.C_SHARP, + c: LanguageName.C, + h: LanguageName.C, + css: LanguageName.CSS, + php: LanguageName.PHP, + phtml: LanguageName.PHP, + php3: LanguageName.PHP, + php4: LanguageName.PHP, + php5: LanguageName.PHP, + php7: LanguageName.PHP, + phps: LanguageName.PHP, + "php-s": LanguageName.PHP, + bash: LanguageName.BASH, + sh: LanguageName.BASH, + json: LanguageName.JSON, + ts: LanguageName.TYPESCRIPT, + mts: LanguageName.TYPESCRIPT, + cts: LanguageName.TYPESCRIPT, + tsx: LanguageName.TSX, + // vue: LanguageName.VUE, // tree-sitter-vue parser is broken + // The .wasm file being used is faulty, and yaml is split line-by-line anyway for the most part + // yaml: LanguageName.YAML, + // yml: LanguageName.YAML, + elm: LanguageName.ELM, + js: LanguageName.JAVASCRIPT, + jsx: LanguageName.JAVASCRIPT, + mjs: LanguageName.JAVASCRIPT, + cjs: LanguageName.JAVASCRIPT, + py: LanguageName.PYTHON, + ipynb: LanguageName.PYTHON, + pyw: LanguageName.PYTHON, + pyi: LanguageName.PYTHON, + el: LanguageName.ELISP, + emacs: LanguageName.ELISP, + ex: LanguageName.ELIXIR, + exs: LanguageName.ELIXIR, + go: LanguageName.GO, + eex: LanguageName.EMBEDDED_TEMPLATE, + heex: LanguageName.EMBEDDED_TEMPLATE, + leex: LanguageName.EMBEDDED_TEMPLATE, + html: LanguageName.HTML, + htm: LanguageName.HTML, + java: LanguageName.JAVA, + lua: LanguageName.LUA, + ocaml: LanguageName.OCAML, + ml: LanguageName.OCAML, + mli: LanguageName.OCAML, + ql: LanguageName.QL, + res: LanguageName.RESCRIPT, + resi: LanguageName.RESCRIPT, + rb: LanguageName.RUBY, + erb: LanguageName.RUBY, + rs: LanguageName.RUST, + rdl: LanguageName.SYSTEMRDL, + toml: LanguageName.TOML, + sol: LanguageName.SOLIDITY, + + // jl: LanguageName.JULIA, + // swift: LanguageName.SWIFT, + // kt: LanguageName.KOTLIN, + // scala: LanguageName.SCALA, +}; + +export const IGNORE_PATH_PATTERNS: Partial> = { + [LanguageName.TYPESCRIPT]: [/.*node_modules/], + [LanguageName.JAVASCRIPT]: [/.*node_modules/], }; export async function getParserForFile(filepath: string) { From 42c99902390321ceb8111c1fa0e8629cc8909eb0 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:12:01 -0800 Subject: [PATCH 76/86] refactor: clean up --- .../context/root-path-context/RootPathContextService.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 2de5b0ae7..55ba38b31 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -82,9 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - const type = node.type; - console.log(getSyntaxTreeString(node)); - debugger; + // const type = node.type; + // console.log(getSyntaxTreeString(node)); + // debugger; query = await getQueryForFile( filepath, @@ -101,7 +101,6 @@ export class RootPathContextService { const queries = query.matches(node).map(async (match) => { for (const item of match.captures) { try { - const text = node.text; const endPosition = item.node.endPosition; const newSnippets = await this.getSnippets( filepath, @@ -178,7 +177,7 @@ export class RootPathContextService { parentKey = key; } - debugger; + return snippets; } } From 9d0b405f64a4c190e58cc632628cf5c13d0297a8 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 14:12:49 -0800 Subject: [PATCH 77/86] refactor: clean up --- .../context/root-path-context/RootPathContextService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 55ba38b31..0147df151 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -92,7 +92,6 @@ export class RootPathContextService { ); break; } - const type = node.type; if (!query) { return snippets; @@ -117,7 +116,6 @@ export class RootPathContextService { await Promise.all(queries); - debugger; return snippets; } From 85f95696f8aeb9854e11b31ef2fbb757ae6a05b4 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 15 Nov 2024 20:16:50 -0800 Subject: [PATCH 78/86] checkout tag, not main --- .github/workflows/main.yaml | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 31b64bae1..b73cdb3ad 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -213,8 +213,8 @@ jobs: git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - - name: Pull latest changes - run: git pull origin main + - name: Pull latest changes from release + run: git fetch origin ${{ github.ref }} && git checkout ${{ github.ref }} # 1. Download the artifacts - uses: actions/download-artifact@v4 @@ -237,21 +237,3 @@ jobs: run: | cd extensions/vscode npx ovsx publish -p ${{ secrets.VSX_REGISTRY_TOKEN }} --packagePath ../../vsix-artifacts/*.vsix - - # 4. Update the package.json version and push changes - # - name: Update version in package.json - # run: | - # cd extensions/vscode - # npm version patch - - # - name: Commit changes - # run: | - # git config --local user.email "action@github.com" - # git config --local user.name "GitHub Action" - # git commit -am "💚 Update package.json version [skip ci]" - - # - name: Push changes - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # branch: ${{ github.ref }} From df38bcc2f524653e851fe86162bce73fcf7bd887 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 04:18:12 +0000 Subject: [PATCH 79/86] build(deps): bump axios from 1.7.1 to 1.7.7 in /core Bumps [axios](https://github.com/axios/axios) from 1.7.1 to 1.7.7. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.7.1...v1.7.7) --- updated-dependencies: - dependency-name: axios dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- core/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index fd3173f28..e817a7c6f 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -5846,9 +5846,9 @@ "integrity": "sha512-3AungXC4I8kKsS9PuS4JH2nc+0bVY/mjgrephHTIi8fpEeGsTHBUJeosp0Wc1myYMElmD0B3Oc4XL/HVJ4PV2g==" }, "node_modules/axios": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", - "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", From 5f0d56449ba9e9444dee6c821897cf90f166f8c7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 04:18:14 +0000 Subject: [PATCH 80/86] build(deps): bump cross-spawn from 7.0.3 to 7.0.5 in /docs Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.5. - [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md) - [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v7.0.3...v7.0.5) --- updated-dependencies: - dependency-name: cross-spawn dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 756266105..c2485bdf7 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -5229,9 +5229,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz", + "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", From eb87236ffb14886142ad04e01e0e622e32f02e40 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 15 Nov 2024 21:31:12 -0800 Subject: [PATCH 81/86] update prompt file docs --- docs/docs/chat/how-to-customize.md | 1 + .../docs/customize/deep-dives/prompt-files.md | 8 +++--- docs/docs/customize/deep-dives/rules.md | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 docs/docs/customize/deep-dives/rules.md diff --git a/docs/docs/chat/how-to-customize.md b/docs/docs/chat/how-to-customize.md index 943d5e7ac..9df6ec020 100644 --- a/docs/docs/chat/how-to-customize.md +++ b/docs/docs/chat/how-to-customize.md @@ -7,6 +7,7 @@ sidebar_position: 5 There are a number of different ways to customize Chat +- You can add a [`.continuerules`](../customize/deep-dives/rules.md) file to the root of your project to customize the system prompt - You can configure [`@Codebase`](../customize/deep-dives/codebase.md) - You can create your own [custom code RAG](../customize/tutorials/custom-code-rag.md) - You can configure [`@Docs`](../customize/deep-dives/docs.md) diff --git a/docs/docs/customize/deep-dives/prompt-files.md b/docs/docs/customize/deep-dives/prompt-files.md index 91f3557ea..e69902a42 100644 --- a/docs/docs/customize/deep-dives/prompt-files.md +++ b/docs/docs/customize/deep-dives/prompt-files.md @@ -10,11 +10,11 @@ Prompt files provide a convenient way to standardize common patterns and share a To assist you in getting started, [we've curated a small library of `.prompt` files](https://github.com/continuedev/prompt-file-examples). We encourage community contributions to this repository, so please consider opening up a pull request with your own prompts! ::: --> -Below is a quick example of setting up a prompt file to write unit tests using Jest. +Below is a quick example of setting up a prompt file to de -1. Create a folder called `.prompts/` at the top level of your workspace. -2. Add a file called `test.prompt` to this folder. The name of this file will be the name of the slash command you will use to generate your prompt. -3. Write the following contents to `test.prompt` and save. +1. Create a folder called `.continue/prompts` at the top level of your workspace (or you can use the button in the UI by typing @, selecting "Prompt Files", and selecting "New Prompt File"). +2. Add a file called `rails.prompt` to this folder. +3. Write the following contents to `rails.prompt` and save. ``` name: Rails Project diff --git a/docs/docs/customize/deep-dives/rules.md b/docs/docs/customize/deep-dives/rules.md new file mode 100644 index 000000000..30100aaeb --- /dev/null +++ b/docs/docs/customize/deep-dives/rules.md @@ -0,0 +1,27 @@ +--- +description: Learn how to customize the system prompt with a `.continuerules` file +keywords: [rules, .continuerules, system, prompt, message] +--- + +# `.continuerules` + +You can create a project-specific system message by adding a `.continuerules` file to the root of your project. This file is raw text and its contents will be inserted into the system message for all LLM requests. + +## Simple Examples + +- If you want concise answers: + +```title=.continuerules +Please provide concise answers. Do explain obvious concepts. You can assume that I am knowledgable about most programming topics. +``` + +- If you want to ensure certain practices are followed, for example in React: + +```title=.continuerules +Whenever you are writing React code, make sure to +- use functional components instead of class components +- use hooks for state management +- define an interface for your component props +- use Tailwind CSS for styling +- modularize components into smaller, reusable pieces +``` From 2fdf39e7511d4e30a80a01291fb56caba9479a66 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 15 Nov 2024 23:04:48 -0800 Subject: [PATCH 82/86] fix default prompt file bug --- core/promptFiles/v2/createNewPromptFile.ts | 3 --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/promptFiles/v2/createNewPromptFile.ts b/core/promptFiles/v2/createNewPromptFile.ts index 21ff3c7c1..0a8adc25d 100644 --- a/core/promptFiles/v2/createNewPromptFile.ts +++ b/core/promptFiles/v2/createNewPromptFile.ts @@ -26,9 +26,6 @@ const FIRST_TIME_DEFAULT_PROMPT_FILE = `# This is an example ".prompt" file # To learn more, see the full .prompt file reference: https://docs.continue.dev/features/prompt-files name: Example - -# For example, here is how you would write a .prompt -name: Example description: Example prompt file --- diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 24930d980..3dc6757e7 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.229", + "version": "0.9.231", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.229", + "version": "0.9.231", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index e7b6c8271..186d18219 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.230", + "version": "0.9.231", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 2f84ef0ab9a87aa6300415d30db02e3460a07195 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 15 Nov 2024 15:29:54 -0800 Subject: [PATCH 83/86] feat: capture python definitions --- .../RootPathContextService.ts | 7 +- .../test/RootPathContextService.test.ts | 25 +-- .../root-path-context/test/files/file1.py | 13 -- .../test/files/python/classes.py | 11 ++ .../test/files/python/functions.py | 42 +++++ .../files/{ => typescript}/arrowFunctions.ts | 0 .../files/{ => typescript}/classMethods.ts | 0 .../test/files/{ => typescript}/classes.ts | 0 .../test/files/{ => typescript}/functions.ts | 0 .../test/files/{ => typescript}/generators.ts | 0 .../root-path-context/test/testCases/index.ts | 2 + .../test/testCases/python.ts | 145 ++++++++++++++++++ .../test/testCases/typescript.ts | 72 ++++----- .../python/class_definition.scm | 27 +++- .../python/function_definition.scm | 71 +++++++-- 15 files changed, 322 insertions(+), 93 deletions(-) delete mode 100644 core/autocomplete/context/root-path-context/test/files/file1.py create mode 100644 core/autocomplete/context/root-path-context/test/files/python/classes.py create mode 100644 core/autocomplete/context/root-path-context/test/files/python/functions.py rename core/autocomplete/context/root-path-context/test/files/{ => typescript}/arrowFunctions.ts (100%) rename core/autocomplete/context/root-path-context/test/files/{ => typescript}/classMethods.ts (100%) rename core/autocomplete/context/root-path-context/test/files/{ => typescript}/classes.ts (100%) rename core/autocomplete/context/root-path-context/test/files/{ => typescript}/functions.ts (100%) rename core/autocomplete/context/root-path-context/test/files/{ => typescript}/generators.ts (100%) create mode 100644 core/autocomplete/context/root-path-context/test/testCases/index.ts create mode 100644 core/autocomplete/context/root-path-context/test/testCases/python.ts diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 0147df151..8571acd0a 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -82,9 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - // const type = node.type; - // console.log(getSyntaxTreeString(node)); - // debugger; + const type = node.type; + console.log(getSyntaxTreeString(node)); + debugger; query = await getQueryForFile( filepath, @@ -176,6 +176,7 @@ export class RootPathContextService { parentKey = key; } + debugger; return snippets; } } diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index 78aed69a7..a954dda84 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -1,30 +1,9 @@ -import { TYPESCRIPT_TEST_CASES } from "./testCases/typescript"; +import { PYTHON_TEST_CASES, TYPESCRIPT_TEST_CASES } from "./testCases"; import { testRootPathContext } from "./testUtils"; const TEST_CASES = [ + ...PYTHON_TEST_CASES, ...TYPESCRIPT_TEST_CASES, - { - nodeType: "function_definition", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 4, character: 25 }, - definitionPositions: [ - { row: 3, column: 30 }, // Person - { row: 3, column: 42 }, // Address - ], - }, - { - nodeType: "function_definition (inside a class)", - fileName: "file1.py", - language: "Python", - cursorPosition: { line: 12, character: 33 }, - definitionPositions: [ - { row: 6, column: 21 }, // BaseClass - { row: 6, column: 33 }, // Collection - { row: 11, column: 47 }, // Person - { row: 11, column: 59 }, // Address - ], - }, { nodeType: "function_definition", fileName: "file1.php", diff --git a/core/autocomplete/context/root-path-context/test/files/file1.py b/core/autocomplete/context/root-path-context/test/files/file1.py deleted file mode 100644 index 55c3d9c25..000000000 --- a/core/autocomplete/context/root-path-context/test/files/file1.py +++ /dev/null @@ -1,13 +0,0 @@ -from .base_module import BaseClass, Collection, Person, Address -from typing import List - -def get_address(person: Person) -> Address: - return person.address - -class Group(BaseClass, Collection): - def __init__(self, people: List[Person]) -> None: - super().__init__() - self.people = people - - def get_person_address(self, person: Person) -> Address: - return get_address(person) diff --git a/core/autocomplete/context/root-path-context/test/files/python/classes.py b/core/autocomplete/context/root-path-context/test/files/python/classes.py new file mode 100644 index 000000000..d752d8433 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/python/classes.py @@ -0,0 +1,11 @@ +class Group(BaseClass, Person): + pass + +class Group(metaclass=MetaGroup): + pass + +class Group(BaseClass[Address], Gathering[Person]): + pass + +class Group(List[Address], Person[str]): + pass \ No newline at end of file diff --git a/core/autocomplete/context/root-path-context/test/files/python/functions.py b/core/autocomplete/context/root-path-context/test/files/python/functions.py new file mode 100644 index 000000000..74a9d8b58 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/files/python/functions.py @@ -0,0 +1,42 @@ +from typing import List, Union, TypeVar, Generic + +T = TypeVar('T') + +class Address: + pass + +class Person: + pass + +class PersonWithGeneric(Generic[T]): + pass + + +def get_address(person: Person) -> Address: + pass + +def get_group_address(people: Group[Person]) -> Group[Address]: + pass + +def log_person(person: Person) -> None: + pass + +def get_hardcoded_address() -> Address: + pass + +def log_person_or_address(value: Union[Person, Address]) -> Union[Person, Address]: + pass + +def log_person_and_address(person: Person, address: Address) -> None: + pass + +def get_address_generator(person: Person) -> Generator[Address, None, None]: + yield + + +class Group: + def log_person_and_address(self, person: Person, address: Address) -> None: + pass + +async def get_person(address: Address) -> Person: + pass \ No newline at end of file diff --git a/core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts b/core/autocomplete/context/root-path-context/test/files/typescript/arrowFunctions.ts similarity index 100% rename from core/autocomplete/context/root-path-context/test/files/arrowFunctions.ts rename to core/autocomplete/context/root-path-context/test/files/typescript/arrowFunctions.ts diff --git a/core/autocomplete/context/root-path-context/test/files/classMethods.ts b/core/autocomplete/context/root-path-context/test/files/typescript/classMethods.ts similarity index 100% rename from core/autocomplete/context/root-path-context/test/files/classMethods.ts rename to core/autocomplete/context/root-path-context/test/files/typescript/classMethods.ts diff --git a/core/autocomplete/context/root-path-context/test/files/classes.ts b/core/autocomplete/context/root-path-context/test/files/typescript/classes.ts similarity index 100% rename from core/autocomplete/context/root-path-context/test/files/classes.ts rename to core/autocomplete/context/root-path-context/test/files/typescript/classes.ts diff --git a/core/autocomplete/context/root-path-context/test/files/functions.ts b/core/autocomplete/context/root-path-context/test/files/typescript/functions.ts similarity index 100% rename from core/autocomplete/context/root-path-context/test/files/functions.ts rename to core/autocomplete/context/root-path-context/test/files/typescript/functions.ts diff --git a/core/autocomplete/context/root-path-context/test/files/generators.ts b/core/autocomplete/context/root-path-context/test/files/typescript/generators.ts similarity index 100% rename from core/autocomplete/context/root-path-context/test/files/generators.ts rename to core/autocomplete/context/root-path-context/test/files/typescript/generators.ts diff --git a/core/autocomplete/context/root-path-context/test/testCases/index.ts b/core/autocomplete/context/root-path-context/test/testCases/index.ts new file mode 100644 index 000000000..7859fc23d --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/testCases/index.ts @@ -0,0 +1,2 @@ +export * from "./python"; +export * from "./typescript"; diff --git a/core/autocomplete/context/root-path-context/test/testCases/python.ts b/core/autocomplete/context/root-path-context/test/testCases/python.ts new file mode 100644 index 000000000..9c8d46e43 --- /dev/null +++ b/core/autocomplete/context/root-path-context/test/testCases/python.ts @@ -0,0 +1,145 @@ +export const FUNCTIONS = [ + { + nodeType: "function_definition with argument and return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 15, character: 8 }, + definitionPositions: [ + { row: 14, column: 30 }, // Person + { row: 14, column: 42 }, // Address + ], + }, + { + nodeType: + "function_definition with generic argument and generic return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 18, character: 8 }, + definitionPositions: [ + { row: 17, column: 35 }, // Group + { row: 17, column: 42 }, // Person + { row: 17, column: 53 }, // Group + { row: 17, column: 61 }, // Address + ], + }, + { + nodeType: "function_definition with single argument and None return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 21, character: 8 }, + definitionPositions: [ + { row: 20, column: 29 }, // Person + ], + }, + { + nodeType: "function_definition with no arguments and single return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 24, character: 8 }, + definitionPositions: [ + { row: 23, column: 38 }, // Address + ], + }, + { + nodeType: "function_definition with Union arguments and Union return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 27, character: 8 }, + definitionPositions: [ + { row: 26, column: 45 }, // Person + { row: 26, column: 54 }, // Address + { row: 26, column: 72 }, // Person + { row: 26, column: 81 }, // Address + ], + }, + { + nodeType: + "function_definition with multiple arguments and None return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 30, character: 8 }, + definitionPositions: [ + { row: 29, column: 41 }, // Person + { row: 29, column: 59 }, // Address + ], + }, + { + nodeType: "function_definition with one argument and Generator return type", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 33, character: 9 }, + definitionPositions: [ + { row: 32, column: 40 }, // Person + { row: 32, column: 62 }, // Address + ], + }, + { + nodeType: "function_definition inside a class", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 38, character: 12 }, + definitionPositions: [ + { row: 37, column: 51 }, // Person + { row: 37, column: 69 }, // Address + ], + }, + { + nodeType: "function_definition of an async function", + fileName: "python/functions.py", + language: "Python", + cursorPosition: { line: 41, character: 8 }, + definitionPositions: [ + { row: 40, column: 37 }, // Address + { row: 40, column: 48 }, // Person + ], + }, +]; + +export const CLASSES = [ + { + nodeType: "class_definition with multiple superclasses", + fileName: "python/classes.py", + language: "Python", + cursorPosition: { line: 1, character: 8 }, + definitionPositions: [ + { row: 0, column: 21 }, // BaseClass + { row: 0, column: 29 }, // Person + ], + }, + { + nodeType: "class_definition with multiple superclasses", + fileName: "python/classes.py", + language: "Python", + cursorPosition: { line: 4, character: 8 }, + definitionPositions: [ + { row: 3, column: 31 }, // MetaGroup + ], + }, + { + nodeType: "class_definition with generic superclasses", + fileName: "python/classes.py", + language: "Python", + cursorPosition: { line: 7, character: 8 }, + definitionPositions: [ + { row: 6, column: 21 }, // BaseClass + { row: 6, column: 29 }, // Address + { row: 6, column: 41 }, // Gathering + { row: 6, column: 48 }, // Person + ], + }, + { + nodeType: "class_definition with generic superclasses (built in types)", + fileName: "python/classes.py", + language: "Python", + cursorPosition: { line: 10, character: 8 }, + definitionPositions: [ + { row: 9, column: 24 }, // Address + { row: 9, column: 33 }, // Person + ], + }, +]; + +export const PYTHON_TEST_CASES = [ + // ...FUNCTIONS, + ...CLASSES, +]; diff --git a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts index f945a02a9..ddda2bfde 100644 --- a/core/autocomplete/context/root-path-context/test/testCases/typescript.ts +++ b/core/autocomplete/context/root-path-context/test/testCases/typescript.ts @@ -1,7 +1,7 @@ const FUNCTIONS = [ { nodeType: "function_declaration with a param and a return type", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 3, character: 9 }, definitionPositions: [ @@ -11,7 +11,7 @@ const FUNCTIONS = [ }, { nodeType: "function_declaration with array param", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 7, character: 9 }, definitionPositions: [ @@ -21,7 +21,7 @@ const FUNCTIONS = [ }, { nodeType: "function_declaration without return type", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 11, character: 9 }, definitionPositions: [ @@ -30,7 +30,7 @@ const FUNCTIONS = [ }, { nodeType: "function_declaration without params", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 15, character: 9 }, definitionPositions: [ @@ -39,7 +39,7 @@ const FUNCTIONS = [ }, { nodeType: "function_declaration with array params and array return type", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 19, character: 9 }, definitionPositions: [ @@ -50,7 +50,7 @@ const FUNCTIONS = [ { nodeType: "function_declaration with generic params and generic return type", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 23, character: 9 }, definitionPositions: [ @@ -63,7 +63,7 @@ const FUNCTIONS = [ { nodeType: "function_declaration with union type params and union return type", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 27, character: 9 }, definitionPositions: [ @@ -75,7 +75,7 @@ const FUNCTIONS = [ }, { nodeType: "function_declaration with two arguments", - fileName: "functions.ts", + fileName: "typescript/functions.ts", language: "TypeScript", cursorPosition: { line: 31, character: 9 }, definitionPositions: [ @@ -88,7 +88,7 @@ const FUNCTIONS = [ const GENERATORS = [ { nodeType: "function_declaration with a param and a return type", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 3, character: 9 }, definitionPositions: [ @@ -98,7 +98,7 @@ const GENERATORS = [ }, { nodeType: "function_declaration with array param", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 7, character: 9 }, definitionPositions: [ @@ -108,7 +108,7 @@ const GENERATORS = [ }, { nodeType: "function_declaration without return type", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 11, character: 9 }, definitionPositions: [ @@ -117,7 +117,7 @@ const GENERATORS = [ }, { nodeType: "function_declaration without params", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 15, character: 9 }, definitionPositions: [ @@ -126,7 +126,7 @@ const GENERATORS = [ }, { nodeType: "function_declaration with array params and array return type", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 19, character: 9 }, definitionPositions: [ @@ -137,7 +137,7 @@ const GENERATORS = [ { nodeType: "function_declaration with generic params and generic return type", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 23, character: 9 }, definitionPositions: [ @@ -150,7 +150,7 @@ const GENERATORS = [ { nodeType: "function_declaration with union type params and union return type", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 27, character: 9 }, definitionPositions: [ @@ -162,7 +162,7 @@ const GENERATORS = [ }, { nodeType: "function_declaration with two arguments", - fileName: "generators.ts", + fileName: "typescript/generators.ts", language: "TypeScript", cursorPosition: { line: 31, character: 9 }, definitionPositions: [ @@ -175,7 +175,7 @@ const GENERATORS = [ const ARROW_FUNCTIONS = [ { nodeType: "arrow_function with a param and a return type", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 3, character: 9 }, definitionPositions: [ @@ -185,7 +185,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function without return type", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 7, character: 9 }, definitionPositions: [ @@ -194,7 +194,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function without params", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 11, character: 9 }, definitionPositions: [ @@ -203,7 +203,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function with array params and array return type", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 15, character: 9 }, definitionPositions: [ @@ -213,7 +213,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function with generic params and generic return type", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 19, character: 9 }, definitionPositions: [ @@ -225,7 +225,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function with union type params and union return type", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 23, character: 9 }, definitionPositions: [ @@ -237,7 +237,7 @@ const ARROW_FUNCTIONS = [ }, { nodeType: "arrow_function with two arguments", - fileName: "arrowFunctions.ts", + fileName: "typescript/arrowFunctions.ts", language: "TypeScript", cursorPosition: { line: 27, character: 11 }, definitionPositions: [ @@ -250,7 +250,7 @@ const ARROW_FUNCTIONS = [ const CLASS_METHODS = [ { nodeType: "method_declaration with a param and a return type", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 4, character: 11 }, definitionPositions: [ @@ -260,7 +260,7 @@ const CLASS_METHODS = [ }, { nodeType: "method_declaration without arguments", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 8, character: 11 }, definitionPositions: [ @@ -269,7 +269,7 @@ const CLASS_METHODS = [ }, { nodeType: "method_declaration without return type", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 12, character: 11 }, definitionPositions: [ @@ -278,7 +278,7 @@ const CLASS_METHODS = [ }, { nodeType: "method_declaration with array type arguments", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 16, character: 11 }, definitionPositions: [ @@ -288,7 +288,7 @@ const CLASS_METHODS = [ { nodeType: "method_declaration with array type arguments and array type return", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 20, character: 11 }, definitionPositions: [ @@ -299,7 +299,7 @@ const CLASS_METHODS = [ { nodeType: "method_declaration with with generic params and generic return type", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 24, character: 11 }, definitionPositions: [ @@ -311,7 +311,7 @@ const CLASS_METHODS = [ }, { nodeType: "method_declaration with union type params and union return type", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 28, character: 11 }, definitionPositions: [ @@ -323,7 +323,7 @@ const CLASS_METHODS = [ }, { nodeType: "method_declaration with two arguments", - fileName: "classMethods.ts", + fileName: "typescript/classMethods.ts", language: "TypeScript", cursorPosition: { line: 32, character: 11 }, definitionPositions: [ @@ -336,7 +336,7 @@ const CLASS_METHODS = [ const CLASS_DEFINITIONS = [ { nodeType: "class_declaration with base class", - fileName: "classes.ts", + fileName: "typescript/classes.ts", language: "TypeScript", cursorPosition: { line: 2, character: 31 }, definitionPositions: [ @@ -345,7 +345,7 @@ const CLASS_DEFINITIONS = [ }, { nodeType: "class_declaration with interface", - fileName: "classes.ts", + fileName: "typescript/classes.ts", language: "TypeScript", cursorPosition: { line: 4, character: 39 }, definitionPositions: [ @@ -354,7 +354,7 @@ const CLASS_DEFINITIONS = [ }, { nodeType: "class_declaration with base class and multiple interfaces", - fileName: "classes.ts", + fileName: "typescript/classes.ts", language: "TypeScript", cursorPosition: { line: 6, character: 74 }, definitionPositions: [ @@ -365,7 +365,7 @@ const CLASS_DEFINITIONS = [ }, { nodeType: "class_declaration with base class and multiple interfaces", - fileName: "classes.ts", + fileName: "typescript/classes.ts", language: "TypeScript", cursorPosition: { line: 6, character: 74 }, definitionPositions: [ @@ -376,7 +376,7 @@ const CLASS_DEFINITIONS = [ }, { nodeType: "class_declaration with generic base class and generic interface", - fileName: "classes.ts", + fileName: "typescript/classes.ts", language: "TypeScript", cursorPosition: { line: 8, character: 69 }, definitionPositions: [ diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm b/extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm index 5a9e34b86..61fdb29ec 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/python/class_definition.scm @@ -1,5 +1,24 @@ -( - (class_definition - superclasses: (argument_list - (identifier) @superclass)) +; Match superclass identifiers in a simple inheritance +(class_definition + superclasses: (argument_list + (identifier) @catch) + (#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; Match the value of a keyword argument in class inheritance +(class_definition + superclasses: (argument_list + (keyword_argument + (_) + (identifier) @catch)) + (#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; Match identifiers within subscripts in class inheritance +(class_definition + superclasses: (argument_list + (subscript + (identifier) @catch + )) + (#not-match? @catch "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") ) \ No newline at end of file diff --git a/extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm b/extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm index 864666a4a..535882bfa 100644 --- a/extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm +++ b/extensions/vscode/tree-sitter/root-path-context-queries/python/function_definition.scm @@ -1,17 +1,60 @@ -( - (function_definition - (parameters - (_ - (type) @a - (#not-match? @a "^(str|int|float|bool|list|dict|tuple)$") - ) - ) - ) +; When the type is a simple identifier: +(function_definition + parameters: (parameters + (typed_parameter + type: (type + (identifier) @type_identifier))) + + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") ) -( - (function_definition - (type) @b - (#not-match? @b "^(str|int|float|bool|list|dict|tuple)$") - ) +; When the type is a generic type with one identifier +(function_definition + parameters: (parameters + (typed_parameter + type: (type + (generic_type + (identifier) @type_identifier)))) + + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; When the generic type has type parameters with one identifier +(function_definition + parameters: (parameters + (typed_parameter + type: (type + (generic_type + (identifier) + (type_parameter + (type + (identifier) @type_identifier)))))) + + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; When the return type is a simple identifier +(function_definition + return_type: (type + (identifier) @type_identifier) + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; When the return type is a generic type with one identifier +(function_definition + return_type: (type + (generic_type + (identifier) @type_identifier)) + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") +) + +; When the generic type has type parameters with one identifier +(function_definition + return_type: (type + (generic_type + (identifier) + (type_parameter + (type + (identifier) @type_identifier)))) + (#not-match? @type_identifier "^(str|int|float|bool|list|dict|tuple|set|frozenset|complex|bytes|bytearray|memoryview|range|slice|object|type|NoneType|List|Dict|Tuple|Set|FrozenSet|Union|Optional|Any|Callable|Iterable|Iterator|Generator|Coroutine|AsyncIterable|AsyncIterator|Awaitable|ContextManager|Pattern|Match|TypeVar|Generic|Sequence|Mapping|MutableMapping|MutableSequence|ByteString|Reversible|Sized|Container|Collection|AbstractSet|MutableSet|KeysView|ItemsView|ValuesView|Hashable|Sized|SupportsInt|SupportsFloat|SupportsComplex|SupportsBytes|SupportsAbs|SupportsRound|ChainMap|Counter|OrderedDict|defaultdict|deque|namedtuple|TypedDict)$") ) \ No newline at end of file From 5a5903f178283fdcd2de4f41349c7e56909f80b9 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Sun, 17 Nov 2024 18:24:12 -0800 Subject: [PATCH 84/86] refactor: cleanup --- .../context/root-path-context/RootPathContextService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 8571acd0a..5e37f9143 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -82,9 +82,9 @@ export class RootPathContextService { this.importDefinitionsService.get(filepath); break; default: - const type = node.type; - console.log(getSyntaxTreeString(node)); - debugger; + // const type = node.type; + // console.log(getSyntaxTreeString(node)); + // debugger; query = await getQueryForFile( filepath, From 3a64c61207dfcccd88440ac6e90f7c2c0318247f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Sun, 17 Nov 2024 18:24:44 -0800 Subject: [PATCH 85/86] refactor: cleanup --- .../context/root-path-context/RootPathContextService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/autocomplete/context/root-path-context/RootPathContextService.ts b/core/autocomplete/context/root-path-context/RootPathContextService.ts index 5e37f9143..0147df151 100644 --- a/core/autocomplete/context/root-path-context/RootPathContextService.ts +++ b/core/autocomplete/context/root-path-context/RootPathContextService.ts @@ -176,7 +176,6 @@ export class RootPathContextService { parentKey = key; } - debugger; return snippets; } } From aaebd85c323cc31e8372f2f935412d11bffae01c Mon Sep 17 00:00:00 2001 From: markMe1024 Date: Mon, 18 Nov 2024 10:56:20 +0800 Subject: [PATCH 86/86] fix issue: every accepted attribute in the file ~/.continue/dev_data/autocomplete.jsonl is true --- core/autocomplete/util/AutocompleteLoggingService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/autocomplete/util/AutocompleteLoggingService.ts b/core/autocomplete/util/AutocompleteLoggingService.ts index ff0c5d493..96261e646 100644 --- a/core/autocomplete/util/AutocompleteLoggingService.ts +++ b/core/autocomplete/util/AutocompleteLoggingService.ts @@ -37,6 +37,7 @@ export class AutocompleteLoggingService { if (this._outcomes.has(completionId)) { const outcome = this._outcomes.get(completionId)!; + outcome.accepted = true; this.logAutocompleteOutcome(outcome); this._outcomes.delete(completionId); return outcome; @@ -94,7 +95,6 @@ export class AutocompleteLoggingService { } private logAutocompleteOutcome(outcome: AutocompleteOutcome) { - outcome.accepted = true; logDevData("autocomplete", outcome); const { prompt, completion, prefix, suffix, ...restOfOutcome } = outcome; void Telemetry.capture(