@codingame/monaco-vscode-chat-service-override 5.3.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat.js +5 -7
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +160 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +17 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +15 -13
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +215 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +1 -9
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +6 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +15 -93
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +27 -106
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +5 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +6 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipantContributions.js +95 -51
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +94 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +64 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +2 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatContextAttachments.js +50 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputCompletions.js +370 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +19 -366
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +122 -63
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +12 -5
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelStats.js +6 -5
- package/vscode/src/vs/workbench/contrib/chat/common/{voiceChat.js → voiceChatService.js} +58 -21
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +15 -14
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +33 -32
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +6 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables.js +0 -26
- package/vscode/src/vs/workbench/contrib/chat/common/languageModels.js +0 -50
- package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl.js +0 -33
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
+
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
+
import { Range } from 'vscode/vscode/vs/editor/common/core/range';
|
|
4
|
+
import { getWordAtText } from 'vscode/vscode/vs/editor/common/core/wordHelper';
|
|
5
|
+
import { CompletionItemKind } from 'vscode/vscode/vs/editor/common/languages';
|
|
6
|
+
import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
|
|
7
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
8
|
+
import { Action2, registerAction2 } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
9
|
+
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
10
|
+
import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
11
|
+
import { SubmitAction } from 'vscode/vscode/vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
|
|
12
|
+
import { IChatWidgetService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat.service';
|
|
13
|
+
import { ChatInputPart } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatInputPart';
|
|
14
|
+
import { SelectAndInsertFileAction } from 'vscode/vscode/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables';
|
|
15
|
+
import { ChatAgentLocation, getFullyQualifiedId } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
16
|
+
import { IChatAgentService, IChatAgentNameService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents.service';
|
|
17
|
+
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestTextPart, chatSubcommandLeader, chatVariableLeader, ChatRequestVariablePart, chatAgentLeader } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
18
|
+
import { IChatSlashCommandService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatSlashCommands.service';
|
|
19
|
+
import { IChatVariablesService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatVariables.service';
|
|
20
|
+
import { LifecyclePhase } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
|
|
21
|
+
|
|
22
|
+
var BuiltinDynamicCompletions_1, VariableCompletions_1;
|
|
23
|
+
const _moduleId = "vs/workbench/contrib/chat/browser/contrib/chatInputCompletions";
|
|
24
|
+
let SlashCommandCompletions = class SlashCommandCompletions extends Disposable {
|
|
25
|
+
constructor(languageFeaturesService, chatWidgetService, chatSlashCommandService) {
|
|
26
|
+
super();
|
|
27
|
+
this.languageFeaturesService = languageFeaturesService;
|
|
28
|
+
this.chatWidgetService = chatWidgetService;
|
|
29
|
+
this.chatSlashCommandService = chatSlashCommandService;
|
|
30
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
31
|
+
_debugDisplayName: 'globalSlashCommands',
|
|
32
|
+
triggerCharacters: ['/'],
|
|
33
|
+
provideCompletionItems: async (model, position, _context, _token) => {
|
|
34
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
35
|
+
if (!widget || !widget.viewModel || (widget.location !== ChatAgentLocation.Panel && widget.location !== ChatAgentLocation.Notebook) ) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const range = computeCompletionRanges(model, position, /\/\w*/g);
|
|
39
|
+
if (!range) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const parsedRequest = widget.parsedInput.parts;
|
|
43
|
+
const usedAgent = parsedRequest.find(p => p instanceof ChatRequestAgentPart);
|
|
44
|
+
if (usedAgent) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const slashCommands = this.chatSlashCommandService.getCommands();
|
|
48
|
+
if (!slashCommands) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
suggestions: ( (slashCommands.map((c, i) => {
|
|
53
|
+
const withSlash = `/${c.command}`;
|
|
54
|
+
return {
|
|
55
|
+
label: withSlash,
|
|
56
|
+
insertText: c.executeImmediately ? '' : `${withSlash} `,
|
|
57
|
+
detail: c.detail,
|
|
58
|
+
range: ( (new Range(1, 1, 1, 1))),
|
|
59
|
+
sortText: c.sortText ?? 'a'.repeat(i + 1),
|
|
60
|
+
kind: CompletionItemKind.Text,
|
|
61
|
+
command: c.executeImmediately ? { id: SubmitAction.ID, title: withSlash, arguments: [{ widget, inputValue: `${withSlash} ` }] } : undefined,
|
|
62
|
+
};
|
|
63
|
+
})))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
SlashCommandCompletions = ( (__decorate([
|
|
70
|
+
( (__param(0, ILanguageFeaturesService))),
|
|
71
|
+
( (__param(1, IChatWidgetService))),
|
|
72
|
+
( (__param(2, IChatSlashCommandService)))
|
|
73
|
+
], SlashCommandCompletions)));
|
|
74
|
+
( (Registry.as(Extensions.Workbench))).registerWorkbenchContribution(SlashCommandCompletions, LifecyclePhase.Eventually);
|
|
75
|
+
let AgentCompletions = class AgentCompletions extends Disposable {
|
|
76
|
+
constructor(languageFeaturesService, chatWidgetService, chatAgentService, chatAgentNameService) {
|
|
77
|
+
super();
|
|
78
|
+
this.languageFeaturesService = languageFeaturesService;
|
|
79
|
+
this.chatWidgetService = chatWidgetService;
|
|
80
|
+
this.chatAgentService = chatAgentService;
|
|
81
|
+
this.chatAgentNameService = chatAgentNameService;
|
|
82
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
83
|
+
_debugDisplayName: 'chatAgent',
|
|
84
|
+
triggerCharacters: ['@'],
|
|
85
|
+
provideCompletionItems: async (model, position, _context, _token) => {
|
|
86
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
87
|
+
if (!widget || !widget.viewModel || (widget.location !== ChatAgentLocation.Panel && widget.location !== ChatAgentLocation.Notebook) ) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const parsedRequest = widget.parsedInput.parts;
|
|
91
|
+
const usedAgent = parsedRequest.find(p => p instanceof ChatRequestAgentPart);
|
|
92
|
+
if (usedAgent && !Range.containsPosition(usedAgent.editorRange, position)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const range = computeCompletionRanges(model, position, /@\w*/g);
|
|
96
|
+
if (!range) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const agents = this.chatAgentService.getAgents()
|
|
100
|
+
.filter(a => !a.isDefault)
|
|
101
|
+
.filter(a => a.locations.includes(widget.location));
|
|
102
|
+
return {
|
|
103
|
+
suggestions: ( (agents.map((agent, i) => {
|
|
104
|
+
const { label: agentLabel, isDupe } = getAgentCompletionDetails(agent, agents, this.chatAgentNameService);
|
|
105
|
+
return {
|
|
106
|
+
label: isDupe ?
|
|
107
|
+
{ label: agentLabel, description: agent.description, detail: ` (${agent.publisherDisplayName})` } :
|
|
108
|
+
agentLabel,
|
|
109
|
+
insertText: `${agentLabel} `,
|
|
110
|
+
detail: agent.description,
|
|
111
|
+
range: ( (new Range(1, 1, 1, 1))),
|
|
112
|
+
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent: agent, widget }] },
|
|
113
|
+
kind: CompletionItemKind.Text,
|
|
114
|
+
};
|
|
115
|
+
})))
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
120
|
+
_debugDisplayName: 'chatAgentSubcommand',
|
|
121
|
+
triggerCharacters: ['/'],
|
|
122
|
+
provideCompletionItems: async (model, position, _context, token) => {
|
|
123
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
124
|
+
if (!widget || !widget.viewModel || widget.location !== ChatAgentLocation.Panel ) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const range = computeCompletionRanges(model, position, /\/\w*/g);
|
|
128
|
+
if (!range) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const parsedRequest = widget.parsedInput.parts;
|
|
132
|
+
const usedAgentIdx = parsedRequest.findIndex((p) => p instanceof ChatRequestAgentPart);
|
|
133
|
+
if (usedAgentIdx < 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const usedSubcommand = parsedRequest.find(p => p instanceof ChatRequestAgentSubcommandPart);
|
|
137
|
+
if (usedSubcommand) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
for (const partAfterAgent of parsedRequest.slice(usedAgentIdx + 1)) {
|
|
141
|
+
if (!(partAfterAgent instanceof ChatRequestTextPart) || !partAfterAgent.text.trim().match(/^(\/\w*)?$/)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const usedAgent = parsedRequest[usedAgentIdx];
|
|
146
|
+
return {
|
|
147
|
+
suggestions: ( (usedAgent.agent.slashCommands.map((c, i) => {
|
|
148
|
+
const withSlash = `/${c.name}`;
|
|
149
|
+
return {
|
|
150
|
+
label: withSlash,
|
|
151
|
+
insertText: `${withSlash} `,
|
|
152
|
+
detail: c.description,
|
|
153
|
+
range,
|
|
154
|
+
kind: CompletionItemKind.Text,
|
|
155
|
+
};
|
|
156
|
+
})))
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
161
|
+
_debugDisplayName: 'chatAgentAndSubcommand',
|
|
162
|
+
triggerCharacters: ['/'],
|
|
163
|
+
provideCompletionItems: async (model, position, _context, token) => {
|
|
164
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
165
|
+
const viewModel = widget?.viewModel;
|
|
166
|
+
if (!widget || !viewModel || widget.location !== ChatAgentLocation.Panel ) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const range = computeCompletionRanges(model, position, /\/\w*/g);
|
|
170
|
+
if (!range) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const agents = this.chatAgentService.getAgents()
|
|
174
|
+
.filter(a => a.locations.includes(widget.location));
|
|
175
|
+
const getFilterText = (agent, command) => {
|
|
176
|
+
const dummyPrefix = agent.id === 'github.copilot.terminal' ? `0000` : ``;
|
|
177
|
+
return `${chatSubcommandLeader}${dummyPrefix}${agent.name}.${command}`;
|
|
178
|
+
};
|
|
179
|
+
const justAgents = ( (agents
|
|
180
|
+
.filter(a => !a.isDefault)
|
|
181
|
+
.map(agent => {
|
|
182
|
+
const { label: agentLabel, isDupe } = getAgentCompletionDetails(agent, agents, this.chatAgentNameService);
|
|
183
|
+
const detail = agent.description;
|
|
184
|
+
return {
|
|
185
|
+
label: isDupe ?
|
|
186
|
+
{ label: agentLabel, description: agent.description, detail: ` (${agent.publisherDisplayName})` } :
|
|
187
|
+
agentLabel,
|
|
188
|
+
detail,
|
|
189
|
+
filterText: `${chatSubcommandLeader}${agent.name}`,
|
|
190
|
+
insertText: `${agentLabel} `,
|
|
191
|
+
range: ( (new Range(1, 1, 1, 1))),
|
|
192
|
+
kind: CompletionItemKind.Text,
|
|
193
|
+
sortText: `${chatSubcommandLeader}${agent.name}`,
|
|
194
|
+
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget }] },
|
|
195
|
+
};
|
|
196
|
+
})));
|
|
197
|
+
return {
|
|
198
|
+
suggestions: justAgents.concat(agents.flatMap(agent => ( (agent.slashCommands.map((c, i) => {
|
|
199
|
+
const { label: agentLabel, isDupe } = getAgentCompletionDetails(agent, agents, this.chatAgentNameService);
|
|
200
|
+
const withSlash = `${chatSubcommandLeader}${c.name}`;
|
|
201
|
+
return {
|
|
202
|
+
label: { label: withSlash, description: agentLabel, detail: isDupe ? ` (${agent.publisherDisplayName})` : undefined },
|
|
203
|
+
filterText: getFilterText(agent, c.name),
|
|
204
|
+
commitCharacters: [' '],
|
|
205
|
+
insertText: `${agentLabel} ${withSlash} `,
|
|
206
|
+
detail: `(${agentLabel}) ${c.description ?? ''}`,
|
|
207
|
+
range: ( (new Range(1, 1, 1, 1))),
|
|
208
|
+
kind: CompletionItemKind.Text,
|
|
209
|
+
sortText: `${chatSubcommandLeader}${agent.name}${c.name}`,
|
|
210
|
+
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget }] },
|
|
211
|
+
};
|
|
212
|
+
})))))
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
AgentCompletions = ( (__decorate([
|
|
219
|
+
( (__param(0, ILanguageFeaturesService))),
|
|
220
|
+
( (__param(1, IChatWidgetService))),
|
|
221
|
+
( (__param(2, IChatAgentService))),
|
|
222
|
+
( (__param(3, IChatAgentNameService)))
|
|
223
|
+
], AgentCompletions)));
|
|
224
|
+
( (Registry.as(Extensions.Workbench))).registerWorkbenchContribution(AgentCompletions, LifecyclePhase.Eventually);
|
|
225
|
+
class AssignSelectedAgentAction extends Action2 {
|
|
226
|
+
static { this.ID = 'workbench.action.chat.assignSelectedAgent'; }
|
|
227
|
+
constructor() {
|
|
228
|
+
super({
|
|
229
|
+
id: AssignSelectedAgentAction.ID,
|
|
230
|
+
title: ''
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async run(accessor, ...args) {
|
|
234
|
+
const arg = args[0];
|
|
235
|
+
if (!arg || !arg.widget || !arg.agent) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
arg.widget.lastSelectedAgent = arg.agent;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
registerAction2(AssignSelectedAgentAction);
|
|
242
|
+
let BuiltinDynamicCompletions = class BuiltinDynamicCompletions extends Disposable {
|
|
243
|
+
static { BuiltinDynamicCompletions_1 = this; }
|
|
244
|
+
static { this.VariableNameDef = ( (new RegExp(`${chatVariableLeader}\\w*`, 'g'))); }
|
|
245
|
+
constructor(languageFeaturesService, chatWidgetService) {
|
|
246
|
+
super();
|
|
247
|
+
this.languageFeaturesService = languageFeaturesService;
|
|
248
|
+
this.chatWidgetService = chatWidgetService;
|
|
249
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
250
|
+
_debugDisplayName: 'chatDynamicCompletions',
|
|
251
|
+
triggerCharacters: [chatVariableLeader],
|
|
252
|
+
provideCompletionItems: async (model, position, _context, _token) => {
|
|
253
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
254
|
+
if (!widget || !widget.supportsFileReferences || widget.location !== ChatAgentLocation.Panel ) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
const range = computeCompletionRanges(model, position, BuiltinDynamicCompletions_1.VariableNameDef);
|
|
258
|
+
if (!range) {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
const afterRange = ( (new Range(
|
|
262
|
+
position.lineNumber,
|
|
263
|
+
range.replace.startColumn,
|
|
264
|
+
position.lineNumber,
|
|
265
|
+
range.replace.startColumn + '#file:'.length
|
|
266
|
+
)));
|
|
267
|
+
return {
|
|
268
|
+
suggestions: [
|
|
269
|
+
{
|
|
270
|
+
label: `${chatVariableLeader}file`,
|
|
271
|
+
insertText: `${chatVariableLeader}file:`,
|
|
272
|
+
detail: ( localizeWithPath(_moduleId, 0, "Pick a file")),
|
|
273
|
+
range,
|
|
274
|
+
kind: CompletionItemKind.Text,
|
|
275
|
+
command: { id: SelectAndInsertFileAction.ID, title: SelectAndInsertFileAction.ID, arguments: [{ widget, range: afterRange }] },
|
|
276
|
+
sortText: 'z'
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
BuiltinDynamicCompletions = BuiltinDynamicCompletions_1 = ( (__decorate([
|
|
285
|
+
( (__param(0, ILanguageFeaturesService))),
|
|
286
|
+
( (__param(1, IChatWidgetService)))
|
|
287
|
+
], BuiltinDynamicCompletions)));
|
|
288
|
+
( (Registry.as(Extensions.Workbench))).registerWorkbenchContribution(BuiltinDynamicCompletions, LifecyclePhase.Eventually);
|
|
289
|
+
function computeCompletionRanges(model, position, reg) {
|
|
290
|
+
const varWord = getWordAtText(position.column, reg, model.getLineContent(position.lineNumber), 0);
|
|
291
|
+
if (!varWord && model.getWordUntilPosition(position).word) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
let insert;
|
|
295
|
+
let replace;
|
|
296
|
+
if (!varWord) {
|
|
297
|
+
insert = replace = Range.fromPositions(position);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
insert = ( (new Range(
|
|
301
|
+
position.lineNumber,
|
|
302
|
+
varWord.startColumn,
|
|
303
|
+
position.lineNumber,
|
|
304
|
+
position.column
|
|
305
|
+
)));
|
|
306
|
+
replace = ( (new Range(
|
|
307
|
+
position.lineNumber,
|
|
308
|
+
varWord.startColumn,
|
|
309
|
+
position.lineNumber,
|
|
310
|
+
varWord.endColumn
|
|
311
|
+
)));
|
|
312
|
+
}
|
|
313
|
+
return { insert, replace, varWord };
|
|
314
|
+
}
|
|
315
|
+
let VariableCompletions = class VariableCompletions extends Disposable {
|
|
316
|
+
static { VariableCompletions_1 = this; }
|
|
317
|
+
static { this.VariableNameDef = ( (new RegExp(`${chatVariableLeader}\\w*`, 'g'))); }
|
|
318
|
+
constructor(languageFeaturesService, chatWidgetService, chatVariablesService) {
|
|
319
|
+
super();
|
|
320
|
+
this.languageFeaturesService = languageFeaturesService;
|
|
321
|
+
this.chatWidgetService = chatWidgetService;
|
|
322
|
+
this.chatVariablesService = chatVariablesService;
|
|
323
|
+
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
|
|
324
|
+
_debugDisplayName: 'chatVariables',
|
|
325
|
+
triggerCharacters: [chatVariableLeader],
|
|
326
|
+
provideCompletionItems: async (model, position, _context, _token) => {
|
|
327
|
+
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
|
|
328
|
+
if (!widget || widget.location !== ChatAgentLocation.Panel ) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
const range = computeCompletionRanges(model, position, VariableCompletions_1.VariableNameDef);
|
|
332
|
+
if (!range) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const usedAgent = widget.parsedInput.parts.find(p => p instanceof ChatRequestAgentPart);
|
|
336
|
+
const slowSupported = usedAgent ? usedAgent.agent.metadata.supportsSlowVariables : true;
|
|
337
|
+
const usedVariables = widget.parsedInput.parts.filter((p) => p instanceof ChatRequestVariablePart);
|
|
338
|
+
const variableItems = ( (Array.from(this.chatVariablesService.getVariables())
|
|
339
|
+
.filter(v => !( (usedVariables.some(usedVar => usedVar.variableName === v.name))))
|
|
340
|
+
.filter(v => !v.isSlow || slowSupported)
|
|
341
|
+
.map((v) => {
|
|
342
|
+
const withLeader = `${chatVariableLeader}${v.name}`;
|
|
343
|
+
return {
|
|
344
|
+
label: withLeader,
|
|
345
|
+
range,
|
|
346
|
+
insertText: withLeader + ' ',
|
|
347
|
+
detail: v.description,
|
|
348
|
+
kind: CompletionItemKind.Text,
|
|
349
|
+
sortText: 'z'
|
|
350
|
+
};
|
|
351
|
+
})));
|
|
352
|
+
return {
|
|
353
|
+
suggestions: variableItems
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
VariableCompletions = VariableCompletions_1 = ( (__decorate([
|
|
360
|
+
( (__param(0, ILanguageFeaturesService))),
|
|
361
|
+
( (__param(1, IChatWidgetService))),
|
|
362
|
+
( (__param(2, IChatVariablesService)))
|
|
363
|
+
], VariableCompletions)));
|
|
364
|
+
( (Registry.as(Extensions.Workbench))).registerWorkbenchContribution(VariableCompletions, LifecyclePhase.Eventually);
|
|
365
|
+
function getAgentCompletionDetails(agent, otherAgents, chatAgentNameService) {
|
|
366
|
+
const isAllowed = chatAgentNameService.getAgentNameRestriction(agent);
|
|
367
|
+
const agentLabel = `${chatAgentLeader}${isAllowed ? agent.name : getFullyQualifiedId(agent)}`;
|
|
368
|
+
const isDupe = isAllowed && !!otherAgents.find(other => other.name === agent.name && other.id !== agent.id);
|
|
369
|
+
return { label: agentLabel, isDupe };
|
|
370
|
+
}
|