From 18d09436b681423ab999b7321fc10c773d0d0a50 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 7 Nov 2024 15:19:05 -0800 Subject: [PATCH 1/6] get current file returns contents and untitled status --- core/config/promptFile.ts | 7 +- core/config/types.ts | 6 +- .../providers/CurrentFileContextProvider.ts | 12 ++- core/index.d.ts | 6 +- .../promptFiles/slashCommandFromPromptFile.ts | 8 +- core/protocol/ide.ts | 6 +- core/util/filesystem.ts | 10 +-- core/util/messageIde.ts | 2 +- .../continue/IdeProtocolClient.kt | 10 ++- .../continueintellijextension/continue/a test | 2 + extensions/vscode/package-lock.json | 2 +- extensions/vscode/src/VsCodeIde.ts | 74 ++++++++++++++++++- .../vscode/src/extension/VsCodeExtension.ts | 5 +- .../src/test/test-suites/ideUtils.test.ts | 7 -- extensions/vscode/src/util/ideUtils.ts | 57 +------------- gui/src/hooks/useChatHandler.ts | 24 +++--- 16 files changed, 127 insertions(+), 111 deletions(-) create mode 100644 extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test diff --git a/core/config/promptFile.ts b/core/config/promptFile.ts index ebbbd59ab4..a22dfadde6 100644 --- a/core/config/promptFile.ts +++ b/core/config/promptFile.ts @@ -152,15 +152,12 @@ async function renderPrompt(prompt: string, context: any, userInput: string) { // A few context providers that don't need to be in config.json to work in .prompt files const diff = await context.ide.getDiff(false); - const currentFilePath = await context.ide.getCurrentFile(); - const currentFile = currentFilePath - ? await context.ide.readFile(currentFilePath) - : undefined; + const currentFile = await context.ide.getCurrentFile(); return renderTemplatedString( prompt, context.ide.readFile.bind(context.ide), - { diff, currentFile, input: userInput }, + { diff, currentFile: currentFile?.contents, input: userInput }, helpers, ); } diff --git a/core/config/types.ts b/core/config/types.ts index ca8ee9bec6..b886ea0214 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -463,7 +463,11 @@ declare global { stepIndex: number, ): Promise; getOpenFiles(): Promise; - getCurrentFile(): Promise; + getCurrentFile(): Promise; getPinnedFiles(): Promise; getSearchResults(query: string): Promise; subprocess(command: string): Promise<[string, string]>; diff --git a/core/context/providers/CurrentFileContextProvider.ts b/core/context/providers/CurrentFileContextProvider.ts index 575350b49a..5e75f85c8d 100644 --- a/core/context/providers/CurrentFileContextProvider.ts +++ b/core/context/providers/CurrentFileContextProvider.ts @@ -24,17 +24,15 @@ class CurrentFileContextProvider extends BaseContextProvider { if (!currentFile) { return []; } - const contents = await ide.readFile(currentFile); + const baseName = getBasename(currentFile.path); return [ { - description: currentFile, - content: `This is the currently open file:\n\n\`\`\`${getBasename( - currentFile, - )}\n${contents}\n\`\`\``, - name: getBasename(currentFile), + description: currentFile.path, + content: `This is the currently open file:\n\n\`\`\`${baseName}\n${currentFile.contents}\n\`\`\``, + name: baseName, uri: { type: "file", - value: currentFile, + value: currentFile.path, }, }, ]; diff --git a/core/index.d.ts b/core/index.d.ts index 5b0b892f67..071d61814e 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -494,7 +494,11 @@ export interface IDE { stepIndex: number, ): Promise; getOpenFiles(): Promise; - getCurrentFile(): Promise; + getCurrentFile(): Promise; getPinnedFiles(): Promise; getSearchResults(query: string): Promise; subprocess(command: string, cwd?: string): Promise<[string, string]>; diff --git a/core/promptFiles/slashCommandFromPromptFile.ts b/core/promptFiles/slashCommandFromPromptFile.ts index e81f13615d..3df3cb8fee 100644 --- a/core/promptFiles/slashCommandFromPromptFile.ts +++ b/core/promptFiles/slashCommandFromPromptFile.ts @@ -38,12 +38,8 @@ export function extractUserInput(input: string, commandName: string): string { } export async function getDefaultVariables(context: any, userInput: string) { - const currentFilePath = await context.ide.getCurrentFile(); - const currentFile = currentFilePath - ? await context.ide.readFile(currentFilePath) - : undefined; - - return { currentFile, input: userInput }; + const currentFile = await context.ide.getCurrentFile(); + return { currentFile: currentFile?.contents, input: userInput }; } export async function renderPrompt( diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index eda6bebfbb..d6b6a90d39 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -48,7 +48,11 @@ export type ToIdeFromWebviewOrCoreProtocol = { ]; getProblems: [{ filepath: string }, Problem[]]; getOpenFiles: [undefined, string[]]; - getCurrentFile: [undefined, string | undefined]; + getCurrentFile: [undefined, undefined | { + isUntitled: boolean; + path: string; + contents: string; + }]; getPinnedFiles: [undefined, string[]]; showLines: [{ filepath: string; startLine: number; endLine: number }, void]; readRangeInFile: [{ filepath: string; range: Range }, string]; diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 0f64d912cf..459e0adee0 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -19,7 +19,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, @@ -205,6 +205,10 @@ class FileSystemIde implements IDE { }); } + getCurrentFile(): Promise { + return Promise.resolve(undefined); + } + showDiff( filepath: string, newContents: string, @@ -221,10 +225,6 @@ class FileSystemIde implements IDE { return Promise.resolve([]); } - getCurrentFile(): Promise { - return Promise.resolve(""); - } - getPinnedFiles(): Promise { return Promise.resolve([]); } diff --git a/core/util/messageIde.ts b/core/util/messageIde.ts index 1fab1c6b92..75c9808093 100644 --- a/core/util/messageIde.ts +++ b/core/util/messageIde.ts @@ -177,7 +177,7 @@ export class MessageIde implements IDE { return this.request("getOpenFiles", undefined); } - getCurrentFile(): Promise { + getCurrentFile() { return this.request("getCurrentFile", undefined); } 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 17c89ec857..17a8da0249 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 @@ -1006,11 +1006,17 @@ class IdeProtocolClient( // return openFiles.intersect(pinnedFiles).toList() } - private fun currentFile(): String? { + private fun currentFile(): Map? { val fileEditorManager = FileEditorManager.getInstance(project) val editor = fileEditorManager.selectedTextEditor val virtualFile = editor?.document?.let { FileDocumentManager.getInstance().getFile(it) } - return virtualFile?.path + return virtualFile?.let { + mapOf( + "filePath" to it.path, + "fileContents" to editor.document.text, + "isUntitled" to false + ) + } } suspend fun showToast(type: String, content: String, buttonTexts: Array = emptyArray()): String? = diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test new file mode 100644 index 0000000000..246284309d --- /dev/null +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test @@ -0,0 +1,2 @@ +asdfasdfasdfasd +her's new co \ No newline at end of file diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3baee50b09..466cd705e2 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -12599,4 +12599,4 @@ } } } -} \ No newline at end of file +} diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index c36516018a..5c5e617f4e 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -255,6 +255,7 @@ class VsCodeIde implements IDE { return tags; } + getIdeInfo(): Promise { return Promise.resolve({ ideType: "vscode", @@ -266,6 +267,7 @@ class VsCodeIde implements IDE { .version, }); } + readRangeInFile(filepath: string, range: Range): Promise { return this.ideUtils.readRangeInFile( filepath, @@ -342,7 +344,7 @@ class VsCodeIde implements IDE { type === vscode.FileType.SymbolicLink) && filename === ".continuerc.json" ) { - const contents = await this.ideUtils.readFile( + const contents = await this.readFile( vscode.Uri.joinPath(workspaceDir, filename).fsPath, ); configs.push(JSON.parse(contents)); @@ -421,8 +423,66 @@ class VsCodeIde implements IDE { async saveFile(filepath: string): Promise { await this.ideUtils.saveFile(filepath); } + + private static MAX_BYTES = 100000; + async readFile(filepath: string): Promise { - return await this.ideUtils.readFile(filepath); + try { + filepath = this.ideUtils.getAbsolutePath(filepath); + const uri = uriFromFilePath(filepath); + + // First, check whether it's a notebook document + // Need to iterate over the cells to get full contents + const notebook = + vscode.workspace.notebookDocuments.find( + (doc) => doc.uri.toString() === uri.toString(), + ) ?? + (uri.fsPath.endsWith("ipynb") + ? await vscode.workspace.openNotebookDocument(uri) + : undefined); + if (notebook) { + return notebook + .getCells() + .map((cell) => cell.document.getText()) + .join("\n\n"); + } + + // Check if the document is an untitled (new and unsaved) document + const untitledDocs = vscode.workspace.textDocuments.filter( + (doc) => doc.isUntitled && doc, + ); + const untitledDoc = vscode.workspace.textDocuments.find( + (doc) => doc.isUntitled && doc.uri.fsPath === uri.fsPath + ); + if (untitledDoc) { + return untitledDoc.getText(); + } + + // Check whether it's an open document + const openTextDocument = vscode.workspace.textDocuments.find( + (doc) => doc.uri.fsPath === uri.fsPath, + ); + if (openTextDocument !== undefined) { + return openTextDocument.getText(); + } + + const fileStats = await vscode.workspace.fs.stat( + uriFromFilePath(filepath), + ); + if (fileStats.size > 10 * VsCodeIde.MAX_BYTES) { + return ""; + } + + const bytes = await vscode.workspace.fs.readFile(uri); + + // Truncate the buffer to the first MAX_BYTES + const truncatedBytes = bytes.slice(0, VsCodeIde.MAX_BYTES); + const contents = new TextDecoder().decode(truncatedBytes); + return contents; + } catch (e) { + console.warn("Error reading file", e); + return ""; + } } async showDiff( filepath: string, @@ -436,8 +496,13 @@ class VsCodeIde implements IDE { return await this.ideUtils.getOpenFiles(); } - async getCurrentFile(): Promise { - return vscode.window.activeTextEditor?.document.uri.fsPath; + async getCurrentFile() { + if (!vscode.window.activeTextEditor) return undefined + return { + isUntitled: vscode.window.activeTextEditor.document.isUntitled, + path: vscode.window.activeTextEditor.document.uri.fsPath, + contents: vscode.window.activeTextEditor.document.getText() + } } async getPinnedFiles(): Promise { @@ -572,3 +637,4 @@ class VsCodeIde implements IDE { } export { VsCodeIde }; + diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 2eda0c1927..e9f9cbad74 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -278,7 +278,7 @@ export class VsCodeExtension { // Reindex the workspaces this.core.invoke("index/forceReIndex", undefined); } else { - // Reindex the file + // Reindex the filex const indexer = await this.core.codebaseIndexerPromise; indexer.refreshFile(filepath); } @@ -329,8 +329,7 @@ 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; diff --git a/extensions/vscode/src/test/test-suites/ideUtils.test.ts b/extensions/vscode/src/test/test-suites/ideUtils.test.ts index adae3fab4c..f994b38102 100644 --- a/extensions/vscode/src/test/test-suites/ideUtils.test.ts +++ b/extensions/vscode/src/test/test-suites/ideUtils.test.ts @@ -59,13 +59,6 @@ describe("IDE Utils", () => { assert(regex.test(uniqueId)); }); - test("readFile", async () => { - const testPyContents = await utils.readFile(testPyPath); - assert(testPyContents === "print('Hello World!')"); - const testJsContents = await utils.readFile(testJsPath); - assert(testJsContents === "console.log('Hello World!')"); - }); - test.skip("getTerminalContents", async () => { await new Promise((resolve) => setTimeout(resolve, 1000)); const terminal = vscode.window.createTerminal(); diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index 6ebb9c1a1b..2dd9cd3300 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -177,8 +177,7 @@ export class VsCodeIdeUtils { vscode.workspace .openTextDocument( vscode.Uri.parse( - `${ - VsCodeExtension.continueVirtualDocumentScheme + `${VsCodeExtension.continueVirtualDocumentScheme }:${encodeURIComponent(name)}?${encodeURIComponent(contents)}`, ), ) @@ -291,56 +290,6 @@ export class VsCodeIdeUtils { } } - private static MAX_BYTES = 100000; - - async readFile(filepath: string): Promise { - try { - filepath = this.getAbsolutePath(filepath); - const uri = uriFromFilePath(filepath); - - // First, check whether it's a notebook document - // Need to iterate over the cells to get full contents - const notebook = - vscode.workspace.notebookDocuments.find( - (doc) => doc.uri.toString() === uri.toString(), - ) ?? - (uri.fsPath.endsWith("ipynb") - ? await vscode.workspace.openNotebookDocument(uri) - : undefined); - if (notebook) { - return notebook - .getCells() - .map((cell) => cell.document.getText()) - .join("\n\n"); - } - - // Check whether it's an open document - const openTextDocument = vscode.workspace.textDocuments.find( - (doc) => doc.uri.fsPath === uri.fsPath, - ); - if (openTextDocument !== undefined) { - return openTextDocument.getText(); - } - - const fileStats = await vscode.workspace.fs.stat( - uriFromFilePath(filepath), - ); - if (fileStats.size > 10 * VsCodeIdeUtils.MAX_BYTES) { - return ""; - } - - const bytes = await vscode.workspace.fs.readFile(uri); - - // Truncate the buffer to the first MAX_BYTES - const truncatedBytes = bytes.slice(0, VsCodeIdeUtils.MAX_BYTES); - const contents = new TextDecoder().decode(truncatedBytes); - return contents; - } catch (e) { - console.warn("Error reading file", e); - return ""; - } - } - async readRangeInFile( filepath: string, range: vscode.Range, @@ -352,8 +301,8 @@ export class VsCodeIdeUtils { return `${lines .slice(range.start.line, range.end.line) .join("\n")}\n${lines[ - range.end.line < lines.length - 1 ? range.end.line : lines.length - 1 - ].slice(0, range.end.character)}`; + range.end.line < lines.length - 1 ? range.end.line : lines.length - 1 + ].slice(0, range.end.character)}`; } async getTerminalContents(commands = -1): Promise { diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index c90c044dcc..f961e62c1a 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -57,13 +57,13 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { const active = useSelector((store: RootState) => store.state.active); const activeRef = useRef(active); - const {saveSession} = useHistory(dispatch); + const { saveSession } = useHistory(dispatch); const [save, triggerSave] = useState(false); useEffect(() => { saveSession(false); }, [save]); - + useEffect(() => { activeRef.current = active; @@ -217,31 +217,29 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { if (!modifiers.noContext) { const usingFreeTrial = defaultModel?.provider === "free-trial"; - const currentFilePath = await ideMessenger.ide.getCurrentFile(); - if (typeof currentFilePath === "string") { - let currentFileContents = await ideMessenger.ide.readFile( - currentFilePath, - ); + const currentFile = await ideMessenger.ide.getCurrentFile(); + if (currentFile) { + let currentFileContents = currentFile.contents if (usingFreeTrial) { - currentFileContents = currentFileContents + currentFileContents = currentFile.contents .split("\n") .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( - currentFilePath, + currentFile.path, await ideMessenger.ide.getWorkspaceDirs(), )}\n${currentFileContents}\n\`\`\``, - name: `Active file: ${getBasename(currentFilePath)}`, - description: currentFilePath, + name: `Active file: ${getBasename(currentFile.path)}`, + description: currentFile.path, id: { - itemId: currentFilePath, + itemId: currentFile.path, providerTitle: "file", }, uri: { type: "file", - value: currentFilePath, + value: currentFile.path, }, }); } From 8ffa1f0f757794ac920a6a6a594f604a6ebbeeb0 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 7 Nov 2024 15:27:52 -0800 Subject: [PATCH 2/6] untitled active file working --- extensions/vscode/src/VsCodeIde.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 5c5e617f4e..caf3658052 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -447,17 +447,6 @@ class VsCodeIde implements IDE { .join("\n\n"); } - // Check if the document is an untitled (new and unsaved) document - const untitledDocs = vscode.workspace.textDocuments.filter( - (doc) => doc.isUntitled && doc, - ); - const untitledDoc = vscode.workspace.textDocuments.find( - (doc) => doc.isUntitled && doc.uri.fsPath === uri.fsPath - ); - if (untitledDoc) { - return untitledDoc.getText(); - } - // Check whether it's an open document const openTextDocument = vscode.workspace.textDocuments.find( (doc) => doc.uri.fsPath === uri.fsPath, From 779bc84938497facb22eeef320dab012b8ebf0cb Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 7 Nov 2024 15:58:05 -0800 Subject: [PATCH 3/6] broken on jetbrains --- core/config/promptFile.ts | 26 ++++++++++++------- core/config/types.ts | 2 +- core/promptFiles/handlebarUtils.ts | 4 +-- core/promptFiles/renderTemplatedString.ts | 2 +- .../promptFiles/slashCommandFromPromptFile.ts | 12 ++++++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core/config/promptFile.ts b/core/config/promptFile.ts index a22dfadde6..728090fccc 100644 --- a/core/config/promptFile.ts +++ b/core/config/promptFile.ts @@ -1,11 +1,12 @@ import Handlebars from "handlebars"; import path from "path"; import * as YAML from "yaml"; -import type { IDE, SlashCommand } from ".."; +import type { ChatHistory, ChatHistoryItem, ChatMessage, ContextItem, ContinueSDK, IContextProvider, IDE, SlashCommand } from ".."; import { walkDir } from "../indexing/walkDir"; import { stripImages } from "../llm/images"; import { renderTemplatedString } from "../promptFiles/renderTemplatedString"; import { getBasename } from "../util/index"; +import { BaseContextProvider } from "../context"; export const DEFAULT_PROMPTS_FOLDER = ".prompts"; @@ -147,25 +148,32 @@ function extractUserInput(input: string, commandName: string): string { return input; } -async function renderPrompt(prompt: string, context: any, userInput: string) { +async function renderPrompt(prompt: string, context: ContinueSDK, userInput: string) { const helpers = getContextProviderHelpers(context); // A few context providers that don't need to be in config.json to work in .prompt files const diff = await context.ide.getDiff(false); const currentFile = await context.ide.getCurrentFile(); + const inputData: Record = { + diff, + input: userInput, + }; + if (currentFile) { + inputData.currentFile = currentFile.path; + } return renderTemplatedString( prompt, context.ide.readFile.bind(context.ide), - { diff, currentFile: currentFile?.contents, input: userInput }, + inputData, helpers, ); } function getContextProviderHelpers( - context: any, + context: ContinueSDK, ): Array<[string, Handlebars.HelperDelegate]> | undefined { - return context.config.contextProviders?.map((provider: any) => [ + return context.config.contextProviders?.map((provider: IContextProvider) => [ provider.description.title, async (helperContext: any) => { const items = await provider.getContextItems(helperContext, { @@ -179,16 +187,16 @@ function getContextProviderHelpers( selectedCode: context.selectedCode, }); - items.forEach((item: any) => + items.forEach((item) => context.addContextItem(createContextItem(item, provider)), ); - return items.map((item: any) => item.content).join("\n\n"); + return items.map((item) => item.content).join("\n\n"); }, ]); } -function createContextItem(item: any, provider: any) { +function createContextItem(item: ContextItem, provider: IContextProvider) { return { ...item, id: { @@ -199,7 +207,7 @@ function createContextItem(item: any, provider: any) { } function updateChatHistory( - history: any[], + history: ChatMessage[], commandName: string, renderedPrompt: string, systemMessage?: string, diff --git a/core/config/types.ts b/core/config/types.ts index b886ea0214..f457812d18 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -463,7 +463,7 @@ declare global { stepIndex: number, ): Promise; getOpenFiles(): Promise; - getCurrentFile(): Promise Promise, - inputData: any, + inputData: Record, ctxProviderNames: string[], ): Promise<[string, any]> { const [newTemplate, vars] = replaceFilepaths(template, ctxProviderNames); @@ -95,7 +95,7 @@ export async function prepareTemplateAndData( return [newTemplate, data]; } -export function compileAndRenderTemplate(template: string, data: any): string { +export function compileAndRenderTemplate(template: string, data: Record): string { const templateFn = Handlebars.compile(template); return templateFn(data); } diff --git a/core/promptFiles/renderTemplatedString.ts b/core/promptFiles/renderTemplatedString.ts index d31cce0b99..bcc645ace1 100644 --- a/core/promptFiles/renderTemplatedString.ts +++ b/core/promptFiles/renderTemplatedString.ts @@ -8,7 +8,7 @@ import { export async function renderTemplatedString( template: string, readFile: (filepath: string) => Promise, - inputData: any, + inputData: Record, availableHelpers?: Array<[string, Handlebars.HelperDelegate]>, ): Promise { const helperPromises = availableHelpers diff --git a/core/promptFiles/slashCommandFromPromptFile.ts b/core/promptFiles/slashCommandFromPromptFile.ts index 3df3cb8fee..af865078e0 100644 --- a/core/promptFiles/slashCommandFromPromptFile.ts +++ b/core/promptFiles/slashCommandFromPromptFile.ts @@ -1,4 +1,4 @@ -import { SlashCommand } from ".."; +import { ContinueSDK, SlashCommand } from ".."; import { stripImages } from "../llm/images"; import { getContextProviderHelpers } from "./getContextProviderHelpers"; import { renderTemplatedString } from "./renderTemplatedString"; @@ -37,14 +37,18 @@ export function extractUserInput(input: string, commandName: string): string { return input; } -export async function getDefaultVariables(context: any, userInput: string) { +export async function getDefaultVariables(context: ContinueSDK, userInput: string): Promise> { const currentFile = await context.ide.getCurrentFile(); - return { currentFile: currentFile?.contents, input: userInput }; + const vars: Record = { input: userInput }; + if (currentFile) { + vars.currentFile = currentFile.path; + } + return vars; } export async function renderPrompt( prompt: string, - context: any, + context: ContinueSDK, userInput: string, ) { const helpers = getContextProviderHelpers(context); From 35abf4be940e31371d323497115b0be591467f96 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 7 Nov 2024 16:20:12 -0800 Subject: [PATCH 4/6] fix jetbrains bug --- .../continueintellijextension/continue/IdeProtocolClient.kt | 4 ++-- gui/src/hooks/useChatHandler.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 17a8da0249..b773026bdc 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 @@ -1012,8 +1012,8 @@ class IdeProtocolClient( val virtualFile = editor?.document?.let { FileDocumentManager.getInstance().getFile(it) } return virtualFile?.let { mapOf( - "filePath" to it.path, - "fileContents" to editor.document.text, + "path" to it.path, + "contents" to editor.document.text, "isUntitled" to false ) } diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index f961e62c1a..cafd4ce4ca 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -153,7 +153,7 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { clearInterval(checkActiveInterval); } }, 100); - + debugger for await (const update of ideMessenger.streamRequest( "command/run", { From 1740992a9b63876c9fcb9ee983d007094692b026 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 7 Nov 2024 16:20:44 -0800 Subject: [PATCH 5/6] Delete extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test --- .../continuedev/continueintellijextension/continue/a test | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test deleted file mode 100644 index 246284309d..0000000000 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/a test +++ /dev/null @@ -1,2 +0,0 @@ -asdfasdfasdfasd -her's new co \ No newline at end of file From 25f05d95da651a1cbd84375265dfb72cb4f9ced6 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 7 Nov 2024 16:34:43 -0800 Subject: [PATCH 6/6] clean up get current file --- extensions/vscode/src/extension/VsCodeExtension.ts | 2 +- gui/src/hooks/useChatHandler.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index e9f9cbad74..54b2cc67e9 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -278,7 +278,7 @@ export class VsCodeExtension { // Reindex the workspaces this.core.invoke("index/forceReIndex", undefined); } else { - // Reindex the filex + // Reindex the file const indexer = await this.core.codebaseIndexerPromise; indexer.refreshFile(filepath); } diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index cafd4ce4ca..f961e62c1a 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -153,7 +153,7 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { clearInterval(checkActiveInterval); } }, 100); - debugger + for await (const update of ideMessenger.streamRequest( "command/run", {