@codingame/monaco-vscode-a793b3ee-7ba9-5176-a019-30ec806fdd95-common 20.0.0

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/empty.js +1 -0
  2. package/package.json +50 -0
  3. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.d.ts +159 -0
  4. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.js +1318 -0
  5. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.d.ts +172 -0
  6. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.js +482 -0
  7. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.d.ts +86 -0
  8. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.js +377 -0
  9. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.d.ts +70 -0
  10. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatStrategies.js +456 -0
  11. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.d.ts +40 -0
  12. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.js +276 -0
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.d.ts +22 -0
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +318 -0
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.d.ts +18 -0
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +59 -0
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.d.ts +69 -0
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +318 -0
@@ -0,0 +1,172 @@
1
+ import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri";
2
+ import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event";
3
+ import { ITextModel, IValidEditOperation } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
4
+ import { IRange, Range } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range";
5
+ import { DetailedLineRangeMapping, LineRangeMapping } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/diff/rangeMapping";
6
+ import { IInlineChatSessionService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.service";
7
+ import { IEditorWorkerService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/editorWorker.service";
8
+ import { ICodeEditor } from "@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorBrowser";
9
+ import { IContextKeyService } from "@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey.service";
10
+ import { ILogService } from "@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service";
11
+ import { ChatModel, IChatRequestModel, IChatTextEditGroupState } from "@codingame/monaco-vscode-c2deffc4-ad68-5e63-8f95-9b89e0fc6898-common/vscode/vs/workbench/contrib/chat/common/chatModel";
12
+ import { IChatAgent } from "@codingame/monaco-vscode-b994942c-360d-5b68-8a33-77d4bde6b714-common/vscode/vs/workbench/contrib/chat/common/chatAgents";
13
+ import { IDocumentDiff } from "@codingame/monaco-vscode-chat-service-override/vscode/vs/editor/common/diff/documentDiffProvider";
14
+ export type TelemetryData = {
15
+ extension: string;
16
+ rounds: string;
17
+ undos: string;
18
+ unstashed: number;
19
+ edits: number;
20
+ finishedByEdit: boolean;
21
+ startTime: string;
22
+ endTime: string;
23
+ acceptedHunks: number;
24
+ discardedHunks: number;
25
+ responseTypes: string;
26
+ };
27
+ export type TelemetryDataClassification = {
28
+ owner: "jrieken";
29
+ comment: "Data about an interaction editor session";
30
+ extension: {
31
+ classification: "SystemMetaData";
32
+ purpose: "FeatureInsight";
33
+ comment: "The extension providing the data";
34
+ };
35
+ rounds: {
36
+ classification: "SystemMetaData";
37
+ purpose: "FeatureInsight";
38
+ comment: "Number of request that were made";
39
+ };
40
+ undos: {
41
+ classification: "SystemMetaData";
42
+ purpose: "FeatureInsight";
43
+ comment: "Requests that have been undone";
44
+ };
45
+ edits: {
46
+ classification: "SystemMetaData";
47
+ purpose: "FeatureInsight";
48
+ comment: "Did edits happen while the session was active";
49
+ };
50
+ unstashed: {
51
+ classification: "SystemMetaData";
52
+ purpose: "FeatureInsight";
53
+ comment: "How often did this session become stashed and resumed";
54
+ };
55
+ finishedByEdit: {
56
+ classification: "SystemMetaData";
57
+ purpose: "FeatureInsight";
58
+ comment: "Did edits cause the session to terminate";
59
+ };
60
+ startTime: {
61
+ classification: "SystemMetaData";
62
+ purpose: "FeatureInsight";
63
+ comment: "When the session started";
64
+ };
65
+ endTime: {
66
+ classification: "SystemMetaData";
67
+ purpose: "FeatureInsight";
68
+ comment: "When the session ended";
69
+ };
70
+ acceptedHunks: {
71
+ classification: "SystemMetaData";
72
+ purpose: "FeatureInsight";
73
+ comment: "Number of accepted hunks";
74
+ };
75
+ discardedHunks: {
76
+ classification: "SystemMetaData";
77
+ purpose: "FeatureInsight";
78
+ comment: "Number of discarded hunks";
79
+ };
80
+ responseTypes: {
81
+ classification: "SystemMetaData";
82
+ purpose: "FeatureInsight";
83
+ comment: "Comma separated list of response types like edits, message, mixed";
84
+ };
85
+ };
86
+ export declare class SessionWholeRange {
87
+ private readonly _textModel;
88
+ private static readonly _options;
89
+ private readonly _onDidChange;
90
+ readonly onDidChange: Event<this>;
91
+ private _decorationIds;
92
+ constructor(_textModel: ITextModel, wholeRange: IRange);
93
+ dispose(): void;
94
+ fixup(changes: readonly DetailedLineRangeMapping[]): void;
95
+ get trackedInitialRange(): Range;
96
+ get value(): Range;
97
+ }
98
+ export declare class Session {
99
+ readonly headless: boolean;
100
+ readonly targetUri: URI;
101
+ readonly textModel0: ITextModel;
102
+ readonly textModelN: ITextModel;
103
+ readonly agent: IChatAgent;
104
+ readonly wholeRange: SessionWholeRange;
105
+ readonly hunkData: HunkData;
106
+ readonly chatModel: ChatModel;
107
+ private _isUnstashed;
108
+ private readonly _startTime;
109
+ private readonly _teldata;
110
+ private readonly _versionByRequest;
111
+ constructor(headless: boolean, targetUri: URI, textModel0: ITextModel, textModelN: ITextModel, agent: IChatAgent, wholeRange: SessionWholeRange, hunkData: HunkData, chatModel: ChatModel, versionsByRequest?: [
112
+ string,
113
+ number
114
+ ][]);
115
+ get isUnstashed(): boolean;
116
+ markUnstashed(): void;
117
+ markModelVersion(request: IChatRequestModel): void;
118
+ get versionsByRequest(): [
119
+ string,
120
+ number
121
+ ][];
122
+ undoChangesUntil(requestId: string): Promise<boolean>;
123
+ get hasChangedText(): boolean;
124
+ asChangedText(changes: readonly LineRangeMapping[]): string | undefined;
125
+ recordExternalEditOccurred(didFinish: boolean): void;
126
+ asTelemetryData(): TelemetryData;
127
+ }
128
+ export declare class StashedSession {
129
+ private readonly _undoCancelEdits;
130
+ private readonly _sessionService;
131
+ private readonly _logService;
132
+ private readonly _listener;
133
+ private readonly _ctxHasStashedSession;
134
+ private _session;
135
+ constructor(editor: ICodeEditor, session: Session, _undoCancelEdits: IValidEditOperation[], contextKeyService: IContextKeyService, _sessionService: IInlineChatSessionService, _logService: ILogService);
136
+ dispose(): void;
137
+ unstash(): Session | undefined;
138
+ }
139
+ export declare class HunkData {
140
+ private readonly _editorWorkerService;
141
+ private readonly _textModel0;
142
+ private readonly _textModelN;
143
+ private static readonly _HUNK_TRACKED_RANGE;
144
+ private static readonly _HUNK_THRESHOLD;
145
+ private readonly _store;
146
+ private readonly _data;
147
+ private _ignoreChanges;
148
+ constructor(_editorWorkerService: IEditorWorkerService, _textModel0: ITextModel, _textModelN: ITextModel);
149
+ dispose(): void;
150
+ set ignoreTextModelNChanges(value: boolean);
151
+ get ignoreTextModelNChanges(): boolean;
152
+ private _mirrorChanges;
153
+ recompute(editState: IChatTextEditGroupState, diff?: IDocumentDiff | null): Promise<void>;
154
+ get size(): number;
155
+ get pending(): number;
156
+ private _discardEdits;
157
+ discardAll(): IValidEditOperation[];
158
+ getInfo(): HunkInformation[];
159
+ }
160
+ export declare enum HunkState {
161
+ Pending = 0,
162
+ Accepted = 1,
163
+ Rejected = 2
164
+ }
165
+ export interface HunkInformation {
166
+ getRangesN(): Range[];
167
+ getRanges0(): Range[];
168
+ isInsertion(): boolean;
169
+ discardChanges(): void;
170
+ acceptChanges(): void;
171
+ getState(): HunkState;
172
+ }
@@ -0,0 +1,482 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { Emitter, Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
4
+ import { TrackedRangeStickiness } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model';
5
+ import { CTX_INLINE_CHAT_HAS_STASHED_SESSION } from '@codingame/monaco-vscode-e28ac690-06d5-5ee9-92d1-02df70296354-common/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
6
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
7
+ import { ModelDecorationOptions } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model/textModel';
8
+ import { EditOperation } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/editOperation';
9
+ import { DetailedLineRangeMapping } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/diff/rangeMapping';
10
+ import { IInlineChatSessionService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.service';
11
+ import { IEditorWorkerService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/editorWorker.service';
12
+ import { coalesceInPlace } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
13
+ import { Iterable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/iterator';
14
+ import { DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
15
+ import { IContextKeyService } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey.service';
16
+ import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
17
+ import { ExtensionIdentifier } from '@codingame/monaco-vscode-api/vscode/vs/platform/extensions/common/extensions';
18
+
19
+ var HunkData_1;
20
+ class SessionWholeRange {
21
+ static { this._options = ModelDecorationOptions.register({ description: 'inlineChat/session/wholeRange' }); }
22
+ constructor(_textModel, wholeRange) {
23
+ this._textModel = _textModel;
24
+ this._onDidChange = ( new Emitter());
25
+ this.onDidChange = this._onDidChange.event;
26
+ this._decorationIds = [];
27
+ this._decorationIds = _textModel.deltaDecorations([], [{ range: wholeRange, options: SessionWholeRange._options }]);
28
+ }
29
+ dispose() {
30
+ this._onDidChange.dispose();
31
+ if (!this._textModel.isDisposed()) {
32
+ this._textModel.deltaDecorations(this._decorationIds, []);
33
+ }
34
+ }
35
+ fixup(changes) {
36
+ const newDeco = [];
37
+ for (const { modified } of changes) {
38
+ const modifiedRange = this._textModel.validateRange(modified.isEmpty
39
+ ? ( new Range(
40
+ modified.startLineNumber,
41
+ 1,
42
+ modified.startLineNumber,
43
+ Number.MAX_SAFE_INTEGER
44
+ ))
45
+ : ( new Range(
46
+ modified.startLineNumber,
47
+ 1,
48
+ modified.endLineNumberExclusive - 1,
49
+ Number.MAX_SAFE_INTEGER
50
+ )));
51
+ newDeco.push({ range: modifiedRange, options: SessionWholeRange._options });
52
+ }
53
+ const [first, ...rest] = this._decorationIds;
54
+ const newIds = this._textModel.deltaDecorations(rest, newDeco);
55
+ this._decorationIds = [first].concat(newIds);
56
+ this._onDidChange.fire(this);
57
+ }
58
+ get trackedInitialRange() {
59
+ const [first] = this._decorationIds;
60
+ return this._textModel.getDecorationRange(first) ?? ( new Range(1, 1, 1, 1));
61
+ }
62
+ get value() {
63
+ let result;
64
+ for (const id of this._decorationIds) {
65
+ const range = this._textModel.getDecorationRange(id);
66
+ if (range) {
67
+ if (!result) {
68
+ result = range;
69
+ }
70
+ else {
71
+ result = Range.plusRange(result, range);
72
+ }
73
+ }
74
+ }
75
+ return result;
76
+ }
77
+ }
78
+ class Session {
79
+ constructor(headless,
80
+ targetUri,
81
+ textModel0,
82
+ textModelN, agent, wholeRange, hunkData, chatModel, versionsByRequest) {
83
+ this.headless = headless;
84
+ this.targetUri = targetUri;
85
+ this.textModel0 = textModel0;
86
+ this.textModelN = textModelN;
87
+ this.agent = agent;
88
+ this.wholeRange = wholeRange;
89
+ this.hunkData = hunkData;
90
+ this.chatModel = chatModel;
91
+ this._isUnstashed = false;
92
+ this._startTime = ( new Date());
93
+ this._versionByRequest = ( new Map());
94
+ this._teldata = {
95
+ extension: ExtensionIdentifier.toKey(agent.extensionId),
96
+ startTime: this._startTime.toISOString(),
97
+ endTime: this._startTime.toISOString(),
98
+ edits: 0,
99
+ finishedByEdit: false,
100
+ rounds: '',
101
+ undos: '',
102
+ unstashed: 0,
103
+ acceptedHunks: 0,
104
+ discardedHunks: 0,
105
+ responseTypes: ''
106
+ };
107
+ if (versionsByRequest) {
108
+ this._versionByRequest = ( new Map(versionsByRequest));
109
+ }
110
+ }
111
+ get isUnstashed() {
112
+ return this._isUnstashed;
113
+ }
114
+ markUnstashed() {
115
+ this._teldata.unstashed += 1;
116
+ this._isUnstashed = true;
117
+ }
118
+ markModelVersion(request) {
119
+ this._versionByRequest.set(request.id, this.textModelN.getAlternativeVersionId());
120
+ }
121
+ get versionsByRequest() {
122
+ return Array.from(this._versionByRequest);
123
+ }
124
+ async undoChangesUntil(requestId) {
125
+ const targetAltVersion = this._versionByRequest.get(requestId);
126
+ if (targetAltVersion === undefined) {
127
+ return false;
128
+ }
129
+ this.hunkData.ignoreTextModelNChanges = true;
130
+ try {
131
+ while (targetAltVersion < this.textModelN.getAlternativeVersionId() && this.textModelN.canUndo()) {
132
+ await this.textModelN.undo();
133
+ }
134
+ }
135
+ finally {
136
+ this.hunkData.ignoreTextModelNChanges = false;
137
+ }
138
+ return true;
139
+ }
140
+ get hasChangedText() {
141
+ return !this.textModel0.equalsTextBuffer(this.textModelN.getTextBuffer());
142
+ }
143
+ asChangedText(changes) {
144
+ if (changes.length === 0) {
145
+ return undefined;
146
+ }
147
+ let startLine = Number.MAX_VALUE;
148
+ let endLine = Number.MIN_VALUE;
149
+ for (const change of changes) {
150
+ startLine = Math.min(startLine, change.modified.startLineNumber);
151
+ endLine = Math.max(endLine, change.modified.endLineNumberExclusive);
152
+ }
153
+ return this.textModelN.getValueInRange(( new Range(startLine, 1, endLine, Number.MAX_VALUE)));
154
+ }
155
+ recordExternalEditOccurred(didFinish) {
156
+ this._teldata.edits += 1;
157
+ this._teldata.finishedByEdit = didFinish;
158
+ }
159
+ asTelemetryData() {
160
+ for (const item of this.hunkData.getInfo()) {
161
+ switch (item.getState()) {
162
+ case HunkState.Accepted:
163
+ this._teldata.acceptedHunks += 1;
164
+ break;
165
+ case HunkState.Rejected:
166
+ this._teldata.discardedHunks += 1;
167
+ break;
168
+ }
169
+ }
170
+ this._teldata.endTime = ( new Date()).toISOString();
171
+ return this._teldata;
172
+ }
173
+ }
174
+ let StashedSession = class StashedSession {
175
+ constructor(editor, session, _undoCancelEdits, contextKeyService, _sessionService, _logService) {
176
+ this._undoCancelEdits = _undoCancelEdits;
177
+ this._sessionService = _sessionService;
178
+ this._logService = _logService;
179
+ this._ctxHasStashedSession = CTX_INLINE_CHAT_HAS_STASHED_SESSION.bindTo(contextKeyService);
180
+ this._session = session;
181
+ this._ctxHasStashedSession.set(true);
182
+ this._listener = Event.once(Event.any(editor.onDidChangeCursorSelection, editor.onDidChangeModelContent, editor.onDidChangeModel, editor.onDidBlurEditorWidget))(() => {
183
+ this._session = undefined;
184
+ this._sessionService.releaseSession(session);
185
+ this._ctxHasStashedSession.reset();
186
+ });
187
+ }
188
+ dispose() {
189
+ this._listener.dispose();
190
+ this._ctxHasStashedSession.reset();
191
+ if (this._session) {
192
+ this._sessionService.releaseSession(this._session);
193
+ }
194
+ }
195
+ unstash() {
196
+ if (!this._session) {
197
+ return undefined;
198
+ }
199
+ this._listener.dispose();
200
+ const result = this._session;
201
+ result.markUnstashed();
202
+ result.hunkData.ignoreTextModelNChanges = true;
203
+ result.textModelN.pushEditOperations(null, this._undoCancelEdits, () => null);
204
+ result.hunkData.ignoreTextModelNChanges = false;
205
+ this._session = undefined;
206
+ this._logService.debug('[IE] Unstashed session');
207
+ return result;
208
+ }
209
+ };
210
+ StashedSession = ( __decorate([
211
+ ( __param(3, IContextKeyService)),
212
+ ( __param(4, IInlineChatSessionService)),
213
+ ( __param(5, ILogService))
214
+ ], StashedSession));
215
+ function lineRangeAsRange(lineRange, model) {
216
+ return lineRange.isEmpty
217
+ ? ( new Range(
218
+ lineRange.startLineNumber,
219
+ 1,
220
+ lineRange.startLineNumber,
221
+ Number.MAX_SAFE_INTEGER
222
+ ))
223
+ : ( new Range(
224
+ lineRange.startLineNumber,
225
+ 1,
226
+ lineRange.endLineNumberExclusive - 1,
227
+ Number.MAX_SAFE_INTEGER
228
+ ));
229
+ }
230
+ let HunkData = class HunkData {
231
+ static { HunkData_1 = this; }
232
+ static { this._HUNK_TRACKED_RANGE = ModelDecorationOptions.register({
233
+ description: 'inline-chat-hunk-tracked-range',
234
+ stickiness: TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
235
+ }); }
236
+ static { this._HUNK_THRESHOLD = 8; }
237
+ constructor(_editorWorkerService, _textModel0, _textModelN) {
238
+ this._editorWorkerService = _editorWorkerService;
239
+ this._textModel0 = _textModel0;
240
+ this._textModelN = _textModelN;
241
+ this._store = ( new DisposableStore());
242
+ this._data = ( new Map());
243
+ this._ignoreChanges = false;
244
+ this._store.add(_textModelN.onDidChangeContent(e => {
245
+ if (!this._ignoreChanges) {
246
+ this._mirrorChanges(e);
247
+ }
248
+ }));
249
+ }
250
+ dispose() {
251
+ if (!this._textModelN.isDisposed()) {
252
+ this._textModelN.changeDecorations(accessor => {
253
+ for (const { textModelNDecorations } of ( this._data.values())) {
254
+ textModelNDecorations.forEach(accessor.removeDecoration, accessor);
255
+ }
256
+ });
257
+ }
258
+ if (!this._textModel0.isDisposed()) {
259
+ this._textModel0.changeDecorations(accessor => {
260
+ for (const { textModel0Decorations } of ( this._data.values())) {
261
+ textModel0Decorations.forEach(accessor.removeDecoration, accessor);
262
+ }
263
+ });
264
+ }
265
+ this._data.clear();
266
+ this._store.dispose();
267
+ }
268
+ set ignoreTextModelNChanges(value) {
269
+ this._ignoreChanges = value;
270
+ }
271
+ get ignoreTextModelNChanges() {
272
+ return this._ignoreChanges;
273
+ }
274
+ _mirrorChanges(event) {
275
+ const hunkRanges = [];
276
+ const ranges0 = [];
277
+ for (const entry of ( this._data.values())) {
278
+ if (entry.state === HunkState.Pending) {
279
+ for (let i = 1; i < entry.textModelNDecorations.length; i++) {
280
+ const rangeN = this._textModelN.getDecorationRange(entry.textModelNDecorations[i]);
281
+ const range0 = this._textModel0.getDecorationRange(entry.textModel0Decorations[i]);
282
+ if (rangeN && range0) {
283
+ hunkRanges.push({
284
+ rangeN, range0,
285
+ markAccepted: () => entry.state = HunkState.Accepted
286
+ });
287
+ }
288
+ }
289
+ }
290
+ else if (entry.state === HunkState.Accepted) {
291
+ for (let i = 1; i < entry.textModel0Decorations.length; i++) {
292
+ const range = this._textModel0.getDecorationRange(entry.textModel0Decorations[i]);
293
+ if (range) {
294
+ ranges0.push(range);
295
+ }
296
+ }
297
+ }
298
+ }
299
+ hunkRanges.sort((a, b) => Range.compareRangesUsingStarts(a.rangeN, b.rangeN));
300
+ ranges0.sort(Range.compareRangesUsingStarts);
301
+ const edits = [];
302
+ for (const change of event.changes) {
303
+ let isOverlapping = false;
304
+ let pendingChangesLen = 0;
305
+ for (const entry of hunkRanges) {
306
+ if (entry.rangeN.getEndPosition().isBefore(Range.getStartPosition(change.range))) {
307
+ pendingChangesLen += this._textModelN.getValueLengthInRange(entry.rangeN);
308
+ pendingChangesLen -= this._textModel0.getValueLengthInRange(entry.range0);
309
+ }
310
+ else if (Range.areIntersectingOrTouching(entry.rangeN, change.range)) {
311
+ entry.markAccepted();
312
+ isOverlapping = true;
313
+ break;
314
+ }
315
+ else {
316
+ break;
317
+ }
318
+ }
319
+ if (isOverlapping) {
320
+ continue;
321
+ }
322
+ const offset0 = change.rangeOffset - pendingChangesLen;
323
+ const start0 = this._textModel0.getPositionAt(offset0);
324
+ let acceptedChangesLen = 0;
325
+ for (const range of ranges0) {
326
+ if (range.getEndPosition().isBefore(start0)) {
327
+ acceptedChangesLen += this._textModel0.getValueLengthInRange(range);
328
+ }
329
+ }
330
+ const start = this._textModel0.getPositionAt(offset0 + acceptedChangesLen);
331
+ const end = this._textModel0.getPositionAt(offset0 + acceptedChangesLen + change.rangeLength);
332
+ edits.push(EditOperation.replace(Range.fromPositions(start, end), change.text));
333
+ }
334
+ this._textModel0.pushEditOperations(null, edits, () => null);
335
+ }
336
+ async recompute(editState, diff) {
337
+ diff ??= await this._editorWorkerService.computeDiff(this._textModel0.uri, this._textModelN.uri, { ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER, computeMoves: false }, 'advanced');
338
+ let mergedChanges = [];
339
+ if (diff && diff.changes.length > 0) {
340
+ mergedChanges = [diff.changes[0]];
341
+ for (let i = 1; i < diff.changes.length; i++) {
342
+ const lastChange = mergedChanges[mergedChanges.length - 1];
343
+ const thisChange = diff.changes[i];
344
+ if (thisChange.modified.startLineNumber - lastChange.modified.endLineNumberExclusive <= HunkData_1._HUNK_THRESHOLD) {
345
+ mergedChanges[mergedChanges.length - 1] = ( new DetailedLineRangeMapping(
346
+ lastChange.original.join(thisChange.original),
347
+ lastChange.modified.join(thisChange.modified),
348
+ (lastChange.innerChanges ?? []).concat(thisChange.innerChanges ?? [])
349
+ ));
350
+ }
351
+ else {
352
+ mergedChanges.push(thisChange);
353
+ }
354
+ }
355
+ }
356
+ const hunks = ( mergedChanges.map(change => ( new RawHunk(change.original, change.modified, change.innerChanges ?? []))));
357
+ editState.applied = hunks.length;
358
+ this._textModelN.changeDecorations(accessorN => {
359
+ this._textModel0.changeDecorations(accessor0 => {
360
+ for (const { textModelNDecorations, textModel0Decorations } of ( this._data.values())) {
361
+ textModelNDecorations.forEach(accessorN.removeDecoration, accessorN);
362
+ textModel0Decorations.forEach(accessor0.removeDecoration, accessor0);
363
+ }
364
+ this._data.clear();
365
+ for (const hunk of hunks) {
366
+ const textModelNDecorations = [];
367
+ const textModel0Decorations = [];
368
+ textModelNDecorations.push(accessorN.addDecoration(lineRangeAsRange(hunk.modified), HunkData_1._HUNK_TRACKED_RANGE));
369
+ textModel0Decorations.push(accessor0.addDecoration(lineRangeAsRange(hunk.original), HunkData_1._HUNK_TRACKED_RANGE));
370
+ for (const change of hunk.changes) {
371
+ textModelNDecorations.push(accessorN.addDecoration(change.modifiedRange, HunkData_1._HUNK_TRACKED_RANGE));
372
+ textModel0Decorations.push(accessor0.addDecoration(change.originalRange, HunkData_1._HUNK_TRACKED_RANGE));
373
+ }
374
+ this._data.set(hunk, {
375
+ editState,
376
+ textModelNDecorations,
377
+ textModel0Decorations,
378
+ state: HunkState.Pending
379
+ });
380
+ }
381
+ });
382
+ });
383
+ }
384
+ get size() {
385
+ return this._data.size;
386
+ }
387
+ get pending() {
388
+ return Iterable.reduce(( this._data.values()), (r, { state }) => r + (state === HunkState.Pending ? 1 : 0), 0);
389
+ }
390
+ _discardEdits(item) {
391
+ const edits = [];
392
+ const rangesN = item.getRangesN();
393
+ const ranges0 = item.getRanges0();
394
+ for (let i = 1; i < rangesN.length; i++) {
395
+ const modifiedRange = rangesN[i];
396
+ const originalValue = this._textModel0.getValueInRange(ranges0[i]);
397
+ edits.push(EditOperation.replace(modifiedRange, originalValue));
398
+ }
399
+ return edits;
400
+ }
401
+ discardAll() {
402
+ const edits = [];
403
+ for (const item of this.getInfo()) {
404
+ if (item.getState() === HunkState.Pending) {
405
+ edits.push(this._discardEdits(item));
406
+ }
407
+ }
408
+ const undoEdits = [];
409
+ this._textModelN.pushEditOperations(null, edits.flat(), (_undoEdits) => {
410
+ undoEdits.push(_undoEdits);
411
+ return null;
412
+ });
413
+ return undoEdits.flat();
414
+ }
415
+ getInfo() {
416
+ const result = [];
417
+ for (const [hunk, data] of this._data.entries()) {
418
+ const item = {
419
+ getState: () => {
420
+ return data.state;
421
+ },
422
+ isInsertion: () => {
423
+ return hunk.original.isEmpty;
424
+ },
425
+ getRangesN: () => {
426
+ const ranges = ( data.textModelNDecorations.map(id => this._textModelN.getDecorationRange(id)));
427
+ coalesceInPlace(ranges);
428
+ return ranges;
429
+ },
430
+ getRanges0: () => {
431
+ const ranges = ( data.textModel0Decorations.map(id => this._textModel0.getDecorationRange(id)));
432
+ coalesceInPlace(ranges);
433
+ return ranges;
434
+ },
435
+ discardChanges: () => {
436
+ if (data.state === HunkState.Pending) {
437
+ const edits = this._discardEdits(item);
438
+ this._textModelN.pushEditOperations(null, edits, () => null);
439
+ data.state = HunkState.Rejected;
440
+ if (data.editState.applied > 0) {
441
+ data.editState.applied -= 1;
442
+ }
443
+ }
444
+ },
445
+ acceptChanges: () => {
446
+ if (data.state === HunkState.Pending) {
447
+ const edits = [];
448
+ const rangesN = item.getRangesN();
449
+ const ranges0 = item.getRanges0();
450
+ for (let i = 1; i < ranges0.length; i++) {
451
+ const originalRange = ranges0[i];
452
+ const modifiedValue = this._textModelN.getValueInRange(rangesN[i]);
453
+ edits.push(EditOperation.replace(originalRange, modifiedValue));
454
+ }
455
+ this._textModel0.pushEditOperations(null, edits, () => null);
456
+ data.state = HunkState.Accepted;
457
+ }
458
+ }
459
+ };
460
+ result.push(item);
461
+ }
462
+ return result;
463
+ }
464
+ };
465
+ HunkData = HunkData_1 = ( __decorate([
466
+ ( __param(0, IEditorWorkerService))
467
+ ], HunkData));
468
+ class RawHunk {
469
+ constructor(original, modified, changes) {
470
+ this.original = original;
471
+ this.modified = modified;
472
+ this.changes = changes;
473
+ }
474
+ }
475
+ var HunkState;
476
+ (function (HunkState) {
477
+ HunkState[HunkState["Pending"] = 0] = "Pending";
478
+ HunkState[HunkState["Accepted"] = 1] = "Accepted";
479
+ HunkState[HunkState["Rejected"] = 2] = "Rejected";
480
+ })(HunkState || (HunkState = {}));
481
+
482
+ export { HunkData, HunkState, Session, SessionWholeRange, StashedSession };