diff --git a/client/cody-shared/BUILD.bazel b/client/cody-shared/BUILD.bazel index 987f935fdb1d..0fa5a51f7bc2 100644 --- a/client/cody-shared/BUILD.bazel +++ b/client/cody-shared/BUILD.bazel @@ -35,7 +35,6 @@ ts_project( "src/chat/recipes/context-search.ts", "src/chat/recipes/explain-code-detailed.ts", "src/chat/recipes/explain-code-high-level.ts", - "src/chat/recipes/file-touch.ts", "src/chat/recipes/find-code-smells.ts", "src/chat/recipes/fixup.ts", "src/chat/recipes/generate-docstring.ts", @@ -46,6 +45,7 @@ ts_project( "src/chat/recipes/helpers.ts", "src/chat/recipes/improve-variable-names.ts", "src/chat/recipes/inline-chat.ts", + "src/chat/recipes/inline-touch.ts", "src/chat/recipes/langs.ts", "src/chat/recipes/next-questions.ts", "src/chat/recipes/non-stop.ts", diff --git a/client/cody-shared/src/chat/recipes/inline-chat.ts b/client/cody-shared/src/chat/recipes/inline-chat.ts index 7d17792d54c6..def8317ec57d 100644 --- a/client/cody-shared/src/chat/recipes/inline-chat.ts +++ b/client/cody-shared/src/chat/recipes/inline-chat.ts @@ -6,12 +6,12 @@ import { truncateText } from '../../prompt/truncation' import { Interaction } from '../transcript/interaction' import { ChatQuestion } from './chat-question' -import { FileTouch } from './file-touch' import { Fixup } from './fixup' import { commandRegex } from './helpers' +import { InlineTouch } from './inline-touch' import { Recipe, RecipeContext, RecipeID } from './recipe' -export class InlineAssist implements Recipe { +export class InlineChat implements Recipe { public id: RecipeID = 'inline-chat' constructor(private debug: (filterLabel: string, text: string, ...args: unknown[]) => void) {} @@ -19,7 +19,7 @@ export class InlineAssist implements Recipe { public async getInteraction(humanChatInput: string, context: RecipeContext): Promise { // Check if this is a touch request if (commandRegex.touch.test(humanChatInput)) { - return new FileTouch(this.debug).getInteraction(humanChatInput.replace(commandRegex.touch, ''), context) + return new InlineTouch(this.debug).getInteraction(humanChatInput.replace(commandRegex.touch, ''), context) } // Check if this is a fixup request @@ -39,14 +39,13 @@ export class InlineAssist implements Recipe { // Reconstruct Cody's prompt using user's context // Replace placeholders in reverse order to avoid collisions if a placeholder occurs in the input - const promptText = InlineAssist.prompt + const promptText = InlineChat.prompt .replace('{humanInput}', truncatedText) .replace('{selectedText}', truncatedSelectedText) .replace('{fileName}', selection.fileName) // Text display in UI fpr human that includes the selected code - const displayText = - humanChatInput + InlineAssist.displayPrompt.replace('{selectedText}', selection.selectedText) + const displayText = humanChatInput + InlineChat.displayPrompt.replace('{selectedText}', selection.selectedText) return Promise.resolve( new Interaction( diff --git a/client/cody-shared/src/chat/recipes/file-touch.ts b/client/cody-shared/src/chat/recipes/inline-touch.ts similarity index 95% rename from client/cody-shared/src/chat/recipes/file-touch.ts rename to client/cody-shared/src/chat/recipes/inline-touch.ts index 68e08b600465..efec10fc97b6 100644 --- a/client/cody-shared/src/chat/recipes/file-touch.ts +++ b/client/cody-shared/src/chat/recipes/inline-touch.ts @@ -20,8 +20,8 @@ import { Recipe, RecipeContext, RecipeID } from './recipe' /** ====================================================== * Recipe for Generating a New File ====================================================== **/ -export class FileTouch implements Recipe { - public id: RecipeID = 'file-touch' +export class InlineTouch implements Recipe { + public id: RecipeID = 'inline-touch' private workspacePath = vscode.workspace.workspaceFolders?.[0].uri constructor(private debug: (filterLabel: string, text: string, ...args: unknown[]) => void) {} @@ -43,7 +43,7 @@ export class FileTouch implements Recipe { // Create file path from selection.fileName and workspacePath const currentFilePath = `${this.workspacePath.fsPath}/${selection.fileName}` const currentDir = currentFilePath.replace(/\/[^/]+$/, '') - this.debug('FileTouch:currentDir', 'currentDir', currentDir) + this.debug('InlineTouch:currentDir', 'currentDir', currentDir) // Create new file name based on the user's input const newFileName = commandRegex.noTest.test(humanInput) @@ -60,7 +60,7 @@ export class FileTouch implements Recipe { // Create file if it doesn't exist workspaceEditor.createFile(fileUri, { ignoreIfExists: true }) await vscode.workspace.applyEdit(workspaceEditor) - this.debug('FileTouch:workspaceEditor', 'createFile', fileUri) + this.debug('InlineTouch:workspaceEditor', 'createFile', fileUri) const truncatedText = truncateText(humanInput, MAX_HUMAN_INPUT_TOKENS) const MAX_RECIPE_CONTENT_TOKENS = MAX_RECIPE_INPUT_TOKENS + MAX_RECIPE_SURROUNDING_TOKENS * 2 @@ -68,7 +68,7 @@ export class FileTouch implements Recipe { // Reconstruct Cody's prompt using user's context // Replace placeholders in reverse order to avoid collisions if a placeholder occurs in the input - const prompt = FileTouch.newFilePrompt + const prompt = InlineTouch.newFilePrompt const promptText = prompt .replace('{newFileName}', newFsPath) .replace('{humanInput}', truncatedText) @@ -88,7 +88,7 @@ export class FileTouch implements Recipe { return } await this.addContentToNewFile(workspaceEditor, fileUri, content) - this.debug('FileTouch:responseMultiplexer', 'BufferedBotResponseSubscriber', content) + this.debug('InlineTouch:responseMultiplexer', 'BufferedBotResponseSubscriber', content) }) ) @@ -168,11 +168,11 @@ export class FileTouch implements Recipe { const contextMessages: ContextMessage[] = [] // Add selected text and current file as context and create context messages from current directory const selectedContext = ChatQuestion.getEditorSelectionContext(selection) - const currentDirContext = await FileTouch.getEditorDirContext(currentDir) + const currentDirContext = await InlineTouch.getEditorDirContext(currentDir) contextMessages.push(...selectedContext, ...currentDirContext) // Create context messages from open tabs if (contextMessages.length < 10) { - contextMessages.push(...FileTouch.getEditorOpenTabsContext(currentDir)) + contextMessages.push(...InlineTouch.getEditorOpenTabsContext(currentDir)) } return contextMessages.slice(-10) } @@ -238,7 +238,7 @@ export class FileTouch implements Recipe { // Get display text for human private getHumanDisplayText(humanChatInput: string, fileName: string): string { - return '**✨Touch✨** ' + humanChatInput + FileTouch.displayPrompt + fileName + return '**✨Touch✨** ' + humanChatInput + InlineTouch.displayPrompt + fileName } private async getInstructionFromInput(): Promise { diff --git a/client/cody-shared/src/chat/recipes/recipe.ts b/client/cody-shared/src/chat/recipes/recipe.ts index 4b80c50cf9ca..e3feae46df94 100644 --- a/client/cody-shared/src/chat/recipes/recipe.ts +++ b/client/cody-shared/src/chat/recipes/recipe.ts @@ -18,7 +18,7 @@ export type RecipeID = | 'context-search' | 'explain-code-detailed' | 'explain-code-high-level' - | 'file-touch' + | 'inline-touch' | 'find-code-smells' | 'fixup' | 'generate-docstring' diff --git a/client/cody-shared/src/configuration.ts b/client/cody-shared/src/configuration.ts index 767e7aa03967..a79b2d7de128 100644 --- a/client/cody-shared/src/configuration.ts +++ b/client/cody-shared/src/configuration.ts @@ -11,7 +11,7 @@ export interface Configuration { customHeaders: Record autocomplete: boolean experimentalChatPredictions: boolean - experimentalInline: boolean + inlineChat: boolean experimentalGuardrails: boolean experimentalNonStop: boolean autocompleteAdvancedProvider: 'anthropic' | 'unstable-codegen' | 'unstable-huggingface' diff --git a/client/cody-shared/src/telemetry/EventLogger.ts b/client/cody-shared/src/telemetry/EventLogger.ts index 883458267d27..c80e2ef9b4dd 100644 --- a/client/cody-shared/src/telemetry/EventLogger.ts +++ b/client/cody-shared/src/telemetry/EventLogger.ts @@ -24,7 +24,7 @@ function getInlineFromConfig(config: vscode.WorkspaceConfiguration): boolean { if (!config) { return false } - return config.get('cody.experimental.inline', false) + return config.get('cody.inlineChat.enabled', false) } function getNonStopFromConfig(config: vscode.WorkspaceConfiguration): boolean { diff --git a/client/cody/CHANGELOG.md b/client/cody/CHANGELOG.md index 1dc5aedddd8c..792af781553b 100644 --- a/client/cody/CHANGELOG.md +++ b/client/cody/CHANGELOG.md @@ -39,10 +39,13 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi - Refactored authentication process. [pull/53434](https://github.com/sourcegraph/sourcegraph/pull/53434) - New sign-in and sign-out flow. [pull/53434](https://github.com/sourcegraph/sourcegraph/pull/53434) - Analytical logs are now displayed in the Output view. [pull/53870](https://github.com/sourcegraph/sourcegraph/pull/53870) -- Renamed Inline Assist to Inline Chat. [pull/53725](https://github.com/sourcegraph/sourcegraph/pull/53725) +- Inline Chat: Renamed Inline Assist to Inline Chat. [pull/53725](https://github.com/sourcegraph/sourcegraph/pull/53725) [pull/54315](https://github.com/sourcegraph/sourcegraph/pull/54315) - Chat: Link to the "Getting Started" guide directly from the first chat message instead of the external documentation website. [pull/54175](https://github.com/sourcegraph/sourcegraph/pull/54175) - Codebase status icons. [pull/54262](https://github.com/sourcegraph/sourcegraph/pull/54262) - Changed the keyboard shortcut for the file touch recipe to `ctrl+alt+/` to avoid conflicts. [pull/54275](https://github.com/sourcegraph/sourcegraph/pull/54275) +- Inline Chat: Do not change current focus when Inline Fixup is done. [pull/53980](https://github.com/sourcegraph/sourcegraph/pull/53980) +- Inline Chat: Replace Close CodeLens with Accept. [pull/53980](https://github.com/sourcegraph/sourcegraph/pull/53980) +- Inline Chat: Moved to Beta state. It is now enabled by default. [pull/54315](https://github.com/sourcegraph/sourcegraph/pull/54315) ## [0.2.5] diff --git a/client/cody/package.json b/client/cody/package.json index 4819d87c9620..11d77cd33447 100644 --- a/client/cody/package.json +++ b/client/cody/package.json @@ -110,7 +110,7 @@ { "id": "inline-assist", "title": "Inline Chat (Experimental)", - "description": "Chat with Cody without leaving your file. Click the + button next to any line number in a file to bring up Inline Chat.\n[Enable in Settings](command:cody.walkthrough.enableInlineAssist)", + "description": "Chat with Cody without leaving your file. Click the + button next to any line number in a file to bring up Inline Chat.\n[Enable in Settings](command:cody.walkthrough.enableInlineChat)", "media": { "markdown": "walkthroughs/inline-assist.md" } @@ -356,7 +356,7 @@ "title": "Show Explain" }, { - "command": "cody.walkthrough.enableInlineAssist", + "command": "cody.walkthrough.enableInlineChat", "category": "Cody Walkthrough", "title": "Show Inline Chat" }, @@ -364,14 +364,14 @@ "command": "cody.comment.add", "title": "Ask Cody", "category": "Cody Inline Chat", - "when": "cody.activated && cody.inline-assist.enabled", + "when": "cody.activated && config.cody.inlineChat.enabled", "enablement": "!commentIsEmpty" }, { "command": "cody.comment.delete", "title": "Remove Comment", "category": "Cody Inline Chat", - "when": "cody.activated && cody.inline-assist.enabled", + "when": "cody.activated && config.cody.inlineChat.enabled", "enablement": "!commentThreadIsEmpty", "icon": "$(trash)" }, @@ -379,7 +379,7 @@ "command": "cody.comment.load", "title": "Loading", "category": "Cody Inline Chat", - "when": "cody.activated && cody.inline-assist.enabled", + "when": "cody.activated && config.cody.inlineChat.enabled", "enablement": "!commentThreadIsEmpty", "icon": "$(sync~spin)" }, @@ -387,7 +387,7 @@ "command": "cody.inline.new", "title": "Start a new Inline Chat session (Ctrl+Shift+C)", "category": "Cody Inline Assist", - "when": "cody.activated && cody.inline-assist.enabled", + "when": "cody.activated && config.cody.inlineChat.enabled", "enablement": "!commentIsEmpty" }, { @@ -397,7 +397,7 @@ "enablement": "config.cody.experimental.guardrails && editorHasSelection" }, { - "command": "cody.recipe.file-touch", + "command": "cody.recipe.inline-touch", "category": "Cody", "title": "Touch" }, @@ -472,7 +472,7 @@ "when": "cody.activated && editorHasSelection && !editorReadonly" }, { - "command": "cody.recipe.file-touch", + "command": "cody.recipe.inline-touch", "key": "ctrl+alt+/", "mac": "cmd+alt+/", "when": "cody.activated && editorTextFocus && !editorReadonly" @@ -508,7 +508,7 @@ "when": "cody.activated && editorHasSelection" }, { - "command": "cody.recipe.file-touch", + "command": "cody.recipe.inline-touch", "when": "cody.activated && editorHasSelection" }, { @@ -605,7 +605,7 @@ "when": "false" }, { - "command": "cody.walkthrough.enableInlineAssist", + "command": "cody.walkthrough.enableInlineChat", "when": "false" } ], @@ -629,8 +629,8 @@ "when": "cody.activated" }, { - "command": "cody.recipe.file-touch", - "when": "cody.activated && cody.inline-assist.enabled" + "command": "cody.recipe.inline-touch", + "when": "cody.activated && config.cody.inlineChat.enabled" }, { "command": "cody.recipe.generate-unit-test", @@ -725,24 +725,24 @@ { "command": "cody.comment.add", "group": "inline", - "when": "cody.activated && commentController =~ /^cody-inline/ && cody.inline-assist.enabled" + "when": "cody.activated && commentController =~ /^cody-inline/ && config.cody.inlineChat.enabled" }, { "command": "cody.focus", "group": "inline", - "when": "!cody.activated && commentController =~ /^cody-inline/ && cody.inline-assist.enabled" + "when": "!cody.activated && commentController =~ /^cody-inline/ && config.cody.inlineChat.enabled" } ], "comments/commentThread/title": [ { "command": "cody.comment.delete", "group": "inline@1", - "when": "cody.activated && commentController =~ /^cody-inline/ && cody.replied && !commentThreadIsEmpty && cody.inline-assist.enabled" + "when": "cody.activated && commentController =~ /^cody-inline/ && cody.replied && !commentThreadIsEmpty && config.cody.inlineChat.enabled" }, { "command": "cody.comment.load", "group": "inline@2", - "when": "cody.activated && commentController =~ /^cody-inline/ && cody.reply.pending && cody.inline-assist.enabled" + "when": "cody.activated && commentController =~ /^cody-inline/ && cody.reply.pending && config.cody.inlineChat.enabled" } ], "view/item/context": [ @@ -819,18 +819,18 @@ "markdownDescription": "Enables inline code suggestions in your editor.", "default": true }, - "cody.experimental.chatPredictions": { + "cody.inlineChat.enabled": { "order": 6, + "title": "Cody Inline Chat", "type": "boolean", - "default": false, - "markdownDescription": "Adds suggestions of possible relevant messages in the chat window." + "markdownDescription": "Enables asking questions and requesting code changes directly from within the code editor. Use the + button next to any line of code to start an inline chat.", + "default": true }, - "cody.experimental.inline": { + "cody.experimental.chatPredictions": { "order": 7, - "title": "Cody Inline Chat", "type": "boolean", - "markdownDescription": "Enables asking questions and requesting code changes directly from within the code editor. Use the + button next to any line of code to start an inline chat.", - "default": false + "default": false, + "markdownDescription": "Adds suggestions of possible relevant messages in the chat window." }, "cody.experimental.guardrails": { "order": 8, diff --git a/client/cody/src/chat/recipes.ts b/client/cody/src/chat/recipes.ts index daf5edb6f04e..ba30afa26f71 100644 --- a/client/cody/src/chat/recipes.ts +++ b/client/cody/src/chat/recipes.ts @@ -2,7 +2,6 @@ import { ChatQuestion } from '@sourcegraph/cody-shared/src/chat/recipes/chat-que import { ContextSearch } from '@sourcegraph/cody-shared/src/chat/recipes/context-search' import { ExplainCodeDetailed } from '@sourcegraph/cody-shared/src/chat/recipes/explain-code-detailed' import { ExplainCodeHighLevel } from '@sourcegraph/cody-shared/src/chat/recipes/explain-code-high-level' -import { FileTouch } from '@sourcegraph/cody-shared/src/chat/recipes/file-touch' import { FindCodeSmells } from '@sourcegraph/cody-shared/src/chat/recipes/find-code-smells' import { Fixup } from '@sourcegraph/cody-shared/src/chat/recipes/fixup' import { GenerateDocstring } from '@sourcegraph/cody-shared/src/chat/recipes/generate-docstring' @@ -11,7 +10,8 @@ import { ReleaseNotes } from '@sourcegraph/cody-shared/src/chat/recipes/generate import { GenerateTest } from '@sourcegraph/cody-shared/src/chat/recipes/generate-test' import { GitHistory } from '@sourcegraph/cody-shared/src/chat/recipes/git-log' import { ImproveVariableNames } from '@sourcegraph/cody-shared/src/chat/recipes/improve-variable-names' -import { InlineAssist } from '@sourcegraph/cody-shared/src/chat/recipes/inline-chat' +import { InlineChat } from '@sourcegraph/cody-shared/src/chat/recipes/inline-chat' +import { InlineTouch } from '@sourcegraph/cody-shared/src/chat/recipes/inline-touch' import { NextQuestions } from '@sourcegraph/cody-shared/src/chat/recipes/next-questions' import { NonStop } from '@sourcegraph/cody-shared/src/chat/recipes/non-stop' import { OptimizeCode } from '@sourcegraph/cody-shared/src/chat/recipes/optimize-code' @@ -40,14 +40,14 @@ function init(): void { new ContextSearch(), new ExplainCodeDetailed(), new ExplainCodeHighLevel(), - new FileTouch(debug), new FindCodeSmells(), new Fixup(), new GenerateDocstring(), new GenerateTest(), new GitHistory(), new ImproveVariableNames(), - new InlineAssist(debug), + new InlineChat(debug), + new InlineTouch(debug), new NextQuestions(), new NonStop(), new OptimizeCode(), diff --git a/client/cody/src/configuration.test.ts b/client/cody/src/configuration.test.ts index 734a49061428..92635e770d98 100644 --- a/client/cody/src/configuration.test.ts +++ b/client/cody/src/configuration.test.ts @@ -15,7 +15,7 @@ describe('getConfiguration', () => { autocomplete: true, experimentalChatPredictions: false, experimentalGuardrails: false, - experimentalInline: false, + inlineChat: true, experimentalNonStop: false, customHeaders: {}, debugEnable: false, @@ -50,7 +50,7 @@ describe('getConfiguration', () => { return true case 'cody.experimental.guardrails': return true - case 'cody.experimental.inline': + case 'cody.inlineChat.enabled': return true case 'cody.experimental.nonStop': return true @@ -86,7 +86,7 @@ describe('getConfiguration', () => { autocomplete: false, experimentalChatPredictions: true, experimentalGuardrails: true, - experimentalInline: true, + inlineChat: true, experimentalNonStop: true, debugEnable: true, debugVerbose: true, diff --git a/client/cody/src/configuration.ts b/client/cody/src/configuration.ts index 3e499e1452ab..26f8c0e9aede 100644 --- a/client/cody/src/configuration.ts +++ b/client/cody/src/configuration.ts @@ -62,7 +62,7 @@ export function getConfiguration(config: ConfigGetter): Configuration { debugFilter: debugRegex, autocomplete: config.get(CONFIG_KEY.autocompleteEnabled, true), experimentalChatPredictions: config.get(CONFIG_KEY.experimentalChatPredictions, isTesting), - experimentalInline: config.get(CONFIG_KEY.experimentalInline, isTesting), + inlineChat: config.get(CONFIG_KEY.inlineChatEnabled, true), experimentalGuardrails: config.get(CONFIG_KEY.experimentalGuardrails, isTesting), experimentalNonStop: config.get(CONFIG_KEY.experimentalNonStop, isTesting), autocompleteAdvancedProvider, diff --git a/client/cody/src/editor/vscode-editor.ts b/client/cody/src/editor/vscode-editor.ts index 5206688b9482..0e3d252e0052 100644 --- a/client/cody/src/editor/vscode-editor.ts +++ b/client/cody/src/editor/vscode-editor.ts @@ -17,24 +17,7 @@ export class VSCodeEditor implements Editor { inline: InlineController fixups: FixupController } - ) { - vscode.workspace.onDidChangeConfiguration(e => { - const config = vscode.workspace.getConfiguration('cody') - const isTesting = process.env.CODY_TESTING === 'true' - if (e.affectsConfiguration('cody')) { - // Inline Chat - const enableInlineAssist = (config.get('experimental.inline') as boolean) || isTesting - const inlineController = this.controllers.inline - void vscode.commands.executeCommand('setContext', 'cody.inline-assist.enabled', enableInlineAssist) - inlineController.get().commentingRangeProvider = { - provideCommentingRanges: (document: vscode.TextDocument) => { - const lineCount = document.lineCount - return enableInlineAssist ? [new vscode.Range(0, 0, lineCount - 1, 0)] : [] - }, - } - } - }) - } + ) {} public get fileName(): string { return vscode.window.activeTextEditor?.document.fileName ?? '' diff --git a/client/cody/src/main.ts b/client/cody/src/main.ts index b88d9e9923c6..1ee7449290c0 100644 --- a/client/cody/src/main.ts +++ b/client/cody/src/main.ts @@ -92,7 +92,6 @@ const register = async ( await updateEventLogger(initialConfig, localStorage) // Controller for inline Chat const commentController = new InlineController(context.extensionPath) - disposables.push(commentController.get()) const fixup = new FixupController() disposables.push(fixup) @@ -226,7 +225,7 @@ const register = async ( vscode.commands.registerCommand('cody.recipe.improve-variable-names', () => executeRecipe('improve-variable-names') ), - vscode.commands.registerCommand('cody.recipe.file-touch', () => executeRecipe('file-touch', false)), + vscode.commands.registerCommand('cody.recipe.inline-touch', () => executeRecipe('inline-touch', false)), vscode.commands.registerCommand('cody.recipe.find-code-smells', () => executeRecipe('find-code-smells')), vscode.commands.registerCommand('cody.recipe.context-search', () => executeRecipe('context-search')), vscode.commands.registerCommand('cody.recipe.optimize-code', () => executeRecipe('optimize-code')), @@ -260,11 +259,11 @@ const register = async ( vscode.commands.registerCommand('cody.walkthrough.showChat', () => chatProvider.setWebviewView('chat')), vscode.commands.registerCommand('cody.walkthrough.showFixup', () => chatProvider.setWebviewView('recipes')), vscode.commands.registerCommand('cody.walkthrough.showExplain', () => chatProvider.setWebviewView('recipes')), - vscode.commands.registerCommand('cody.walkthrough.enableInlineAssist', async () => { - await workspaceConfig.update('cody.experimental.inline', true, vscode.ConfigurationTarget.Global) + vscode.commands.registerCommand('cody.walkthrough.enableInlineChat', async () => { + await workspaceConfig.update('cody.inlineChat', true, vscode.ConfigurationTarget.Global) // Open VSCode setting view. Provides visual confirmation that the setting is enabled. return vscode.commands.executeCommand('workbench.action.openSettings', { - query: 'cody.experimental.inline', + query: 'cody.inlineChat.enabled', openToSide: true, }) }) @@ -315,14 +314,8 @@ const register = async ( }) // Initiate inline chat when feature flag is on - if (initialConfig.experimentalInline) { - commentController.get().commentingRangeProvider = { - provideCommentingRanges: (document: vscode.TextDocument) => { - const lineCount = document.lineCount - return [new vscode.Range(0, 0, lineCount - 1, 0)] - }, - } - void vscode.commands.executeCommand('setContext', 'cody.inline-assist.enabled', true) + if (!initialConfig.inlineChat) { + commentController.dispose() } if (initialConfig.experimentalGuardrails) { diff --git a/client/cody/src/services/InlineController.ts b/client/cody/src/services/InlineController.ts index 23d7533e08d6..098cca4a5e01 100644 --- a/client/cody/src/services/InlineController.ts +++ b/client/cody/src/services/InlineController.ts @@ -27,7 +27,7 @@ export class InlineController { private readonly userIcon: vscode.Uri = getIconPath('user', this.extensionPath) private _disposables: vscode.Disposable[] = [] // Constroller State - private commentController: vscode.CommentController + private commentController: vscode.CommentController | null = null public thread: vscode.CommentThread | null = null // a thread is a comment private threads = new Map() private currentTaskId = '' @@ -40,9 +40,23 @@ export class InlineController { private codeLenses: Map = new Map() constructor(private extensionPath: string) { - this.commentController = vscode.comments.createCommentController(this.id, this.label) - this.commentController.options = this.options - + this.commentController = this.init() + this._disposables.push(this.commentController) + // Toggle Inline Chat on Config Change + vscode.workspace.onDidChangeConfiguration(e => { + const config = vscode.workspace.getConfiguration('cody') + if (e.affectsConfiguration('cody')) { + // Inline Chat + const enableInlineChat = config.get('inlineChat.enabled') as boolean + if (enableInlineChat) { + this.commentController = this.init() + return + } + this.commentController?.dispose() + this.commentController = null + this.dispose() + } + }) // Track last selection range in valid doc before an action is called vscode.window.onDidChangeTextEditorSelection(e => { if ( @@ -91,17 +105,34 @@ export class InlineController { vscode.commands.registerCommand('cody.inline.fix.undo', id => this.undo(id)) ) } - /** - * Getter to return instance + * Create comment controller and set options + */ + public init(): vscode.CommentController { + this.commentController?.dispose() + const commentController = vscode.comments.createCommentController(this.id, this.label) + commentController.options = this.options + commentController.commentingRangeProvider = { + provideCommentingRanges: (document: vscode.TextDocument) => { + const lineCount = document.lineCount + return [new vscode.Range(0, 0, lineCount - 1, 0)] + }, + } + return commentController + } + /** + * Getter to return comment controller */ - public get(): vscode.CommentController { + public get(): vscode.CommentController | null { return this.commentController } /** * Create a new thread (the first comment of a thread) */ public create(humanInput: string): vscode.CommentReply | null { + if (!this.commentController) { + return null + } const editor = vscode.window.activeTextEditor if (!editor || !humanInput || editor.document.uri.scheme !== 'file') { return null diff --git a/client/cody/src/services/StatusBar.ts b/client/cody/src/services/StatusBar.ts index e06ae962636b..c225124acf22 100644 --- a/client/cody/src/services/StatusBar.ts +++ b/client/cody/src/services/StatusBar.ts @@ -68,8 +68,8 @@ export function createStatusBar(): CodyStatusBar { 'Inline Chat', 'Beta', 'Enable chatting and editing with Cody, directly in your code', - 'cody.experimental.inline', - c => c.experimentalInline + 'cody.inlineChat.enabled', + c => c.inlineChat ), createFeatureToggle( diff --git a/client/cody/test/e2e/BUILD.bazel b/client/cody/test/e2e/BUILD.bazel index 40a2e01144e0..7f3ef8370190 100644 --- a/client/cody/test/e2e/BUILD.bazel +++ b/client/cody/test/e2e/BUILD.bazel @@ -14,7 +14,7 @@ ts_project( "helpers.ts", "history.test.ts", "inline-assist.test.ts", - "inline-assist-file-touch.test.ts", + "inline-assist-inline-touch.test.ts", "task-controller.test.ts", ], tsconfig = "//client/cody:tsconfig", diff --git a/client/cody/test/e2e/helpers.ts b/client/cody/test/e2e/helpers.ts index 92de800adc34..a2ee68fa3836 100644 --- a/client/cody/test/e2e/helpers.ts +++ b/client/cody/test/e2e/helpers.ts @@ -134,7 +134,6 @@ function escapeToPath(text: string): string { // Build a workspace settings file that enables the experimental inline mode export async function buildWorkSpaceSettings(workspaceDirectory: string): Promise { const settings = { - 'cody.experimental.inline': true, 'cody.serverEndpoint': 'http://localhost:49300', } // create a temporary directory with settings.json and add to the workspaceDirectory diff --git a/client/cody/test/e2e/inline-assist-file-touch.test.ts b/client/cody/test/e2e/inline-assist-inline-touch.test.ts similarity index 100% rename from client/cody/test/e2e/inline-assist-file-touch.test.ts rename to client/cody/test/e2e/inline-assist-inline-touch.test.ts