Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts
5221 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { localize } from '../../../../nls.js';
7
import { MenuId } from '../../../../platform/actions/common/actions.js';
8
import { Extensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';
9
import { ContextKeyExpr, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
10
import { Registry } from '../../../../platform/registry/common/platform.js';
11
import { diffInserted, diffRemoved, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputBackground, inputPlaceholderForeground, registerColor, transparent, widgetShadow } from '../../../../platform/theme/common/colorRegistry.js';
12
import { NOTEBOOK_IS_ACTIVE_EDITOR } from '../../notebook/common/notebookContextKeys.js';
13
14
// settings
15
16
export const enum InlineChatConfigKeys {
17
FinishOnType = 'inlineChat.finishOnType',
18
HoldToSpeech = 'inlineChat.holdToSpeech',
19
/** @deprecated do not read on client */
20
EnableV2 = 'inlineChat.enableV2',
21
notebookAgent = 'inlineChat.notebookAgent',
22
DefaultModel = 'inlineChat.defaultModel',
23
Affordance = 'inlineChat.affordance',
24
RenderMode = 'inlineChat.renderMode',
25
}
26
27
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
28
id: 'editor',
29
properties: {
30
[InlineChatConfigKeys.FinishOnType]: {
31
description: localize('finishOnType', "Whether to finish an inline chat session when typing outside of changed regions."),
32
default: false,
33
type: 'boolean'
34
},
35
[InlineChatConfigKeys.HoldToSpeech]: {
36
description: localize('holdToSpeech', "Whether holding the inline chat keybinding will automatically enable speech recognition."),
37
default: true,
38
type: 'boolean'
39
},
40
[InlineChatConfigKeys.EnableV2]: {
41
description: localize('enableV2', "Whether to use the next version of inline chat."),
42
default: false,
43
type: 'boolean',
44
tags: ['preview'],
45
experiment: {
46
mode: 'auto'
47
}
48
},
49
[InlineChatConfigKeys.notebookAgent]: {
50
markdownDescription: localize('notebookAgent', "Enable agent-like behavior for inline chat widget in notebooks."),
51
default: false,
52
type: 'boolean',
53
tags: ['experimental'],
54
experiment: {
55
mode: 'startup'
56
}
57
},
58
[InlineChatConfigKeys.Affordance]: {
59
description: localize('affordance', "Controls whether an inline chat affordance is shown when text is selected."),
60
default: 'off',
61
type: 'string',
62
enum: ['off', 'gutter', 'editor'],
63
enumDescriptions: [
64
localize('affordance.off', "No affordance is shown."),
65
localize('affordance.gutter', "Show an affordance in the gutter."),
66
localize('affordance.editor', "Show an affordance in the editor at the cursor position."),
67
],
68
experiment: {
69
mode: 'auto'
70
},
71
tags: ['experimental']
72
},
73
[InlineChatConfigKeys.RenderMode]: {
74
description: localize('renderMode', "Controls how inline chat is rendered."),
75
default: 'zone',
76
type: 'string',
77
enum: ['zone', 'hover'],
78
enumDescriptions: [
79
localize('renderMode.zone', "Render inline chat as a zone widget below the current line."),
80
localize('renderMode.hover', "Render inline chat as a hover overlay."),
81
],
82
experiment: {
83
mode: 'auto'
84
},
85
tags: ['experimental']
86
}
87
}
88
});
89
90
91
export const INLINE_CHAT_ID = 'interactiveEditor';
92
export const INTERACTIVE_EDITOR_ACCESSIBILITY_HELP_ID = 'interactiveEditorAccessiblityHelp';
93
94
// --- CONTEXT
95
96
export const enum InlineChatResponseType {
97
None = 'none',
98
Messages = 'messages',
99
MessagesAndEdits = 'messagesAndEdits'
100
}
101
102
export 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"));
103
export const CTX_INLINE_CHAT_HAS_AGENT2 = new RawContextKey<boolean>('inlineChatHasEditsAgent', false, localize('inlineChatHasEditsAgent', "Whether an agent for inline for interactive editors exists"));
104
export const CTX_INLINE_CHAT_HAS_NOTEBOOK_INLINE = new RawContextKey<boolean>('inlineChatHasNotebookInline', false, localize('inlineChatHasNotebookInline', "Whether an agent for notebook cells exists"));
105
export const CTX_INLINE_CHAT_HAS_NOTEBOOK_AGENT = new RawContextKey<boolean>('inlineChatHasNotebookAgent', false, localize('inlineChatHasNotebookAgent', "Whether an agent for notebook cells exists"));
106
export const CTX_INLINE_CHAT_VISIBLE = new RawContextKey<boolean>('inlineChatVisible', false, localize('inlineChatVisible', "Whether the interactive editor input is visible"));
107
export const CTX_INLINE_CHAT_FOCUSED = new RawContextKey<boolean>('inlineChatFocused', false, localize('inlineChatFocused', "Whether the interactive editor input is focused"));
108
export 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"));
109
export const CTX_INLINE_CHAT_RESPONSE_FOCUSED = new RawContextKey<boolean>('inlineChatResponseFocused', false, localize('inlineChatResponseFocused', "Whether the interactive widget's response is focused"));
110
export const CTX_INLINE_CHAT_EMPTY = new RawContextKey<boolean>('inlineChatEmpty', false, localize('inlineChatEmpty', "Whether the interactive editor input is empty"));
111
export 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"));
112
export 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"));
113
export 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"));
114
export const CTX_INLINE_CHAT_HAS_STASHED_SESSION = new RawContextKey<boolean>('inlineChatHasStashedSession', false, localize('inlineChatHasStashedSession', "Whether interactive editor has kept a session for quick restore"));
115
export const CTX_INLINE_CHAT_CHANGE_HAS_DIFF = new RawContextKey<boolean>('inlineChatChangeHasDiff', false, localize('inlineChatChangeHasDiff', "Whether the current change supports showing a diff"));
116
export const CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF = new RawContextKey<boolean>('inlineChatChangeShowsDiff', false, localize('inlineChatChangeShowsDiff', "Whether the current change showing a diff"));
117
export const CTX_INLINE_CHAT_REQUEST_IN_PROGRESS = new RawContextKey<boolean>('inlineChatRequestInProgress', false, localize('inlineChatRequestInProgress', "Whether an inline chat request is currently in progress"));
118
export 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"));
119
120
export const CTX_INLINE_CHAT_V1_ENABLED = ContextKeyExpr.or(
121
ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, CTX_INLINE_CHAT_HAS_NOTEBOOK_INLINE)
122
);
123
124
export const CTX_INLINE_CHAT_V2_ENABLED = ContextKeyExpr.or(
125
CTX_INLINE_CHAT_HAS_AGENT2,
126
ContextKeyExpr.and(NOTEBOOK_IS_ACTIVE_EDITOR, CTX_INLINE_CHAT_HAS_NOTEBOOK_AGENT)
127
);
128
129
export const CTX_HOVER_MODE = ContextKeyExpr.equals('config.inlineChat.renderMode', 'hover');
130
131
// --- (selected) action identifier
132
133
export const ACTION_START = 'inlineChat.start';
134
export const ACTION_ACCEPT_CHANGES = 'inlineChat.acceptChanges';
135
export const ACTION_DISCARD_CHANGES = 'inlineChat.discardHunkChange';
136
export const ACTION_REGENERATE_RESPONSE = 'inlineChat.regenerate';
137
export const ACTION_VIEW_IN_CHAT = 'inlineChat.viewInChat';
138
export const ACTION_TOGGLE_DIFF = 'inlineChat.toggleDiff';
139
export const ACTION_REPORT_ISSUE = 'inlineChat.reportIssue';
140
141
// --- menus
142
143
export const MENU_INLINE_CHAT_WIDGET_STATUS = MenuId.for('inlineChatWidget.status');
144
export const MENU_INLINE_CHAT_WIDGET_SECONDARY = MenuId.for('inlineChatWidget.secondary');
145
export const MENU_INLINE_CHAT_ZONE = MenuId.for('inlineChatWidget.changesZone');
146
147
export const MENU_INLINE_CHAT_SIDE = MenuId.for('inlineChatWidget.side');
148
149
// --- colors
150
151
152
export const inlineChatForeground = registerColor('inlineChat.foreground', editorWidgetForeground, localize('inlineChat.foreground', "Foreground color of the interactive editor widget"));
153
export const inlineChatBackground = registerColor('inlineChat.background', editorWidgetBackground, localize('inlineChat.background', "Background color of the interactive editor widget"));
154
export const inlineChatBorder = registerColor('inlineChat.border', editorWidgetBorder, localize('inlineChat.border', "Border color of the interactive editor widget"));
155
export const inlineChatShadow = registerColor('inlineChat.shadow', widgetShadow, localize('inlineChat.shadow', "Shadow color of the interactive editor widget"));
156
export const inlineChatInputBorder = registerColor('inlineChatInput.border', editorWidgetBorder, localize('inlineChatInput.border', "Border color of the interactive editor input"));
157
export const inlineChatInputFocusBorder = registerColor('inlineChatInput.focusBorder', focusBorder, localize('inlineChatInput.focusBorder', "Border color of the interactive editor input when focused"));
158
export const inlineChatInputPlaceholderForeground = registerColor('inlineChatInput.placeholderForeground', inputPlaceholderForeground, localize('inlineChatInput.placeholderForeground', "Foreground color of the interactive editor input placeholder"));
159
export const inlineChatInputBackground = registerColor('inlineChatInput.background', inputBackground, localize('inlineChatInput.background', "Background color of the interactive editor input"));
160
161
export const inlineChatDiffInserted = registerColor('inlineChatDiff.inserted', transparent(diffInserted, .5), localize('inlineChatDiff.inserted', "Background color of inserted text in the interactive editor input"));
162
export 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.'));
163
export 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.'));
164
165
export const inlineChatDiffRemoved = registerColor('inlineChatDiff.removed', transparent(diffRemoved, .5), localize('inlineChatDiff.removed', "Background color of removed text in the interactive editor input"));
166
export 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.'));
167
168