Path: blob/main/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts
5221 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize } from '../../../../nls.js';6import { MenuId } from '../../../../platform/actions/common/actions.js';7import { Extensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';8import { ContextKeyExpr, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';9import { Registry } from '../../../../platform/registry/common/platform.js';10import { diffInserted, diffRemoved, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputBackground, inputPlaceholderForeground, registerColor, transparent, widgetShadow } from '../../../../platform/theme/common/colorRegistry.js';11import { NOTEBOOK_IS_ACTIVE_EDITOR } from '../../notebook/common/notebookContextKeys.js';1213// settings1415export const enum InlineChatConfigKeys {16FinishOnType = 'inlineChat.finishOnType',17HoldToSpeech = 'inlineChat.holdToSpeech',18/** @deprecated do not read on client */19EnableV2 = 'inlineChat.enableV2',20notebookAgent = 'inlineChat.notebookAgent',21DefaultModel = 'inlineChat.defaultModel',22Affordance = 'inlineChat.affordance',23RenderMode = 'inlineChat.renderMode',24}2526Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({27id: 'editor',28properties: {29[InlineChatConfigKeys.FinishOnType]: {30description: localize('finishOnType', "Whether to finish an inline chat session when typing outside of changed regions."),31default: false,32type: 'boolean'33},34[InlineChatConfigKeys.HoldToSpeech]: {35description: localize('holdToSpeech', "Whether holding the inline chat keybinding will automatically enable speech recognition."),36default: true,37type: 'boolean'38},39[InlineChatConfigKeys.EnableV2]: {40description: localize('enableV2', "Whether to use the next version of inline chat."),41default: false,42type: 'boolean',43tags: ['preview'],44experiment: {45mode: 'auto'46}47},48[InlineChatConfigKeys.notebookAgent]: {49markdownDescription: localize('notebookAgent', "Enable agent-like behavior for inline chat widget in notebooks."),50default: false,51type: 'boolean',52tags: ['experimental'],53experiment: {54mode: 'startup'55}56},57[InlineChatConfigKeys.Affordance]: {58description: localize('affordance', "Controls whether an inline chat affordance is shown when text is selected."),59default: 'off',60type: 'string',61enum: ['off', 'gutter', 'editor'],62enumDescriptions: [63localize('affordance.off', "No affordance is shown."),64localize('affordance.gutter', "Show an affordance in the gutter."),65localize('affordance.editor', "Show an affordance in the editor at the cursor position."),66],67experiment: {68mode: 'auto'69},70tags: ['experimental']71},72[InlineChatConfigKeys.RenderMode]: {73description: localize('renderMode', "Controls how inline chat is rendered."),74default: 'zone',75type: 'string',76enum: ['zone', 'hover'],77enumDescriptions: [78localize('renderMode.zone', "Render inline chat as a zone widget below the current line."),79localize('renderMode.hover', "Render inline chat as a hover overlay."),80],81experiment: {82mode: 'auto'83},84tags: ['experimental']85}86}87});888990export const INLINE_CHAT_ID = 'interactiveEditor';91export const INTERACTIVE_EDITOR_ACCESSIBILITY_HELP_ID = 'interactiveEditorAccessiblityHelp';9293// --- CONTEXT9495export const enum InlineChatResponseType {96None = 'none',97Messages = 'messages',98MessagesAndEdits = 'messagesAndEdits'99}100101export const CTX_INLINE_CHAT_POSSIBLE = new RawContextKey<boolean>('inlineChatPossible', false, localize('inlineChatHasPossible', "Whether a provider for inline chat exists and whether an editor for inline chat is open"));102export const CTX_INLINE_CHAT_HAS_AGENT2 = new RawContextKey<boolean>('inlineChatHasEditsAgent', false, localize('inlineChatHasEditsAgent', "Whether an agent for inline for interactive editors exists"));103export const CTX_INLINE_CHAT_HAS_NOTEBOOK_INLINE = new RawContextKey<boolean>('inlineChatHasNotebookInline', false, localize('inlineChatHasNotebookInline', "Whether an agent for notebook cells exists"));104export const CTX_INLINE_CHAT_HAS_NOTEBOOK_AGENT = new RawContextKey<boolean>('inlineChatHasNotebookAgent', false, localize('inlineChatHasNotebookAgent', "Whether an agent for notebook cells exists"));105export const CTX_INLINE_CHAT_VISIBLE = new RawContextKey<boolean>('inlineChatVisible', false, localize('inlineChatVisible', "Whether the interactive editor input is visible"));106export const CTX_INLINE_CHAT_FOCUSED = new RawContextKey<boolean>('inlineChatFocused', false, localize('inlineChatFocused', "Whether the interactive editor input is focused"));107export const CTX_INLINE_CHAT_EDITING = new RawContextKey<boolean>('inlineChatEditing', true, localize('inlineChatEditing', "Whether the user is currently editing or generating code in the inline chat"));108export const CTX_INLINE_CHAT_RESPONSE_FOCUSED = new RawContextKey<boolean>('inlineChatResponseFocused', false, localize('inlineChatResponseFocused', "Whether the interactive widget's response is focused"));109export const CTX_INLINE_CHAT_EMPTY = new RawContextKey<boolean>('inlineChatEmpty', false, localize('inlineChatEmpty', "Whether the interactive editor input is empty"));110export const CTX_INLINE_CHAT_INNER_CURSOR_FIRST = new RawContextKey<boolean>('inlineChatInnerCursorFirst', false, localize('inlineChatInnerCursorFirst', "Whether the cursor of the iteractive editor input is on the first line"));111export const CTX_INLINE_CHAT_INNER_CURSOR_LAST = new RawContextKey<boolean>('inlineChatInnerCursorLast', false, localize('inlineChatInnerCursorLast', "Whether the cursor of the iteractive editor input is on the last line"));112export const CTX_INLINE_CHAT_OUTER_CURSOR_POSITION = new RawContextKey<'above' | 'below' | ''>('inlineChatOuterCursorPosition', '', localize('inlineChatOuterCursorPosition', "Whether the cursor of the outer editor is above or below the interactive editor input"));113export const CTX_INLINE_CHAT_HAS_STASHED_SESSION = new RawContextKey<boolean>('inlineChatHasStashedSession', false, localize('inlineChatHasStashedSession', "Whether interactive editor has kept a session for quick restore"));114export const CTX_INLINE_CHAT_CHANGE_HAS_DIFF = new RawContextKey<boolean>('inlineChatChangeHasDiff', false, localize('inlineChatChangeHasDiff', "Whether the current change supports showing a diff"));115export const CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF = new RawContextKey<boolean>('inlineChatChangeShowsDiff', false, localize('inlineChatChangeShowsDiff', "Whether the current change showing a diff"));116export const CTX_INLINE_CHAT_REQUEST_IN_PROGRESS = new RawContextKey<boolean>('inlineChatRequestInProgress', false, localize('inlineChatRequestInProgress', "Whether an inline chat request is currently in progress"));117export const CTX_INLINE_CHAT_RESPONSE_TYPE = new RawContextKey<InlineChatResponseType>('inlineChatResponseType', InlineChatResponseType.None, localize('inlineChatResponseTypes', "What type was the responses have been receieved, nothing yet, just messages, or messaged and local edits"));118119export const CTX_INLINE_CHAT_V1_ENABLED = ContextKeyExpr.or(120ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, CTX_INLINE_CHAT_HAS_NOTEBOOK_INLINE)121);122123export const CTX_INLINE_CHAT_V2_ENABLED = ContextKeyExpr.or(124CTX_INLINE_CHAT_HAS_AGENT2,125ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, CTX_INLINE_CHAT_HAS_NOTEBOOK_AGENT)126);127128export const CTX_HOVER_MODE = ContextKeyExpr.equals('config.inlineChat.renderMode', 'hover');129130// --- (selected) action identifier131132export const ACTION_START = 'inlineChat.start';133export const ACTION_ACCEPT_CHANGES = 'inlineChat.acceptChanges';134export const ACTION_DISCARD_CHANGES = 'inlineChat.discardHunkChange';135export const ACTION_REGENERATE_RESPONSE = 'inlineChat.regenerate';136export const ACTION_VIEW_IN_CHAT = 'inlineChat.viewInChat';137export const ACTION_TOGGLE_DIFF = 'inlineChat.toggleDiff';138export const ACTION_REPORT_ISSUE = 'inlineChat.reportIssue';139140// --- menus141142export const MENU_INLINE_CHAT_WIDGET_STATUS = MenuId.for('inlineChatWidget.status');143export const MENU_INLINE_CHAT_WIDGET_SECONDARY = MenuId.for('inlineChatWidget.secondary');144export const MENU_INLINE_CHAT_ZONE = MenuId.for('inlineChatWidget.changesZone');145146export const MENU_INLINE_CHAT_SIDE = MenuId.for('inlineChatWidget.side');147148// --- colors149150151export const inlineChatForeground = registerColor('inlineChat.foreground', editorWidgetForeground, localize('inlineChat.foreground', "Foreground color of the interactive editor widget"));152export const inlineChatBackground = registerColor('inlineChat.background', editorWidgetBackground, localize('inlineChat.background', "Background color of the interactive editor widget"));153export const inlineChatBorder = registerColor('inlineChat.border', editorWidgetBorder, localize('inlineChat.border', "Border color of the interactive editor widget"));154export const inlineChatShadow = registerColor('inlineChat.shadow', widgetShadow, localize('inlineChat.shadow', "Shadow color of the interactive editor widget"));155export const inlineChatInputBorder = registerColor('inlineChatInput.border', editorWidgetBorder, localize('inlineChatInput.border', "Border color of the interactive editor input"));156export const inlineChatInputFocusBorder = registerColor('inlineChatInput.focusBorder', focusBorder, localize('inlineChatInput.focusBorder', "Border color of the interactive editor input when focused"));157export const inlineChatInputPlaceholderForeground = registerColor('inlineChatInput.placeholderForeground', inputPlaceholderForeground, localize('inlineChatInput.placeholderForeground', "Foreground color of the interactive editor input placeholder"));158export const inlineChatInputBackground = registerColor('inlineChatInput.background', inputBackground, localize('inlineChatInput.background', "Background color of the interactive editor input"));159160export const inlineChatDiffInserted = registerColor('inlineChatDiff.inserted', transparent(diffInserted, .5), localize('inlineChatDiff.inserted', "Background color of inserted text in the interactive editor input"));161export const overviewRulerInlineChatDiffInserted = registerColor('editorOverviewRuler.inlineChatInserted', { dark: transparent(diffInserted, 0.6), light: transparent(diffInserted, 0.8), hcDark: transparent(diffInserted, 0.6), hcLight: transparent(diffInserted, 0.8) }, localize('editorOverviewRuler.inlineChatInserted', 'Overview ruler marker color for inline chat inserted content.'));162export const minimapInlineChatDiffInserted = registerColor('editorMinimap.inlineChatInserted', { dark: transparent(diffInserted, 0.6), light: transparent(diffInserted, 0.8), hcDark: transparent(diffInserted, 0.6), hcLight: transparent(diffInserted, 0.8) }, localize('editorMinimap.inlineChatInserted', 'Minimap marker color for inline chat inserted content.'));163164export const inlineChatDiffRemoved = registerColor('inlineChatDiff.removed', transparent(diffRemoved, .5), localize('inlineChatDiff.removed', "Background color of removed text in the interactive editor input"));165export const overviewRulerInlineChatDiffRemoved = registerColor('editorOverviewRuler.inlineChatRemoved', { dark: transparent(diffRemoved, 0.6), light: transparent(diffRemoved, 0.8), hcDark: transparent(diffRemoved, 0.6), hcLight: transparent(diffRemoved, 0.8) }, localize('editorOverviewRuler.inlineChatRemoved', 'Overview ruler marker color for inline chat removed content.'));166167168