@codingame/monaco-vscode-xterm-addons-common 25.1.2 → 26.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.
Files changed (18) hide show
  1. package/package.json +10 -10
  2. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContext.js +58 -114
  3. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables.d.ts +42 -0
  4. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables.js +209 -0
  5. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/attachInstructionsAction.js +18 -16
  6. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/newPromptFileActions.d.ts +1 -0
  7. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/newPromptFileActions.js +151 -70
  8. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptName.js +27 -25
  9. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/askForPromptSourceFolder.js +67 -53
  10. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/promptFilePickers.d.ts +4 -1
  11. package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/pickers/promptFilePickers.js +188 -116
  12. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/editor/chatPasteProviders.js +106 -71
  13. package/vscode/src/vs/workbench/contrib/terminal/browser/terminalUri.js +6 -3
  14. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.js +204 -140
  15. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/markNavigationAddon.js +77 -82
  16. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermAddonImporter.js +24 -24
  17. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.d.ts +4 -1
  18. package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.js +262 -162
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-xterm-addons-common",
3
- "version": "25.1.2",
3
+ "version": "26.0.1",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - common package depending on xterm addons",
6
6
  "keywords": [],
@@ -15,15 +15,15 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-api": "25.1.2",
19
- "@xterm/addon-clipboard": "0.3.0-beta.97",
20
- "@xterm/addon-image": "0.10.0-beta.97",
21
- "@xterm/addon-ligatures": "0.11.0-beta.97",
22
- "@xterm/addon-progress": "0.3.0-beta.97",
23
- "@xterm/addon-search": "0.17.0-beta.97",
24
- "@xterm/addon-serialize": "0.15.0-beta.97",
25
- "@xterm/addon-unicode11": "0.10.0-beta.97",
26
- "@xterm/addon-webgl": "0.20.0-beta.104"
18
+ "@codingame/monaco-vscode-api": "26.0.1",
19
+ "@xterm/addon-clipboard": "0.3.0-beta.147",
20
+ "@xterm/addon-image": "0.10.0-beta.147",
21
+ "@xterm/addon-ligatures": "0.11.0-beta.147",
22
+ "@xterm/addon-progress": "0.3.0-beta.147",
23
+ "@xterm/addon-search": "0.17.0-beta.147",
24
+ "@xterm/addon-serialize": "0.15.0-beta.147",
25
+ "@xterm/addon-unicode11": "0.10.0-beta.147",
26
+ "@xterm/addon-webgl": "0.20.0-beta.146"
27
27
  },
28
28
  "exports": {
29
29
  ".": {
@@ -1,10 +1,8 @@
1
1
 
2
2
  import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
- import { CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
4
3
  import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
5
4
  import { Disposable, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
6
5
  import { isElectron } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
7
- import { dirname } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
8
6
  import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
9
7
  import { IClipboardService } from '@codingame/monaco-vscode-api/vscode/vs/platform/clipboard/common/clipboardService.service';
10
8
  import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
@@ -17,9 +15,8 @@ import { UntitledTextEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/
17
15
  import { FileEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/files/browser/editors/fileEditorInput';
18
16
  import { NotebookEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookEditorInput';
19
17
  import { IChatContextPickService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/attachments/chatContextPickService.service';
20
- import { IChatEditingService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/editing/chatEditingService.service';
21
- import { toToolSetVariableEntry, toToolVariableEntry, OmittedState } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/attachments/chatVariableEntries';
22
- import { ToolSet, ToolDataSource } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/tools/languageModelToolsService';
18
+ import { toToolSetVariableEntry, toToolVariableEntry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/attachments/chatVariableEntries';
19
+ import { isToolSet, ToolDataSource } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/tools/languageModelToolsService';
23
20
  import { isImage } from '../widget/input/editor/chatPasteProviders.js';
24
21
  import { convertBufferToScreenshotVariable } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/attachments/chatScreenshotContext';
25
22
  import { ChatInstructionsPickerPick } from '../promptSyntax/attachInstructionsAction.js';
@@ -28,25 +25,33 @@ import { TerminalCapability } from '@codingame/monaco-vscode-api/vscode/vs/platf
28
25
  import { imageToHash } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/chatImageUtils';
29
26
 
30
27
  let ChatContextContributions = class ChatContextContributions extends Disposable {
31
- static { this.ID = 'chat.contextContributions'; }
28
+ static {
29
+ this.ID = "chat.contextContributions";
30
+ }
32
31
  constructor(instantiationService, contextPickService) {
33
32
  super();
34
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(ToolsContextPickerPick)));
35
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(ChatInstructionsPickerPick)));
36
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(OpenEditorContextValuePick)));
37
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(RelatedFilesContextPickerPick)));
38
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(ClipboardImageContextValuePick)));
39
- this._store.add(contextPickService.registerChatContextItem(instantiationService.createInstance(ScreenshotContextValuePick)));
33
+ this._store.add(
34
+ contextPickService.registerChatContextItem(instantiationService.createInstance(ToolsContextPickerPick))
35
+ );
36
+ this._store.add(
37
+ contextPickService.registerChatContextItem(instantiationService.createInstance(ChatInstructionsPickerPick))
38
+ );
39
+ this._store.add(
40
+ contextPickService.registerChatContextItem(instantiationService.createInstance(OpenEditorContextValuePick))
41
+ );
42
+ this._store.add(
43
+ contextPickService.registerChatContextItem(instantiationService.createInstance(ClipboardImageContextValuePick))
44
+ );
45
+ this._store.add(
46
+ contextPickService.registerChatContextItem(instantiationService.createInstance(ScreenshotContextValuePick))
47
+ );
40
48
  }
41
49
  };
42
- ChatContextContributions = ( __decorate([
43
- ( __param(0, IInstantiationService)),
44
- ( __param(1, IChatContextPickService))
45
- ], ChatContextContributions));
50
+ ChatContextContributions = ( __decorate([( __param(0, IInstantiationService)), ( __param(1, IChatContextPickService))], ChatContextContributions));
46
51
  class ToolsContextPickerPick {
47
52
  constructor() {
48
- this.type = 'pickerPick';
49
- this.label = ( localize(4707, 'Tools...'));
53
+ this.type = "pickerPick";
54
+ this.label = ( localize(4719, "Tools..."));
50
55
  this.icon = Codicon.tools;
51
56
  this.ordinal = -500;
52
57
  }
@@ -57,15 +62,14 @@ class ToolsContextPickerPick {
57
62
  const items = [];
58
63
  for (const [entry, enabled] of widget.input.selectedToolsModel.entriesMap.get()) {
59
64
  if (enabled) {
60
- if (entry instanceof ToolSet) {
65
+ if (isToolSet(entry)) {
61
66
  items.push({
62
67
  toolInfo: ToolDataSource.classify(entry.source),
63
68
  label: entry.referenceName,
64
69
  description: entry.description,
65
70
  asAttachment: () => toToolSetVariableEntry(entry)
66
71
  });
67
- }
68
- else {
72
+ } else {
69
73
  items.push({
70
74
  toolInfo: ToolDataSource.classify(entry.source),
71
75
  label: entry.toolReferenceName ?? entry.displayName,
@@ -89,13 +93,16 @@ class ToolsContextPickerPick {
89
93
  const picks = [];
90
94
  for (const item of items) {
91
95
  if (lastGroupLabel !== item.toolInfo.label) {
92
- picks.push({ type: 'separator', label: item.toolInfo.label });
96
+ picks.push({
97
+ type: "separator",
98
+ label: item.toolInfo.label
99
+ });
93
100
  lastGroupLabel = item.toolInfo.label;
94
101
  }
95
102
  picks.push(item);
96
103
  }
97
104
  return {
98
- placeholder: ( localize(4708, 'Select a tool')),
105
+ placeholder: ( localize(4720, "Select a tool")),
99
106
  picks: Promise.resolve(picks)
100
107
  };
101
108
  }
@@ -104,13 +111,15 @@ let OpenEditorContextValuePick = class OpenEditorContextValuePick {
104
111
  constructor(_editorService, _labelService) {
105
112
  this._editorService = _editorService;
106
113
  this._labelService = _labelService;
107
- this.type = 'valuePick';
108
- this.label = ( localize(4709, 'Open Editors'));
114
+ this.type = "valuePick";
115
+ this.label = ( localize(4721, "Open Editors"));
109
116
  this.icon = Codicon.file;
110
117
  this.ordinal = 800;
111
118
  }
112
119
  isEnabled() {
113
- return this._editorService.editors.filter(e => e instanceof FileEditorInput || e instanceof DiffEditorInput || e instanceof UntitledTextEditorInput).length > 0;
120
+ return this._editorService.editors.filter(
121
+ e => e instanceof FileEditorInput || e instanceof DiffEditorInput || e instanceof UntitledTextEditorInput
122
+ ).length > 0;
114
123
  }
115
124
  async asAttachment() {
116
125
  const result = [];
@@ -118,92 +127,35 @@ let OpenEditorContextValuePick = class OpenEditorContextValuePick {
118
127
  if (!(editor instanceof FileEditorInput || editor instanceof DiffEditorInput || editor instanceof UntitledTextEditorInput || editor instanceof NotebookEditorInput)) {
119
128
  continue;
120
129
  }
121
- const uri = EditorResourceAccessor.getOriginalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY });
130
+ const uri = EditorResourceAccessor.getOriginalUri(editor, {
131
+ supportSideBySide: SideBySideEditor.PRIMARY
132
+ });
122
133
  if (!uri) {
123
134
  continue;
124
135
  }
125
136
  result.push({
126
- kind: 'file',
137
+ kind: "file",
127
138
  id: ( uri.toString()),
128
139
  value: uri,
129
- name: this._labelService.getUriBasenameLabel(uri),
140
+ name: this._labelService.getUriBasenameLabel(uri)
130
141
  });
131
142
  }
132
143
  return result;
133
144
  }
134
145
  };
135
- OpenEditorContextValuePick = ( __decorate([
136
- ( __param(0, IEditorService)),
137
- ( __param(1, ILabelService))
138
- ], OpenEditorContextValuePick));
139
- let RelatedFilesContextPickerPick = class RelatedFilesContextPickerPick {
140
- constructor(_chatEditingService, _labelService) {
141
- this._chatEditingService = _chatEditingService;
142
- this._labelService = _labelService;
143
- this.type = 'pickerPick';
144
- this.label = ( localize(4710, 'Related Files'));
145
- this.icon = Codicon.sparkle;
146
- this.ordinal = 300;
147
- }
148
- isEnabled(widget) {
149
- return this._chatEditingService.hasRelatedFilesProviders() && (Boolean(widget.getInput()) || widget.attachmentModel.fileAttachments.length > 0);
150
- }
151
- asPicker(widget) {
152
- const picks = (async () => {
153
- const chatSessionResource = widget.viewModel?.sessionResource;
154
- if (!chatSessionResource) {
155
- return [];
156
- }
157
- const relatedFiles = await this._chatEditingService.getRelatedFiles(chatSessionResource, widget.getInput(), widget.attachmentModel.fileAttachments, CancellationToken.None);
158
- if (!relatedFiles) {
159
- return [];
160
- }
161
- const attachments = widget.attachmentModel.getAttachmentIDs();
162
- return this._chatEditingService.getRelatedFiles(chatSessionResource, widget.getInput(), widget.attachmentModel.fileAttachments, CancellationToken.None)
163
- .then((files) => (files ?? []).reduce((acc, cur) => {
164
- acc.push({ type: 'separator', label: cur.group });
165
- for (const file of cur.files) {
166
- const label = this._labelService.getUriBasenameLabel(file.uri);
167
- acc.push({
168
- label: label,
169
- description: this._labelService.getUriLabel(dirname(file.uri), { relative: true }),
170
- disabled: ( attachments.has(( file.uri.toString()))),
171
- asAttachment: () => {
172
- return {
173
- kind: 'file',
174
- id: ( file.uri.toString()),
175
- value: file.uri,
176
- name: label,
177
- omittedState: OmittedState.NotOmitted
178
- };
179
- }
180
- });
181
- }
182
- return acc;
183
- }, []));
184
- })();
185
- return {
186
- placeholder: ( localize(4711, 'Add related files to your working set')),
187
- picks,
188
- };
189
- }
190
- };
191
- RelatedFilesContextPickerPick = ( __decorate([
192
- ( __param(0, IChatEditingService)),
193
- ( __param(1, ILabelService))
194
- ], RelatedFilesContextPickerPick));
146
+ OpenEditorContextValuePick = ( __decorate([( __param(0, IEditorService)), ( __param(1, ILabelService))], OpenEditorContextValuePick));
195
147
  let ClipboardImageContextValuePick = class ClipboardImageContextValuePick {
196
148
  constructor(_clipboardService) {
197
149
  this._clipboardService = _clipboardService;
198
- this.type = 'valuePick';
199
- this.label = ( localize(4712, 'Image from Clipboard'));
150
+ this.type = "valuePick";
151
+ this.label = ( localize(4722, "Image from Clipboard"));
200
152
  this.icon = Codicon.fileMedia;
201
153
  }
202
154
  async isEnabled(widget) {
203
155
  if (!widget.attachmentCapabilities.supportsImageAttachments) {
204
156
  return false;
205
157
  }
206
- if (!widget.input.selectedLanguageModel?.metadata.capabilities?.vision) {
158
+ if (!widget.input.selectedLanguageModel.get()?.metadata.capabilities?.vision) {
207
159
  return false;
208
160
  }
209
161
  const imageData = await this._clipboardService.readImage();
@@ -213,23 +165,21 @@ let ClipboardImageContextValuePick = class ClipboardImageContextValuePick {
213
165
  const fileBuffer = await this._clipboardService.readImage();
214
166
  return {
215
167
  id: await imageToHash(fileBuffer),
216
- name: ( localize(4713, 'Pasted Image')),
217
- fullName: ( localize(4713, 'Pasted Image')),
168
+ name: ( localize(4723, "Pasted Image")),
169
+ fullName: ( localize(4723, "Pasted Image")),
218
170
  value: fileBuffer,
219
- kind: 'image',
171
+ kind: "image"
220
172
  };
221
173
  }
222
174
  };
223
- ClipboardImageContextValuePick = ( __decorate([
224
- ( __param(0, IClipboardService))
225
- ], ClipboardImageContextValuePick));
175
+ ClipboardImageContextValuePick = ( __decorate([( __param(0, IClipboardService))], ClipboardImageContextValuePick));
226
176
  let TerminalContext = class TerminalContext {
227
177
  constructor(_resource, _terminalService) {
228
178
  this._resource = _resource;
229
179
  this._terminalService = _terminalService;
230
- this.type = 'valuePick';
180
+ this.type = "valuePick";
231
181
  this.icon = Codicon.terminal;
232
- this.label = ( localize(4714, 'Terminal'));
182
+ this.label = ( localize(4724, "Terminal"));
233
183
  }
234
184
  isEnabled(widget) {
235
185
  const terminal = this._terminalService.getInstanceFromResource(this._resource);
@@ -241,12 +191,12 @@ let TerminalContext = class TerminalContext {
241
191
  return;
242
192
  }
243
193
  const params = ( new URLSearchParams(this._resource.query));
244
- const command = terminal.capabilities.get(TerminalCapability.CommandDetection)?.commands.find(cmd => cmd.id === params.get('command'));
194
+ const command = terminal.capabilities.get(TerminalCapability.CommandDetection)?.commands.find(cmd => cmd.id === params.get("command"));
245
195
  if (!command) {
246
196
  return;
247
197
  }
248
198
  const attachment = {
249
- kind: 'terminalCommand',
199
+ kind: "terminalCommand",
250
200
  id: `terminalCommand:${Date.now()}}`,
251
201
  value: this.asValue(command),
252
202
  name: command.command,
@@ -282,34 +232,28 @@ let TerminalContext = class TerminalContext {
282
232
  if (output) {
283
233
  value += `\nOutput:\n${output}`;
284
234
  }
285
- if (typeof command.exitCode === 'number') {
235
+ if (typeof command.exitCode === "number") {
286
236
  value += `\nExit Code: ${command.exitCode}`;
287
237
  }
288
238
  return value;
289
239
  }
290
240
  };
291
- TerminalContext = ( __decorate([
292
- ( __param(1, ITerminalService))
293
- ], TerminalContext));
241
+ TerminalContext = ( __decorate([( __param(1, ITerminalService))], TerminalContext));
294
242
  let ScreenshotContextValuePick = class ScreenshotContextValuePick {
295
243
  constructor(_hostService) {
296
244
  this._hostService = _hostService;
297
- this.type = 'valuePick';
245
+ this.type = "valuePick";
298
246
  this.icon = Codicon.deviceCamera;
299
- this.label = (isElectron
300
- ? ( localize(4715, 'Screenshot Window'))
301
- : ( localize(4716, 'Screenshot')));
247
+ this.label = (isElectron ? ( localize(4725, "Screenshot Window")) : ( localize(4726, "Screenshot")));
302
248
  }
303
249
  async isEnabled(widget) {
304
- return !!widget.attachmentCapabilities.supportsImageAttachments && !!widget.input.selectedLanguageModel?.metadata.capabilities?.vision;
250
+ return !!widget.attachmentCapabilities.supportsImageAttachments && !!widget.input.selectedLanguageModel.get()?.metadata.capabilities?.vision;
305
251
  }
306
252
  async asAttachment() {
307
253
  const blob = await this._hostService.getScreenshot();
308
254
  return blob && convertBufferToScreenshotVariable(blob);
309
255
  }
310
256
  };
311
- ScreenshotContextValuePick = ( __decorate([
312
- ( __param(0, IHostService))
313
- ], ScreenshotContextValuePick));
257
+ ScreenshotContextValuePick = ( __decorate([( __param(0, IHostService))], ScreenshotContextValuePick));
314
258
 
315
259
  export { ChatContextContributions, TerminalContext };
@@ -0,0 +1,42 @@
1
+ import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
+ import { IRange } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
3
+ import { Command } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/languages";
4
+ import { Action2 } from "@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions";
5
+ import { ServicesAccessor } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
6
+ import { ILabelService } from "@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service";
7
+ import { IChatRequestVariableValue, IDynamicVariable } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/attachments/chatVariables";
8
+ import { IChatWidget } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/chat";
9
+ import { IChatWidgetContrib } from "@codingame/monaco-vscode-katex-common/vscode/vs/workbench/contrib/chat/browser/widget/chatWidget";
10
+ export declare const dynamicVariableDecorationType = "chat-dynamic-variable";
11
+ export declare class ChatDynamicVariableModel extends Disposable implements IChatWidgetContrib {
12
+ private readonly widget;
13
+ private readonly labelService;
14
+ static readonly ID = "chatDynamicVariableModel";
15
+ private _variables;
16
+ get variables(): ReadonlyArray<IDynamicVariable>;
17
+ get id(): string;
18
+ private decorationData;
19
+ constructor(widget: IChatWidget, labelService: ILabelService);
20
+ getInputState(contrib: Record<string, unknown>): void;
21
+ setInputState(contrib: Readonly<Record<string, unknown>>): void;
22
+ addReference(ref: IDynamicVariable): void;
23
+ private updateDecorations;
24
+ private getHoverForReference;
25
+ /**
26
+ * Dispose all existing variables.
27
+ */
28
+ private disposeVariables;
29
+ dispose(): void;
30
+ }
31
+ export interface IAddDynamicVariableContext {
32
+ id: string;
33
+ widget: IChatWidget;
34
+ range: IRange;
35
+ variableData: IChatRequestVariableValue;
36
+ command?: Command;
37
+ }
38
+ export declare class AddDynamicVariableAction extends Action2 {
39
+ static readonly ID = "workbench.action.chat.addDynamicVariable";
40
+ constructor();
41
+ run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void>;
42
+ }
@@ -0,0 +1,209 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { coalesce } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
4
+ import { MarkdownString } from '@codingame/monaco-vscode-api/vscode/vs/base/common/htmlContent';
5
+ import { Disposable, dispose, isDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
6
+ import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
7
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
8
+ import { isLocation } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages';
9
+ import { Action2, registerAction2 } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions';
10
+ import { ICommandService } from '@codingame/monaco-vscode-api/vscode/vs/platform/commands/common/commands.service';
11
+ import { ILabelService } from '@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service';
12
+ import { addDynamicVariableActionId } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/widget/input/editor/chatDynamicVariablesConstant';
13
+
14
+ var ChatDynamicVariableModel_1;
15
+ const dynamicVariableDecorationType = "chat-dynamic-variable";
16
+ let ChatDynamicVariableModel = class ChatDynamicVariableModel extends Disposable {
17
+ static {
18
+ ChatDynamicVariableModel_1 = this;
19
+ }
20
+ static {
21
+ this.ID = "chatDynamicVariableModel";
22
+ }
23
+ get variables() {
24
+ return [...this._variables];
25
+ }
26
+ get id() {
27
+ return ChatDynamicVariableModel_1.ID;
28
+ }
29
+ constructor(widget, labelService) {
30
+ super();
31
+ this.widget = widget;
32
+ this.labelService = labelService;
33
+ this._variables = [];
34
+ this.decorationData = [];
35
+ this._register(widget.inputEditor.onDidChangeModelContent(e => {
36
+ const removed = [];
37
+ let didChange = false;
38
+ this._variables = coalesce(( this._variables.map((ref, idx) => {
39
+ const model = widget.inputEditor.getModel();
40
+ if (!model) {
41
+ removed.push(ref);
42
+ return null;
43
+ }
44
+ const data = this.decorationData[idx];
45
+ const newRange = model.getDecorationRange(data.id);
46
+ if (!newRange) {
47
+ removed.push(ref);
48
+ return null;
49
+ }
50
+ const newText = model.getValueInRange(newRange);
51
+ if (newText !== data.text) {
52
+ this.widget.inputEditor.executeEdits(this.id, [{
53
+ range: newRange,
54
+ text: ""
55
+ }]);
56
+ this.widget.refreshParsedInput();
57
+ removed.push(ref);
58
+ return null;
59
+ }
60
+ if (newRange.equalsRange(ref.range)) {
61
+ return ref;
62
+ }
63
+ didChange = true;
64
+ return {
65
+ ...ref,
66
+ range: newRange
67
+ };
68
+ })));
69
+ dispose(removed.filter(isDisposable));
70
+ if (didChange || removed.length > 0) {
71
+ this.widget.refreshParsedInput();
72
+ }
73
+ this.updateDecorations();
74
+ }));
75
+ }
76
+ getInputState(contrib) {
77
+ contrib[ChatDynamicVariableModel_1.ID] = this.variables;
78
+ }
79
+ setInputState(contrib) {
80
+ let s = contrib[ChatDynamicVariableModel_1.ID];
81
+ if (!Array.isArray(s)) {
82
+ s = [];
83
+ }
84
+ this.disposeVariables();
85
+ this._variables = [];
86
+ for (const variable of s) {
87
+ if (!isDynamicVariable(variable)) {
88
+ continue;
89
+ }
90
+ this.addReference(variable);
91
+ }
92
+ }
93
+ addReference(ref) {
94
+ this._variables.push(ref);
95
+ this.updateDecorations();
96
+ this.widget.refreshParsedInput();
97
+ }
98
+ updateDecorations() {
99
+ const decorationIds = this.widget.inputEditor.setDecorationsByType("chat", dynamicVariableDecorationType, ( this._variables.map(r => ({
100
+ range: r.range,
101
+ hoverMessage: this.getHoverForReference(r)
102
+ }))));
103
+ this.decorationData = [];
104
+ for (let i = 0; i < decorationIds.length; i++) {
105
+ this.decorationData.push({
106
+ id: decorationIds[i],
107
+ text: this.widget.inputEditor.getModel().getValueInRange(this._variables[i].range)
108
+ });
109
+ }
110
+ }
111
+ getHoverForReference(ref) {
112
+ const value = ref.data;
113
+ if (URI.isUri(value)) {
114
+ return ( new MarkdownString(this.labelService.getUriLabel(value, {
115
+ relative: true
116
+ })));
117
+ } else if (isLocation(value)) {
118
+ const prefix = ref.fullName ? ` ${ref.fullName}` : "";
119
+ const rangeString = `#${value.range.startLineNumber}-${value.range.endLineNumber}`;
120
+ return ( new MarkdownString(prefix + this.labelService.getUriLabel(value.uri, {
121
+ relative: true
122
+ }) + rangeString));
123
+ } else {
124
+ return undefined;
125
+ }
126
+ }
127
+ disposeVariables() {
128
+ for (const variable of this._variables) {
129
+ if (isDisposable(variable)) {
130
+ variable.dispose();
131
+ }
132
+ }
133
+ }
134
+ dispose() {
135
+ this.disposeVariables();
136
+ super.dispose();
137
+ }
138
+ };
139
+ ChatDynamicVariableModel = ChatDynamicVariableModel_1 = ( __decorate([( __param(1, ILabelService))], ChatDynamicVariableModel));
140
+ function isDynamicVariable(obj) {
141
+ return obj && typeof obj.id === "string" && Range.isIRange(obj.range) && "data" in obj;
142
+ }
143
+ function isAddDynamicVariableContext(context) {
144
+ return "widget" in context && "range" in context && "variableData" in context;
145
+ }
146
+ class AddDynamicVariableAction extends Action2 {
147
+ static {
148
+ this.ID = addDynamicVariableActionId;
149
+ }
150
+ constructor() {
151
+ super({
152
+ id: AddDynamicVariableAction.ID,
153
+ title: ""
154
+ });
155
+ }
156
+ async run(accessor, ...args) {
157
+ const context = args[0];
158
+ if (!isAddDynamicVariableContext(context)) {
159
+ return;
160
+ }
161
+ let range = context.range;
162
+ const variableData = context.variableData;
163
+ const doCleanup = () => {
164
+ context.widget.inputEditor.executeEdits("chatInsertDynamicVariableWithArguments", [{
165
+ range: context.range,
166
+ text: ``
167
+ }]);
168
+ };
169
+ if (context.command) {
170
+ const commandService = accessor.get(ICommandService);
171
+ const selection = await commandService.executeCommand(context.command.id, ...(context.command.arguments ?? []));
172
+ if (!selection) {
173
+ doCleanup();
174
+ return;
175
+ }
176
+ const insertText = ":" + selection;
177
+ const insertRange = ( new Range(
178
+ range.startLineNumber,
179
+ range.endColumn,
180
+ range.endLineNumber,
181
+ range.endColumn + insertText.length
182
+ ));
183
+ range = ( new Range(
184
+ range.startLineNumber,
185
+ range.startColumn,
186
+ range.endLineNumber,
187
+ range.endColumn + insertText.length
188
+ ));
189
+ const editor = context.widget.inputEditor;
190
+ const success = editor.executeEdits("chatInsertDynamicVariableWithArguments", [{
191
+ range: insertRange,
192
+ text: insertText + " "
193
+ }]);
194
+ if (!success) {
195
+ doCleanup();
196
+ return;
197
+ }
198
+ }
199
+ context.widget.getContrib(ChatDynamicVariableModel.ID)?.addReference({
200
+ id: context.id,
201
+ range: range,
202
+ isFile: true,
203
+ data: variableData
204
+ });
205
+ }
206
+ }
207
+ registerAction2(AddDynamicVariableAction);
208
+
209
+ export { AddDynamicVariableAction, ChatDynamicVariableModel, dynamicVariableDecorationType };