@codingame/monaco-vscode-api 1.76.2 → 1.76.3-next.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 (59) hide show
  1. package/README.md +2 -1
  2. package/dist/api.js +3 -860
  3. package/dist/{extHost.js → api2.js} +16555 -13467
  4. package/dist/async.js +107 -2
  5. package/dist/audioCue.js +105 -103
  6. package/dist/button.js +1 -1
  7. package/dist/cancellation.js +3 -0
  8. package/dist/configuration.js +7 -344
  9. package/dist/configuration2.js +339 -0
  10. package/dist/configurationRegistry.js +441 -0
  11. package/dist/contextkeys.js +211 -0
  12. package/dist/debug.d.ts +22 -0
  13. package/dist/debug.js +15842 -0
  14. package/dist/dialogs.js +855 -9
  15. package/dist/extensionResourceLoader.js +96 -0
  16. package/dist/extensions.d.ts +491 -0
  17. package/dist/extensions.js +70 -0
  18. package/dist/{tools.js → extensionsRegistry.js} +2 -30
  19. package/dist/files.js +1407 -334
  20. package/dist/iconv.js +43 -0
  21. package/dist/injection.js +1 -1
  22. package/dist/jschardet.js +7 -0
  23. package/dist/keybindings.d.ts +1 -485
  24. package/dist/keybindings.js +666 -679
  25. package/dist/labels.js +14 -0
  26. package/dist/languageConfiguration.d.ts +1 -2
  27. package/dist/languageConfiguration.js +9 -16
  28. package/dist/languageService.js +112 -8
  29. package/dist/languages.d.ts +1 -473
  30. package/dist/languages.js +2 -12
  31. package/dist/layout.js +4 -3
  32. package/dist/layoutService.js +1 -1
  33. package/dist/missing-services.js +4710 -74
  34. package/dist/modelEditor.d.ts +324 -2
  35. package/dist/modelEditor.js +15 -228
  36. package/dist/monaco.js +7 -72
  37. package/dist/notifications.js +75 -232
  38. package/dist/polyfill.js +10715 -2459
  39. package/dist/resources.js +197 -0
  40. package/dist/services.d.ts +924 -3
  41. package/dist/services.js +1 -2
  42. package/dist/services2.js +2436 -18
  43. package/dist/snippets.d.ts +1 -473
  44. package/dist/snippets.js +8 -867
  45. package/dist/snippetsService.js +868 -0
  46. package/dist/textFileEditorModel.js +2985 -0
  47. package/dist/textmate.d.ts +3 -475
  48. package/dist/textmate.js +19 -29
  49. package/dist/theme.d.ts +1 -3
  50. package/dist/theme.js +24 -70
  51. package/dist/tokenClassification.d.ts +1 -475
  52. package/dist/tokenClassification.js +11 -37
  53. package/dist/tokenClassificationRegistry.js +8 -4
  54. package/dist/variableResolver.js +1711 -0
  55. package/dist/workbenchThemeService.js +1 -1
  56. package/dist/workspaceContext.js +1 -3
  57. package/package.json +27 -12
  58. package/dist/contextkey.js +0 -419
  59. package/dist/dialog.web.contribution.js +0 -945
@@ -0,0 +1,2985 @@
1
+ import { _ as __decorate, E as Emitter, a as __param, X as ETAG_DISABLED, Z as NotModifiedSinceFileOperationError, n as IFileService, l as ITextFileService, r as IPathService } from './services2.js';
2
+ import { b$ as SaveSourceRegistry, c6 as LanguageDetectionLanguageEventSource, bP as ILanguageDetectionService, c0 as IWorkingCopyBackupService, I as IWorkingCopyService, c3 as IFilesConfigurationService, bp as IExtensionService } from './missing-services.js';
3
+ import { Disposable, combinedDisposable, MutableDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { R as Range, S as Selection, P as Position, w as withUndefinedAsNull, K as listenStream, Q as newWriteableStream } from './polyfill.js';
5
+ import { ThrottledDelayer, timeout } from 'monaco-editor/esm/vs/base/common/async.js';
6
+ import { PLAINTEXT_LANGUAGE_ID } from 'monaco-editor/esm/vs/editor/common/languages/modesRegistry.js';
7
+ import { localize } from 'monaco-editor/esm/vs/nls.js';
8
+ import { IModelService } from 'monaco-editor/esm/vs/editor/common/services/model.js';
9
+ import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
10
+ import { IAccessibilityService } from 'monaco-editor/esm/vs/platform/accessibility/common/accessibility.js';
11
+ import { C as CancellationTokenSource } from './cancellation.js';
12
+ import { VSBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js';
13
+ import { T as TaskSequentializer } from './async.js';
14
+ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
15
+ import { EDITOR_MODEL_DEFAULTS } from 'monaco-editor/esm/vs/editor/common/core/textModelDefaults.js';
16
+ import { IUndoRedoService } from 'monaco-editor/esm/vs/platform/undoRedo/common/undoRedo.js';
17
+ import { ILanguageConfigurationService } from 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
18
+ import { PieceTreeTextBufferBuilder } from 'monaco-editor/esm/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder.js';
19
+ import { guessIndentation } from 'monaco-editor/esm/vs/editor/common/model/indentationGuesser.js';
20
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
21
+ import { BracketPairsTextModelPart } from 'monaco-editor/esm/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsImpl.js';
22
+ import { GuidesTextModelPart } from 'monaco-editor/esm/vs/editor/common/model/guidesTextModelPart.js';
23
+ import { ColorizedBracketPairsDecorationProvider } from 'monaco-editor/esm/vs/editor/common/model/bracketPairsTextModelPart/colorizedBracketPairsDecorationProvider.js';
24
+ import { TokenizationTextModelPart } from 'monaco-editor/esm/vs/editor/common/model/tokenizationTextModelPart.js';
25
+ import { singleLetterHash, UNUSUAL_LINE_TERMINATORS, isHighSurrogate } from 'monaco-editor/esm/vs/base/common/strings.js';
26
+ import { EditStack } from 'monaco-editor/esm/vs/editor/common/model/editStack.js';
27
+ import { InternalModelContentChangeEvent, ModelRawContentChangedEvent, ModelRawFlush, ModelRawEOLChanged, LineInjectedText, ModelRawLineChanged, ModelRawLinesDeleted, ModelRawLinesInserted, ModelInjectedTextChangedEvent } from 'monaco-editor/esm/vs/editor/common/textModelEvents.js';
28
+ import { illegalArgument, onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
29
+ import { recomputeMaxEnd, IntervalNode, IntervalTree } from 'monaco-editor/esm/vs/editor/common/model/intervalTree.js';
30
+ import { normalizeIndentation } from 'monaco-editor/esm/vs/editor/common/core/indentation.js';
31
+ import { TextModelSearch, SearchParams } from 'monaco-editor/esm/vs/editor/common/model/textModelSearch.js';
32
+ import { ValidAnnotatedEditOperation, isITextSnapshot, OverviewRulerLane } from 'monaco-editor/esm/vs/editor/common/model.js';
33
+ import { countEOL } from 'monaco-editor/esm/vs/editor/common/core/eolCounter.js';
34
+ import { pushMany, ArrayQueue } from 'monaco-editor/esm/vs/base/common/arrays.js';
35
+ import { PieceTreeTextBuffer } from 'monaco-editor/esm/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.js';
36
+ import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
37
+ import { basename } from 'monaco-editor/esm/vs/base/common/path.js';
38
+ import { extUri } from 'monaco-editor/esm/vs/base/common/resources.js';
39
+ import { withNullAsUndefined, assertIsDefined } from 'monaco-editor/esm/vs/base/common/types.js';
40
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
41
+ import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
42
+ const TextModelResolvedOptions = monaco.editor.TextModelResolvedOptions;
43
+ function createTextBufferFactory(text) {
44
+ const builder = ( (new PieceTreeTextBufferBuilder()));
45
+ builder.acceptChunk(text);
46
+ return builder.finish();
47
+ }
48
+ function createTextBufferFactoryFromStream(stream) {
49
+ return (
50
+ (new Promise((resolve, reject) => {
51
+ const builder = ( (new PieceTreeTextBufferBuilder()));
52
+ let done = false;
53
+ listenStream(stream, {
54
+ onData: chunk => {
55
+ builder.acceptChunk((typeof chunk === 'string') ? chunk : ( (chunk.toString())));
56
+ },
57
+ onError: error => {
58
+ if (!done) {
59
+ done = true;
60
+ reject(error);
61
+ }
62
+ },
63
+ onEnd: () => {
64
+ if (!done) {
65
+ done = true;
66
+ resolve(builder.finish());
67
+ }
68
+ }
69
+ });
70
+ }))
71
+ );
72
+ }
73
+ function createTextBufferFactoryFromSnapshot(snapshot) {
74
+ const builder = ( (new PieceTreeTextBufferBuilder()));
75
+ let chunk;
76
+ while (typeof (chunk = snapshot.read()) === 'string') {
77
+ builder.acceptChunk(chunk);
78
+ }
79
+ return builder.finish();
80
+ }
81
+ function createTextBuffer(value, defaultEOL) {
82
+ let factory;
83
+ if (typeof value === 'string') {
84
+ factory = createTextBufferFactory(value);
85
+ }
86
+ else if (isITextSnapshot(value)) {
87
+ factory = createTextBufferFactoryFromSnapshot(value);
88
+ }
89
+ else {
90
+ factory = value;
91
+ }
92
+ return factory.create(defaultEOL);
93
+ }
94
+ let MODEL_ID = 0;
95
+ const LIMIT_FIND_COUNT = 999;
96
+ const LONG_LINE_BOUNDARY = 10000;
97
+ class TextModelSnapshot {
98
+ constructor(source) {
99
+ this._source = source;
100
+ this._eos = false;
101
+ }
102
+ read() {
103
+ if (this._eos) {
104
+ return null;
105
+ }
106
+ const result = [];
107
+ let resultCnt = 0;
108
+ let resultLength = 0;
109
+ do {
110
+ const tmp = this._source.read();
111
+ if (tmp === null) {
112
+ this._eos = true;
113
+ if (resultCnt === 0) {
114
+ return null;
115
+ }
116
+ else {
117
+ return result.join('');
118
+ }
119
+ }
120
+ if (tmp.length > 0) {
121
+ result[resultCnt++] = tmp;
122
+ resultLength += tmp.length;
123
+ }
124
+ if (resultLength >= 64 * 1024) {
125
+ return result.join('');
126
+ }
127
+ } while (true);
128
+ }
129
+ }
130
+ const invalidFunc = () => { throw new Error(`Invalid change accessor`); };
131
+ let TextModel = class TextModel extends Disposable {
132
+ static resolveOptions(textBuffer, options) {
133
+ if (options.detectIndentation) {
134
+ const guessedIndentation = guessIndentation(textBuffer, options.tabSize, options.insertSpaces);
135
+ return new TextModelResolvedOptions({
136
+ tabSize: guessedIndentation.tabSize,
137
+ indentSize: 'tabSize',
138
+ insertSpaces: guessedIndentation.insertSpaces,
139
+ trimAutoWhitespace: options.trimAutoWhitespace,
140
+ defaultEOL: options.defaultEOL,
141
+ bracketPairColorizationOptions: options.bracketPairColorizationOptions,
142
+ });
143
+ }
144
+ return new TextModelResolvedOptions(options);
145
+ }
146
+ get onDidChangeLanguage() { return this._tokenizationTextModelPart.onDidChangeLanguage; }
147
+ get onDidChangeLanguageConfiguration() { return this._tokenizationTextModelPart.onDidChangeLanguageConfiguration; }
148
+ get onDidChangeTokens() { return this._tokenizationTextModelPart.onDidChangeTokens; }
149
+ onDidChangeContent(listener) {
150
+ return this._eventEmitter.slowEvent((e) => listener(e.contentChangedEvent));
151
+ }
152
+ onDidChangeContentOrInjectedText(listener) {
153
+ return combinedDisposable(this._eventEmitter.fastEvent(e => listener(e)), this._onDidChangeInjectedText.event(e => listener(e)));
154
+ }
155
+ _isDisposing() { return this.__isDisposing; }
156
+ get tokenization() { return this._tokenizationTextModelPart; }
157
+ get bracketPairs() { return this._bracketPairs; }
158
+ get guides() { return this._guidesTextModelPart; }
159
+ constructor(source, languageId, creationOptions, associatedResource = null, _undoRedoService, _languageService, _languageConfigurationService) {
160
+ super();
161
+ this._undoRedoService = _undoRedoService;
162
+ this._languageService = _languageService;
163
+ this._languageConfigurationService = _languageConfigurationService;
164
+ this._onWillDispose = this._register(( (new Emitter())));
165
+ this.onWillDispose = this._onWillDispose.event;
166
+ this._onDidChangeDecorations = this._register(( (new DidChangeDecorationsEmitter(
167
+ affectedInjectedTextLines => this.handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines)
168
+ ))));
169
+ this.onDidChangeDecorations = this._onDidChangeDecorations.event;
170
+ this._onDidChangeOptions = this._register(( (new Emitter())));
171
+ this.onDidChangeOptions = this._onDidChangeOptions.event;
172
+ this._onDidChangeAttached = this._register(( (new Emitter())));
173
+ this.onDidChangeAttached = this._onDidChangeAttached.event;
174
+ this._onDidChangeInjectedText = this._register(( (new Emitter())));
175
+ this._eventEmitter = this._register(( (new DidChangeContentEmitter())));
176
+ this._deltaDecorationCallCnt = 0;
177
+ MODEL_ID++;
178
+ this.id = '$model' + MODEL_ID;
179
+ this.isForSimpleWidget = creationOptions.isForSimpleWidget;
180
+ if (typeof associatedResource === 'undefined' || associatedResource === null) {
181
+ this._associatedResource = ( (URI.parse('inmemory://model/' + MODEL_ID)));
182
+ }
183
+ else {
184
+ this._associatedResource = associatedResource;
185
+ }
186
+ this._attachedEditorCount = 0;
187
+ const { textBuffer, disposable } = createTextBuffer(source, creationOptions.defaultEOL);
188
+ this._buffer = textBuffer;
189
+ this._bufferDisposable = disposable;
190
+ this._options = TextModel.resolveOptions(this._buffer, creationOptions);
191
+ this._bracketPairs = this._register(( (new BracketPairsTextModelPart(this, this._languageConfigurationService))));
192
+ this._guidesTextModelPart = this._register(( (new GuidesTextModelPart(this, this._languageConfigurationService))));
193
+ this._decorationProvider = this._register(( (new ColorizedBracketPairsDecorationProvider(this))));
194
+ this._tokenizationTextModelPart = ( (new TokenizationTextModelPart(
195
+ this._languageService,
196
+ this._languageConfigurationService,
197
+ this,
198
+ this._bracketPairs,
199
+ languageId
200
+ )));
201
+ const bufferLineCount = this._buffer.getLineCount();
202
+ const bufferTextLength = this._buffer.getValueLengthInRange(( (new Range(1, 1, bufferLineCount, this._buffer.getLineLength(bufferLineCount) + 1))), 0 );
203
+ if (creationOptions.largeFileOptimizations) {
204
+ this._isTooLargeForTokenization = ((bufferTextLength > TextModel.LARGE_FILE_SIZE_THRESHOLD)
205
+ || (bufferLineCount > TextModel.LARGE_FILE_LINE_COUNT_THRESHOLD));
206
+ }
207
+ else {
208
+ this._isTooLargeForTokenization = false;
209
+ }
210
+ this._isTooLargeForSyncing = (bufferTextLength > TextModel._MODEL_SYNC_LIMIT);
211
+ this._versionId = 1;
212
+ this._alternativeVersionId = 1;
213
+ this._initialUndoRedoSnapshot = null;
214
+ this._isDisposed = false;
215
+ this.__isDisposing = false;
216
+ this._instanceId = singleLetterHash(MODEL_ID);
217
+ this._lastDecorationId = 0;
218
+ this._decorations = Object.create(null);
219
+ this._decorationsTree = ( (new DecorationsTrees()));
220
+ this._commandManager = ( (new EditStack(this, this._undoRedoService)));
221
+ this._isUndoing = false;
222
+ this._isRedoing = false;
223
+ this._trimAutoWhitespaceLines = null;
224
+ this._register(this._decorationProvider.onDidChange(() => {
225
+ this._onDidChangeDecorations.beginDeferredEmit();
226
+ this._onDidChangeDecorations.fire();
227
+ this._onDidChangeDecorations.endDeferredEmit();
228
+ }));
229
+ }
230
+ dispose() {
231
+ this.__isDisposing = true;
232
+ this._onWillDispose.fire();
233
+ this._tokenizationTextModelPart.dispose();
234
+ this._isDisposed = true;
235
+ super.dispose();
236
+ this._bufferDisposable.dispose();
237
+ this.__isDisposing = false;
238
+ const emptyDisposedTextBuffer = ( (new PieceTreeTextBuffer([], '', '\n', false, false, true, true)));
239
+ emptyDisposedTextBuffer.dispose();
240
+ this._buffer = emptyDisposedTextBuffer;
241
+ this._bufferDisposable = Disposable.None;
242
+ }
243
+ _hasListeners() {
244
+ return (this._onWillDispose.hasListeners()
245
+ || this._onDidChangeDecorations.hasListeners()
246
+ || this._tokenizationTextModelPart._hasListeners()
247
+ || this._onDidChangeOptions.hasListeners()
248
+ || this._onDidChangeAttached.hasListeners()
249
+ || this._onDidChangeInjectedText.hasListeners()
250
+ || this._eventEmitter.hasListeners());
251
+ }
252
+ _assertNotDisposed() {
253
+ if (this._isDisposed) {
254
+ throw new Error('Model is disposed!');
255
+ }
256
+ }
257
+ equalsTextBuffer(other) {
258
+ this._assertNotDisposed();
259
+ return this._buffer.equals(other);
260
+ }
261
+ getTextBuffer() {
262
+ this._assertNotDisposed();
263
+ return this._buffer;
264
+ }
265
+ _emitContentChangedEvent(rawChange, change) {
266
+ if (this.__isDisposing) {
267
+ return;
268
+ }
269
+ this._tokenizationTextModelPart.handleDidChangeContent(change);
270
+ this._bracketPairs.handleDidChangeContent(change);
271
+ this._eventEmitter.fire(( (new InternalModelContentChangeEvent(rawChange, change))));
272
+ }
273
+ setValue(value) {
274
+ this._assertNotDisposed();
275
+ if (value === null || value === undefined) {
276
+ throw illegalArgument();
277
+ }
278
+ const { textBuffer, disposable } = createTextBuffer(value, this._options.defaultEOL);
279
+ this._setValueFromTextBuffer(textBuffer, disposable);
280
+ }
281
+ _createContentChanged2(range, rangeOffset, rangeLength, text, isUndoing, isRedoing, isFlush) {
282
+ return {
283
+ changes: [{
284
+ range: range,
285
+ rangeOffset: rangeOffset,
286
+ rangeLength: rangeLength,
287
+ text: text,
288
+ }],
289
+ eol: this._buffer.getEOL(),
290
+ versionId: this.getVersionId(),
291
+ isUndoing: isUndoing,
292
+ isRedoing: isRedoing,
293
+ isFlush: isFlush
294
+ };
295
+ }
296
+ _setValueFromTextBuffer(textBuffer, textBufferDisposable) {
297
+ this._assertNotDisposed();
298
+ const oldFullModelRange = this.getFullModelRange();
299
+ const oldModelValueLength = this.getValueLengthInRange(oldFullModelRange);
300
+ const endLineNumber = this.getLineCount();
301
+ const endColumn = this.getLineMaxColumn(endLineNumber);
302
+ this._buffer = textBuffer;
303
+ this._bufferDisposable.dispose();
304
+ this._bufferDisposable = textBufferDisposable;
305
+ this._increaseVersionId();
306
+ this._tokenizationTextModelPart.flush();
307
+ this._decorations = Object.create(null);
308
+ this._decorationsTree = ( (new DecorationsTrees()));
309
+ this._commandManager.clear();
310
+ this._trimAutoWhitespaceLines = null;
311
+ this._emitContentChangedEvent(( (new ModelRawContentChangedEvent([
312
+ ( (new ModelRawFlush()))
313
+ ], this._versionId, false, false))), this._createContentChanged2(( (new Range(1, 1, endLineNumber, endColumn))), 0, oldModelValueLength, this.getValue(), false, false, true));
314
+ }
315
+ setEOL(eol) {
316
+ this._assertNotDisposed();
317
+ const newEOL = (eol === 1 ? '\r\n' : '\n');
318
+ if (this._buffer.getEOL() === newEOL) {
319
+ return;
320
+ }
321
+ const oldFullModelRange = this.getFullModelRange();
322
+ const oldModelValueLength = this.getValueLengthInRange(oldFullModelRange);
323
+ const endLineNumber = this.getLineCount();
324
+ const endColumn = this.getLineMaxColumn(endLineNumber);
325
+ this._onBeforeEOLChange();
326
+ this._buffer.setEOL(newEOL);
327
+ this._increaseVersionId();
328
+ this._onAfterEOLChange();
329
+ this._emitContentChangedEvent(( (new ModelRawContentChangedEvent([
330
+ ( (new ModelRawEOLChanged()))
331
+ ], this._versionId, false, false))), this._createContentChanged2(( (new Range(1, 1, endLineNumber, endColumn))), 0, oldModelValueLength, this.getValue(), false, false, false));
332
+ }
333
+ _onBeforeEOLChange() {
334
+ this._decorationsTree.ensureAllNodesHaveRanges(this);
335
+ }
336
+ _onAfterEOLChange() {
337
+ const versionId = this.getVersionId();
338
+ const allDecorations = this._decorationsTree.collectNodesPostOrder();
339
+ for (let i = 0, len = allDecorations.length; i < len; i++) {
340
+ const node = allDecorations[i];
341
+ const range = node.range;
342
+ const delta = node.cachedAbsoluteStart - node.start;
343
+ const startOffset = this._buffer.getOffsetAt(range.startLineNumber, range.startColumn);
344
+ const endOffset = this._buffer.getOffsetAt(range.endLineNumber, range.endColumn);
345
+ node.cachedAbsoluteStart = startOffset;
346
+ node.cachedAbsoluteEnd = endOffset;
347
+ node.cachedVersionId = versionId;
348
+ node.start = startOffset - delta;
349
+ node.end = endOffset - delta;
350
+ recomputeMaxEnd(node);
351
+ }
352
+ }
353
+ onBeforeAttached() {
354
+ this._attachedEditorCount++;
355
+ if (this._attachedEditorCount === 1) {
356
+ this._tokenizationTextModelPart.handleDidChangeAttached();
357
+ this._onDidChangeAttached.fire(undefined);
358
+ }
359
+ }
360
+ onBeforeDetached() {
361
+ this._attachedEditorCount--;
362
+ if (this._attachedEditorCount === 0) {
363
+ this._tokenizationTextModelPart.handleDidChangeAttached();
364
+ this._onDidChangeAttached.fire(undefined);
365
+ }
366
+ }
367
+ isAttachedToEditor() {
368
+ return this._attachedEditorCount > 0;
369
+ }
370
+ getAttachedEditorCount() {
371
+ return this._attachedEditorCount;
372
+ }
373
+ isTooLargeForSyncing() {
374
+ return this._isTooLargeForSyncing;
375
+ }
376
+ isTooLargeForTokenization() {
377
+ return this._isTooLargeForTokenization;
378
+ }
379
+ isDisposed() {
380
+ return this._isDisposed;
381
+ }
382
+ isDominatedByLongLines() {
383
+ this._assertNotDisposed();
384
+ if (this.isTooLargeForTokenization()) {
385
+ return false;
386
+ }
387
+ let smallLineCharCount = 0;
388
+ let longLineCharCount = 0;
389
+ const lineCount = this._buffer.getLineCount();
390
+ for (let lineNumber = 1; lineNumber <= lineCount; lineNumber++) {
391
+ const lineLength = this._buffer.getLineLength(lineNumber);
392
+ if (lineLength >= LONG_LINE_BOUNDARY) {
393
+ longLineCharCount += lineLength;
394
+ }
395
+ else {
396
+ smallLineCharCount += lineLength;
397
+ }
398
+ }
399
+ return (longLineCharCount > smallLineCharCount);
400
+ }
401
+ get uri() {
402
+ return this._associatedResource;
403
+ }
404
+ getOptions() {
405
+ this._assertNotDisposed();
406
+ return this._options;
407
+ }
408
+ getFormattingOptions() {
409
+ return {
410
+ tabSize: this._options.indentSize,
411
+ insertSpaces: this._options.insertSpaces
412
+ };
413
+ }
414
+ updateOptions(_newOpts) {
415
+ this._assertNotDisposed();
416
+ const tabSize = (typeof _newOpts.tabSize !== 'undefined') ? _newOpts.tabSize : this._options.tabSize;
417
+ const indentSize = (typeof _newOpts.indentSize !== 'undefined') ? _newOpts.indentSize : this._options.originalIndentSize;
418
+ const insertSpaces = (typeof _newOpts.insertSpaces !== 'undefined') ? _newOpts.insertSpaces : this._options.insertSpaces;
419
+ const trimAutoWhitespace = (typeof _newOpts.trimAutoWhitespace !== 'undefined') ? _newOpts.trimAutoWhitespace : this._options.trimAutoWhitespace;
420
+ const bracketPairColorizationOptions = (typeof _newOpts.bracketColorizationOptions !== 'undefined') ? _newOpts.bracketColorizationOptions : this._options.bracketPairColorizationOptions;
421
+ const newOpts = new TextModelResolvedOptions({
422
+ tabSize: tabSize,
423
+ indentSize: indentSize,
424
+ insertSpaces: insertSpaces,
425
+ defaultEOL: this._options.defaultEOL,
426
+ trimAutoWhitespace: trimAutoWhitespace,
427
+ bracketPairColorizationOptions,
428
+ });
429
+ if (this._options.equals(newOpts)) {
430
+ return;
431
+ }
432
+ const e = this._options.createChangeEvent(newOpts);
433
+ this._options = newOpts;
434
+ this._bracketPairs.handleDidChangeOptions(e);
435
+ this._decorationProvider.handleDidChangeOptions(e);
436
+ this._onDidChangeOptions.fire(e);
437
+ }
438
+ detectIndentation(defaultInsertSpaces, defaultTabSize) {
439
+ this._assertNotDisposed();
440
+ const guessedIndentation = guessIndentation(this._buffer, defaultTabSize, defaultInsertSpaces);
441
+ this.updateOptions({
442
+ insertSpaces: guessedIndentation.insertSpaces,
443
+ tabSize: guessedIndentation.tabSize,
444
+ indentSize: guessedIndentation.tabSize,
445
+ });
446
+ }
447
+ normalizeIndentation(str) {
448
+ this._assertNotDisposed();
449
+ return normalizeIndentation(str, this._options.indentSize, this._options.insertSpaces);
450
+ }
451
+ getVersionId() {
452
+ this._assertNotDisposed();
453
+ return this._versionId;
454
+ }
455
+ mightContainRTL() {
456
+ return this._buffer.mightContainRTL();
457
+ }
458
+ mightContainUnusualLineTerminators() {
459
+ return this._buffer.mightContainUnusualLineTerminators();
460
+ }
461
+ removeUnusualLineTerminators(selections = null) {
462
+ const matches = this.findMatches(UNUSUAL_LINE_TERMINATORS.source, false, true, false, null, false, 1073741824 );
463
+ this._buffer.resetMightContainUnusualLineTerminators();
464
+ this.pushEditOperations(selections, ( (matches.map(m => ({ range: m.range, text: null })))), () => null);
465
+ }
466
+ mightContainNonBasicASCII() {
467
+ return this._buffer.mightContainNonBasicASCII();
468
+ }
469
+ getAlternativeVersionId() {
470
+ this._assertNotDisposed();
471
+ return this._alternativeVersionId;
472
+ }
473
+ getInitialUndoRedoSnapshot() {
474
+ this._assertNotDisposed();
475
+ return this._initialUndoRedoSnapshot;
476
+ }
477
+ getOffsetAt(rawPosition) {
478
+ this._assertNotDisposed();
479
+ const position = this._validatePosition(rawPosition.lineNumber, rawPosition.column, 0 );
480
+ return this._buffer.getOffsetAt(position.lineNumber, position.column);
481
+ }
482
+ getPositionAt(rawOffset) {
483
+ this._assertNotDisposed();
484
+ const offset = (Math.min(this._buffer.getLength(), Math.max(0, rawOffset)));
485
+ return this._buffer.getPositionAt(offset);
486
+ }
487
+ _increaseVersionId() {
488
+ this._versionId = this._versionId + 1;
489
+ this._alternativeVersionId = this._versionId;
490
+ }
491
+ _overwriteVersionId(versionId) {
492
+ this._versionId = versionId;
493
+ }
494
+ _overwriteAlternativeVersionId(newAlternativeVersionId) {
495
+ this._alternativeVersionId = newAlternativeVersionId;
496
+ }
497
+ _overwriteInitialUndoRedoSnapshot(newInitialUndoRedoSnapshot) {
498
+ this._initialUndoRedoSnapshot = newInitialUndoRedoSnapshot;
499
+ }
500
+ getValue(eol, preserveBOM = false) {
501
+ this._assertNotDisposed();
502
+ const fullModelRange = this.getFullModelRange();
503
+ const fullModelValue = this.getValueInRange(fullModelRange, eol);
504
+ if (preserveBOM) {
505
+ return this._buffer.getBOM() + fullModelValue;
506
+ }
507
+ return fullModelValue;
508
+ }
509
+ createSnapshot(preserveBOM = false) {
510
+ return (
511
+ (new TextModelSnapshot(this._buffer.createSnapshot(preserveBOM)))
512
+ );
513
+ }
514
+ getValueLength(eol, preserveBOM = false) {
515
+ this._assertNotDisposed();
516
+ const fullModelRange = this.getFullModelRange();
517
+ const fullModelValue = this.getValueLengthInRange(fullModelRange, eol);
518
+ if (preserveBOM) {
519
+ return this._buffer.getBOM().length + fullModelValue;
520
+ }
521
+ return fullModelValue;
522
+ }
523
+ getValueInRange(rawRange, eol = 0 ) {
524
+ this._assertNotDisposed();
525
+ return this._buffer.getValueInRange(this.validateRange(rawRange), eol);
526
+ }
527
+ getValueLengthInRange(rawRange, eol = 0 ) {
528
+ this._assertNotDisposed();
529
+ return this._buffer.getValueLengthInRange(this.validateRange(rawRange), eol);
530
+ }
531
+ getCharacterCountInRange(rawRange, eol = 0 ) {
532
+ this._assertNotDisposed();
533
+ return this._buffer.getCharacterCountInRange(this.validateRange(rawRange), eol);
534
+ }
535
+ getLineCount() {
536
+ this._assertNotDisposed();
537
+ return this._buffer.getLineCount();
538
+ }
539
+ getLineContent(lineNumber) {
540
+ this._assertNotDisposed();
541
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
542
+ throw new Error('Illegal value for lineNumber');
543
+ }
544
+ return this._buffer.getLineContent(lineNumber);
545
+ }
546
+ getLineLength(lineNumber) {
547
+ this._assertNotDisposed();
548
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
549
+ throw new Error('Illegal value for lineNumber');
550
+ }
551
+ return this._buffer.getLineLength(lineNumber);
552
+ }
553
+ getLinesContent() {
554
+ this._assertNotDisposed();
555
+ return this._buffer.getLinesContent();
556
+ }
557
+ getEOL() {
558
+ this._assertNotDisposed();
559
+ return this._buffer.getEOL();
560
+ }
561
+ getEndOfLineSequence() {
562
+ this._assertNotDisposed();
563
+ return (this._buffer.getEOL() === '\n' ? 0 : 1) ;
564
+ }
565
+ getLineMinColumn(lineNumber) {
566
+ this._assertNotDisposed();
567
+ return 1;
568
+ }
569
+ getLineMaxColumn(lineNumber) {
570
+ this._assertNotDisposed();
571
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
572
+ throw new Error('Illegal value for lineNumber');
573
+ }
574
+ return this._buffer.getLineLength(lineNumber) + 1;
575
+ }
576
+ getLineFirstNonWhitespaceColumn(lineNumber) {
577
+ this._assertNotDisposed();
578
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
579
+ throw new Error('Illegal value for lineNumber');
580
+ }
581
+ return this._buffer.getLineFirstNonWhitespaceColumn(lineNumber);
582
+ }
583
+ getLineLastNonWhitespaceColumn(lineNumber) {
584
+ this._assertNotDisposed();
585
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
586
+ throw new Error('Illegal value for lineNumber');
587
+ }
588
+ return this._buffer.getLineLastNonWhitespaceColumn(lineNumber);
589
+ }
590
+ _validateRangeRelaxedNoAllocations(range) {
591
+ const linesCount = this._buffer.getLineCount();
592
+ const initialStartLineNumber = range.startLineNumber;
593
+ const initialStartColumn = range.startColumn;
594
+ let startLineNumber = Math.floor((typeof initialStartLineNumber === 'number' && !isNaN(initialStartLineNumber)) ? initialStartLineNumber : 1);
595
+ let startColumn = Math.floor((typeof initialStartColumn === 'number' && !isNaN(initialStartColumn)) ? initialStartColumn : 1);
596
+ if (startLineNumber < 1) {
597
+ startLineNumber = 1;
598
+ startColumn = 1;
599
+ }
600
+ else if (startLineNumber > linesCount) {
601
+ startLineNumber = linesCount;
602
+ startColumn = this.getLineMaxColumn(startLineNumber);
603
+ }
604
+ else {
605
+ if (startColumn <= 1) {
606
+ startColumn = 1;
607
+ }
608
+ else {
609
+ const maxColumn = this.getLineMaxColumn(startLineNumber);
610
+ if (startColumn >= maxColumn) {
611
+ startColumn = maxColumn;
612
+ }
613
+ }
614
+ }
615
+ const initialEndLineNumber = range.endLineNumber;
616
+ const initialEndColumn = range.endColumn;
617
+ let endLineNumber = Math.floor((typeof initialEndLineNumber === 'number' && !isNaN(initialEndLineNumber)) ? initialEndLineNumber : 1);
618
+ let endColumn = Math.floor((typeof initialEndColumn === 'number' && !isNaN(initialEndColumn)) ? initialEndColumn : 1);
619
+ if (endLineNumber < 1) {
620
+ endLineNumber = 1;
621
+ endColumn = 1;
622
+ }
623
+ else if (endLineNumber > linesCount) {
624
+ endLineNumber = linesCount;
625
+ endColumn = this.getLineMaxColumn(endLineNumber);
626
+ }
627
+ else {
628
+ if (endColumn <= 1) {
629
+ endColumn = 1;
630
+ }
631
+ else {
632
+ const maxColumn = this.getLineMaxColumn(endLineNumber);
633
+ if (endColumn >= maxColumn) {
634
+ endColumn = maxColumn;
635
+ }
636
+ }
637
+ }
638
+ if (initialStartLineNumber === startLineNumber
639
+ && initialStartColumn === startColumn
640
+ && initialEndLineNumber === endLineNumber
641
+ && initialEndColumn === endColumn
642
+ && range instanceof Range
643
+ && !(range instanceof Selection)) {
644
+ return range;
645
+ }
646
+ return (
647
+ (new Range(startLineNumber, startColumn, endLineNumber, endColumn))
648
+ );
649
+ }
650
+ _isValidPosition(lineNumber, column, validationType) {
651
+ if (typeof lineNumber !== 'number' || typeof column !== 'number') {
652
+ return false;
653
+ }
654
+ if (isNaN(lineNumber) || isNaN(column)) {
655
+ return false;
656
+ }
657
+ if (lineNumber < 1 || column < 1) {
658
+ return false;
659
+ }
660
+ if ((lineNumber | 0) !== lineNumber || (column | 0) !== column) {
661
+ return false;
662
+ }
663
+ const lineCount = this._buffer.getLineCount();
664
+ if (lineNumber > lineCount) {
665
+ return false;
666
+ }
667
+ if (column === 1) {
668
+ return true;
669
+ }
670
+ const maxColumn = this.getLineMaxColumn(lineNumber);
671
+ if (column > maxColumn) {
672
+ return false;
673
+ }
674
+ if (validationType === 1 ) {
675
+ const charCodeBefore = this._buffer.getLineCharCode(lineNumber, column - 2);
676
+ if (isHighSurrogate(charCodeBefore)) {
677
+ return false;
678
+ }
679
+ }
680
+ return true;
681
+ }
682
+ _validatePosition(_lineNumber, _column, validationType) {
683
+ const lineNumber = Math.floor((typeof _lineNumber === 'number' && !isNaN(_lineNumber)) ? _lineNumber : 1);
684
+ const column = Math.floor((typeof _column === 'number' && !isNaN(_column)) ? _column : 1);
685
+ const lineCount = this._buffer.getLineCount();
686
+ if (lineNumber < 1) {
687
+ return (
688
+ (new Position(1, 1))
689
+ );
690
+ }
691
+ if (lineNumber > lineCount) {
692
+ return (
693
+ (new Position(lineCount, this.getLineMaxColumn(lineCount)))
694
+ );
695
+ }
696
+ if (column <= 1) {
697
+ return (
698
+ (new Position(lineNumber, 1))
699
+ );
700
+ }
701
+ const maxColumn = this.getLineMaxColumn(lineNumber);
702
+ if (column >= maxColumn) {
703
+ return (
704
+ (new Position(lineNumber, maxColumn))
705
+ );
706
+ }
707
+ if (validationType === 1 ) {
708
+ const charCodeBefore = this._buffer.getLineCharCode(lineNumber, column - 2);
709
+ if (isHighSurrogate(charCodeBefore)) {
710
+ return (
711
+ (new Position(lineNumber, column - 1))
712
+ );
713
+ }
714
+ }
715
+ return (
716
+ (new Position(lineNumber, column))
717
+ );
718
+ }
719
+ validatePosition(position) {
720
+ const validationType = 1 ;
721
+ this._assertNotDisposed();
722
+ if (position instanceof Position) {
723
+ if (this._isValidPosition(position.lineNumber, position.column, validationType)) {
724
+ return position;
725
+ }
726
+ }
727
+ return this._validatePosition(position.lineNumber, position.column, validationType);
728
+ }
729
+ _isValidRange(range, validationType) {
730
+ const startLineNumber = range.startLineNumber;
731
+ const startColumn = range.startColumn;
732
+ const endLineNumber = range.endLineNumber;
733
+ const endColumn = range.endColumn;
734
+ if (!this._isValidPosition(startLineNumber, startColumn, 0 )) {
735
+ return false;
736
+ }
737
+ if (!this._isValidPosition(endLineNumber, endColumn, 0 )) {
738
+ return false;
739
+ }
740
+ if (validationType === 1 ) {
741
+ const charCodeBeforeStart = (startColumn > 1 ? this._buffer.getLineCharCode(startLineNumber, startColumn - 2) : 0);
742
+ const charCodeBeforeEnd = (endColumn > 1 && endColumn <= this._buffer.getLineLength(endLineNumber) ? this._buffer.getLineCharCode(endLineNumber, endColumn - 2) : 0);
743
+ const startInsideSurrogatePair = isHighSurrogate(charCodeBeforeStart);
744
+ const endInsideSurrogatePair = isHighSurrogate(charCodeBeforeEnd);
745
+ if (!startInsideSurrogatePair && !endInsideSurrogatePair) {
746
+ return true;
747
+ }
748
+ return false;
749
+ }
750
+ return true;
751
+ }
752
+ validateRange(_range) {
753
+ const validationType = 1 ;
754
+ this._assertNotDisposed();
755
+ if ((_range instanceof Range) && !(_range instanceof Selection)) {
756
+ if (this._isValidRange(_range, validationType)) {
757
+ return _range;
758
+ }
759
+ }
760
+ const start = this._validatePosition(_range.startLineNumber, _range.startColumn, 0 );
761
+ const end = this._validatePosition(_range.endLineNumber, _range.endColumn, 0 );
762
+ const startLineNumber = start.lineNumber;
763
+ const startColumn = start.column;
764
+ const endLineNumber = end.lineNumber;
765
+ const endColumn = end.column;
766
+ {
767
+ const charCodeBeforeStart = (startColumn > 1 ? this._buffer.getLineCharCode(startLineNumber, startColumn - 2) : 0);
768
+ const charCodeBeforeEnd = (endColumn > 1 && endColumn <= this._buffer.getLineLength(endLineNumber) ? this._buffer.getLineCharCode(endLineNumber, endColumn - 2) : 0);
769
+ const startInsideSurrogatePair = isHighSurrogate(charCodeBeforeStart);
770
+ const endInsideSurrogatePair = isHighSurrogate(charCodeBeforeEnd);
771
+ if (!startInsideSurrogatePair && !endInsideSurrogatePair) {
772
+ return (
773
+ (new Range(startLineNumber, startColumn, endLineNumber, endColumn))
774
+ );
775
+ }
776
+ if (startLineNumber === endLineNumber && startColumn === endColumn) {
777
+ return (
778
+ (new Range(startLineNumber, startColumn - 1, endLineNumber, endColumn - 1))
779
+ );
780
+ }
781
+ if (startInsideSurrogatePair && endInsideSurrogatePair) {
782
+ return (
783
+ (new Range(startLineNumber, startColumn - 1, endLineNumber, endColumn + 1))
784
+ );
785
+ }
786
+ if (startInsideSurrogatePair) {
787
+ return (
788
+ (new Range(startLineNumber, startColumn - 1, endLineNumber, endColumn))
789
+ );
790
+ }
791
+ return (
792
+ (new Range(startLineNumber, startColumn, endLineNumber, endColumn + 1))
793
+ );
794
+ }
795
+ }
796
+ modifyPosition(rawPosition, offset) {
797
+ this._assertNotDisposed();
798
+ const candidate = this.getOffsetAt(rawPosition) + offset;
799
+ return this.getPositionAt(Math.min(this._buffer.getLength(), Math.max(0, candidate)));
800
+ }
801
+ getFullModelRange() {
802
+ this._assertNotDisposed();
803
+ const lineCount = this.getLineCount();
804
+ return (
805
+ (new Range(1, 1, lineCount, this.getLineMaxColumn(lineCount)))
806
+ );
807
+ }
808
+ findMatchesLineByLine(searchRange, searchData, captureMatches, limitResultCount) {
809
+ return this._buffer.findMatchesLineByLine(searchRange, searchData, captureMatches, limitResultCount);
810
+ }
811
+ findMatches(searchString, rawSearchScope, isRegex, matchCase, wordSeparators, captureMatches, limitResultCount = LIMIT_FIND_COUNT) {
812
+ this._assertNotDisposed();
813
+ let searchRanges = null;
814
+ if (rawSearchScope !== null) {
815
+ if (!Array.isArray(rawSearchScope)) {
816
+ rawSearchScope = [rawSearchScope];
817
+ }
818
+ if (rawSearchScope.every((searchScope) => Range.isIRange(searchScope))) {
819
+ searchRanges = ( (rawSearchScope.map((searchScope) => this.validateRange(searchScope))));
820
+ }
821
+ }
822
+ if (searchRanges === null) {
823
+ searchRanges = [this.getFullModelRange()];
824
+ }
825
+ searchRanges = searchRanges.sort((d1, d2) => d1.startLineNumber - d2.startLineNumber || d1.startColumn - d2.startColumn);
826
+ const uniqueSearchRanges = [];
827
+ uniqueSearchRanges.push(searchRanges.reduce((prev, curr) => {
828
+ if (Range.areIntersecting(prev, curr)) {
829
+ return prev.plusRange(curr);
830
+ }
831
+ uniqueSearchRanges.push(prev);
832
+ return curr;
833
+ }));
834
+ let matchMapper;
835
+ if (!isRegex && searchString.indexOf('\n') < 0) {
836
+ const searchParams = ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators)));
837
+ const searchData = searchParams.parseSearchRequest();
838
+ if (!searchData) {
839
+ return [];
840
+ }
841
+ matchMapper = (searchRange) => this.findMatchesLineByLine(searchRange, searchData, captureMatches, limitResultCount);
842
+ }
843
+ else {
844
+ matchMapper = (searchRange) => TextModelSearch.findMatches(this, ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators))), searchRange, captureMatches, limitResultCount);
845
+ }
846
+ return ( (uniqueSearchRanges.map(matchMapper))).reduce((arr, matches) => arr.concat(matches), []);
847
+ }
848
+ findNextMatch(searchString, rawSearchStart, isRegex, matchCase, wordSeparators, captureMatches) {
849
+ this._assertNotDisposed();
850
+ const searchStart = this.validatePosition(rawSearchStart);
851
+ if (!isRegex && searchString.indexOf('\n') < 0) {
852
+ const searchParams = ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators)));
853
+ const searchData = searchParams.parseSearchRequest();
854
+ if (!searchData) {
855
+ return null;
856
+ }
857
+ const lineCount = this.getLineCount();
858
+ let searchRange = ( (new Range(
859
+ searchStart.lineNumber,
860
+ searchStart.column,
861
+ lineCount,
862
+ this.getLineMaxColumn(lineCount)
863
+ )));
864
+ let ret = this.findMatchesLineByLine(searchRange, searchData, captureMatches, 1);
865
+ TextModelSearch.findNextMatch(this, ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators))), searchStart, captureMatches);
866
+ if (ret.length > 0) {
867
+ return ret[0];
868
+ }
869
+ searchRange = ( (new Range(
870
+ 1,
871
+ 1,
872
+ searchStart.lineNumber,
873
+ this.getLineMaxColumn(searchStart.lineNumber)
874
+ )));
875
+ ret = this.findMatchesLineByLine(searchRange, searchData, captureMatches, 1);
876
+ if (ret.length > 0) {
877
+ return ret[0];
878
+ }
879
+ return null;
880
+ }
881
+ return TextModelSearch.findNextMatch(this, ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators))), searchStart, captureMatches);
882
+ }
883
+ findPreviousMatch(searchString, rawSearchStart, isRegex, matchCase, wordSeparators, captureMatches) {
884
+ this._assertNotDisposed();
885
+ const searchStart = this.validatePosition(rawSearchStart);
886
+ return TextModelSearch.findPreviousMatch(this, ( (new SearchParams(searchString, isRegex, matchCase, wordSeparators))), searchStart, captureMatches);
887
+ }
888
+ pushStackElement() {
889
+ this._commandManager.pushStackElement();
890
+ }
891
+ popStackElement() {
892
+ this._commandManager.popStackElement();
893
+ }
894
+ pushEOL(eol) {
895
+ const currentEOL = ((this.getEOL() === '\n' ? 0 : 1) );
896
+ if (currentEOL === eol) {
897
+ return;
898
+ }
899
+ try {
900
+ this._onDidChangeDecorations.beginDeferredEmit();
901
+ this._eventEmitter.beginDeferredEmit();
902
+ if (this._initialUndoRedoSnapshot === null) {
903
+ this._initialUndoRedoSnapshot = this._undoRedoService.createSnapshot(this.uri);
904
+ }
905
+ this._commandManager.pushEOL(eol);
906
+ }
907
+ finally {
908
+ this._eventEmitter.endDeferredEmit();
909
+ this._onDidChangeDecorations.endDeferredEmit();
910
+ }
911
+ }
912
+ _validateEditOperation(rawOperation) {
913
+ if (rawOperation instanceof ValidAnnotatedEditOperation) {
914
+ return rawOperation;
915
+ }
916
+ return new ValidAnnotatedEditOperation(rawOperation.identifier || null, this.validateRange(rawOperation.range), rawOperation.text, rawOperation.forceMoveMarkers || false, rawOperation.isAutoWhitespaceEdit || false, rawOperation._isTracked || false);
917
+ }
918
+ _validateEditOperations(rawOperations) {
919
+ const result = [];
920
+ for (let i = 0, len = rawOperations.length; i < len; i++) {
921
+ result[i] = this._validateEditOperation(rawOperations[i]);
922
+ }
923
+ return result;
924
+ }
925
+ pushEditOperations(beforeCursorState, editOperations, cursorStateComputer, group) {
926
+ try {
927
+ this._onDidChangeDecorations.beginDeferredEmit();
928
+ this._eventEmitter.beginDeferredEmit();
929
+ return this._pushEditOperations(beforeCursorState, this._validateEditOperations(editOperations), cursorStateComputer, group);
930
+ }
931
+ finally {
932
+ this._eventEmitter.endDeferredEmit();
933
+ this._onDidChangeDecorations.endDeferredEmit();
934
+ }
935
+ }
936
+ _pushEditOperations(beforeCursorState, editOperations, cursorStateComputer, group) {
937
+ if (this._options.trimAutoWhitespace && this._trimAutoWhitespaceLines) {
938
+ const incomingEdits = ( (editOperations.map((op) => {
939
+ return {
940
+ range: this.validateRange(op.range),
941
+ text: op.text
942
+ };
943
+ })));
944
+ let editsAreNearCursors = true;
945
+ if (beforeCursorState) {
946
+ for (let i = 0, len = beforeCursorState.length; i < len; i++) {
947
+ const sel = beforeCursorState[i];
948
+ let foundEditNearSel = false;
949
+ for (let j = 0, lenJ = incomingEdits.length; j < lenJ; j++) {
950
+ const editRange = incomingEdits[j].range;
951
+ const selIsAbove = editRange.startLineNumber > sel.endLineNumber;
952
+ const selIsBelow = sel.startLineNumber > editRange.endLineNumber;
953
+ if (!selIsAbove && !selIsBelow) {
954
+ foundEditNearSel = true;
955
+ break;
956
+ }
957
+ }
958
+ if (!foundEditNearSel) {
959
+ editsAreNearCursors = false;
960
+ break;
961
+ }
962
+ }
963
+ }
964
+ if (editsAreNearCursors) {
965
+ for (let i = 0, len = this._trimAutoWhitespaceLines.length; i < len; i++) {
966
+ const trimLineNumber = this._trimAutoWhitespaceLines[i];
967
+ const maxLineColumn = this.getLineMaxColumn(trimLineNumber);
968
+ let allowTrimLine = true;
969
+ for (let j = 0, lenJ = incomingEdits.length; j < lenJ; j++) {
970
+ const editRange = incomingEdits[j].range;
971
+ const editText = incomingEdits[j].text;
972
+ if (trimLineNumber < editRange.startLineNumber || trimLineNumber > editRange.endLineNumber) {
973
+ continue;
974
+ }
975
+ if (trimLineNumber === editRange.startLineNumber && editRange.startColumn === maxLineColumn
976
+ && editRange.isEmpty() && editText && editText.length > 0 && editText.charAt(0) === '\n') {
977
+ continue;
978
+ }
979
+ if (trimLineNumber === editRange.startLineNumber && editRange.startColumn === 1
980
+ && editRange.isEmpty() && editText && editText.length > 0 && editText.charAt(editText.length - 1) === '\n') {
981
+ continue;
982
+ }
983
+ allowTrimLine = false;
984
+ break;
985
+ }
986
+ if (allowTrimLine) {
987
+ const trimRange = ( (new Range(trimLineNumber, 1, trimLineNumber, maxLineColumn)));
988
+ editOperations.push(new ValidAnnotatedEditOperation(null, trimRange, null, false, false, false));
989
+ }
990
+ }
991
+ }
992
+ this._trimAutoWhitespaceLines = null;
993
+ }
994
+ if (this._initialUndoRedoSnapshot === null) {
995
+ this._initialUndoRedoSnapshot = this._undoRedoService.createSnapshot(this.uri);
996
+ }
997
+ return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer, group);
998
+ }
999
+ _applyUndo(changes, eol, resultingAlternativeVersionId, resultingSelection) {
1000
+ const edits = ( (changes.map((change) => {
1001
+ const rangeStart = this.getPositionAt(change.newPosition);
1002
+ const rangeEnd = this.getPositionAt(change.newEnd);
1003
+ return {
1004
+ range: ( (new Range(
1005
+ rangeStart.lineNumber,
1006
+ rangeStart.column,
1007
+ rangeEnd.lineNumber,
1008
+ rangeEnd.column
1009
+ ))),
1010
+ text: change.oldText
1011
+ };
1012
+ })));
1013
+ this._applyUndoRedoEdits(edits, eol, true, false, resultingAlternativeVersionId, resultingSelection);
1014
+ }
1015
+ _applyRedo(changes, eol, resultingAlternativeVersionId, resultingSelection) {
1016
+ const edits = ( (changes.map((change) => {
1017
+ const rangeStart = this.getPositionAt(change.oldPosition);
1018
+ const rangeEnd = this.getPositionAt(change.oldEnd);
1019
+ return {
1020
+ range: ( (new Range(
1021
+ rangeStart.lineNumber,
1022
+ rangeStart.column,
1023
+ rangeEnd.lineNumber,
1024
+ rangeEnd.column
1025
+ ))),
1026
+ text: change.newText
1027
+ };
1028
+ })));
1029
+ this._applyUndoRedoEdits(edits, eol, false, true, resultingAlternativeVersionId, resultingSelection);
1030
+ }
1031
+ _applyUndoRedoEdits(edits, eol, isUndoing, isRedoing, resultingAlternativeVersionId, resultingSelection) {
1032
+ try {
1033
+ this._onDidChangeDecorations.beginDeferredEmit();
1034
+ this._eventEmitter.beginDeferredEmit();
1035
+ this._isUndoing = isUndoing;
1036
+ this._isRedoing = isRedoing;
1037
+ this.applyEdits(edits, false);
1038
+ this.setEOL(eol);
1039
+ this._overwriteAlternativeVersionId(resultingAlternativeVersionId);
1040
+ }
1041
+ finally {
1042
+ this._isUndoing = false;
1043
+ this._isRedoing = false;
1044
+ this._eventEmitter.endDeferredEmit(resultingSelection);
1045
+ this._onDidChangeDecorations.endDeferredEmit();
1046
+ }
1047
+ }
1048
+ applyEdits(rawOperations, computeUndoEdits = false) {
1049
+ try {
1050
+ this._onDidChangeDecorations.beginDeferredEmit();
1051
+ this._eventEmitter.beginDeferredEmit();
1052
+ const operations = this._validateEditOperations(rawOperations);
1053
+ return this._doApplyEdits(operations, computeUndoEdits);
1054
+ }
1055
+ finally {
1056
+ this._eventEmitter.endDeferredEmit();
1057
+ this._onDidChangeDecorations.endDeferredEmit();
1058
+ }
1059
+ }
1060
+ _doApplyEdits(rawOperations, computeUndoEdits) {
1061
+ const oldLineCount = this._buffer.getLineCount();
1062
+ const result = this._buffer.applyEdits(rawOperations, this._options.trimAutoWhitespace, computeUndoEdits);
1063
+ const newLineCount = this._buffer.getLineCount();
1064
+ const contentChanges = result.changes;
1065
+ this._trimAutoWhitespaceLines = result.trimAutoWhitespaceLineNumbers;
1066
+ if (contentChanges.length !== 0) {
1067
+ for (let i = 0, len = contentChanges.length; i < len; i++) {
1068
+ const change = contentChanges[i];
1069
+ const [eolCount, firstLineLength, lastLineLength] = countEOL(change.text);
1070
+ this._tokenizationTextModelPart.acceptEdit(change.range, change.text, eolCount, firstLineLength, lastLineLength);
1071
+ this._decorationsTree.acceptReplace(change.rangeOffset, change.rangeLength, change.text.length, change.forceMoveMarkers);
1072
+ }
1073
+ const rawContentChanges = [];
1074
+ this._increaseVersionId();
1075
+ let lineCount = oldLineCount;
1076
+ for (let i = 0, len = contentChanges.length; i < len; i++) {
1077
+ const change = contentChanges[i];
1078
+ const [eolCount] = countEOL(change.text);
1079
+ this._onDidChangeDecorations.fire();
1080
+ const startLineNumber = change.range.startLineNumber;
1081
+ const endLineNumber = change.range.endLineNumber;
1082
+ const deletingLinesCnt = endLineNumber - startLineNumber;
1083
+ const insertingLinesCnt = eolCount;
1084
+ const editingLinesCnt = Math.min(deletingLinesCnt, insertingLinesCnt);
1085
+ const changeLineCountDelta = (insertingLinesCnt - deletingLinesCnt);
1086
+ const currentEditStartLineNumber = newLineCount - lineCount - changeLineCountDelta + startLineNumber;
1087
+ const firstEditLineNumber = currentEditStartLineNumber;
1088
+ const lastInsertedLineNumber = currentEditStartLineNumber + insertingLinesCnt;
1089
+ const decorationsWithInjectedTextInEditedRange = this._decorationsTree.getInjectedTextInInterval(this, this.getOffsetAt(( (new Position(firstEditLineNumber, 1)))), this.getOffsetAt(( (new Position(lastInsertedLineNumber, this.getLineMaxColumn(lastInsertedLineNumber))))), 0);
1090
+ const injectedTextInEditedRange = LineInjectedText.fromDecorations(decorationsWithInjectedTextInEditedRange);
1091
+ const injectedTextInEditedRangeQueue = ( (new ArrayQueue(injectedTextInEditedRange)));
1092
+ for (let j = editingLinesCnt; j >= 0; j--) {
1093
+ const editLineNumber = startLineNumber + j;
1094
+ const currentEditLineNumber = currentEditStartLineNumber + j;
1095
+ injectedTextInEditedRangeQueue.takeFromEndWhile(r => r.lineNumber > currentEditLineNumber);
1096
+ const decorationsInCurrentLine = injectedTextInEditedRangeQueue.takeFromEndWhile(r => r.lineNumber === currentEditLineNumber);
1097
+ rawContentChanges.push(( (new ModelRawLineChanged(
1098
+ editLineNumber,
1099
+ this.getLineContent(currentEditLineNumber),
1100
+ decorationsInCurrentLine
1101
+ ))));
1102
+ }
1103
+ if (editingLinesCnt < deletingLinesCnt) {
1104
+ const spliceStartLineNumber = startLineNumber + editingLinesCnt;
1105
+ rawContentChanges.push(( (new ModelRawLinesDeleted(spliceStartLineNumber + 1, endLineNumber))));
1106
+ }
1107
+ if (editingLinesCnt < insertingLinesCnt) {
1108
+ const injectedTextInEditedRangeQueue = ( (new ArrayQueue(injectedTextInEditedRange)));
1109
+ const spliceLineNumber = startLineNumber + editingLinesCnt;
1110
+ const cnt = insertingLinesCnt - editingLinesCnt;
1111
+ const fromLineNumber = newLineCount - lineCount - cnt + spliceLineNumber + 1;
1112
+ const injectedTexts = [];
1113
+ const newLines = [];
1114
+ for (let i = 0; i < cnt; i++) {
1115
+ const lineNumber = fromLineNumber + i;
1116
+ newLines[i] = this.getLineContent(lineNumber);
1117
+ injectedTextInEditedRangeQueue.takeWhile(r => r.lineNumber < lineNumber);
1118
+ injectedTexts[i] = injectedTextInEditedRangeQueue.takeWhile(r => r.lineNumber === lineNumber);
1119
+ }
1120
+ rawContentChanges.push(( (new ModelRawLinesInserted(
1121
+ spliceLineNumber + 1,
1122
+ startLineNumber + insertingLinesCnt,
1123
+ newLines,
1124
+ injectedTexts
1125
+ ))));
1126
+ }
1127
+ lineCount += changeLineCountDelta;
1128
+ }
1129
+ this._emitContentChangedEvent(( (new ModelRawContentChangedEvent(rawContentChanges, this.getVersionId(), this._isUndoing, this._isRedoing))), {
1130
+ changes: contentChanges,
1131
+ eol: this._buffer.getEOL(),
1132
+ versionId: this.getVersionId(),
1133
+ isUndoing: this._isUndoing,
1134
+ isRedoing: this._isRedoing,
1135
+ isFlush: false
1136
+ });
1137
+ }
1138
+ return (result.reverseEdits === null ? undefined : result.reverseEdits);
1139
+ }
1140
+ undo() {
1141
+ return this._undoRedoService.undo(this.uri);
1142
+ }
1143
+ canUndo() {
1144
+ return this._undoRedoService.canUndo(this.uri);
1145
+ }
1146
+ redo() {
1147
+ return this._undoRedoService.redo(this.uri);
1148
+ }
1149
+ canRedo() {
1150
+ return this._undoRedoService.canRedo(this.uri);
1151
+ }
1152
+ handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines) {
1153
+ if (affectedInjectedTextLines === null || affectedInjectedTextLines.size === 0) {
1154
+ return;
1155
+ }
1156
+ const affectedLines = Array.from(affectedInjectedTextLines);
1157
+ const lineChangeEvents = ( (affectedLines.map(lineNumber => ( (new ModelRawLineChanged(
1158
+ lineNumber,
1159
+ this.getLineContent(lineNumber),
1160
+ this._getInjectedTextInLine(lineNumber)
1161
+ ))))));
1162
+ this._onDidChangeInjectedText.fire(( (new ModelInjectedTextChangedEvent(lineChangeEvents))));
1163
+ }
1164
+ changeDecorations(callback, ownerId = 0) {
1165
+ this._assertNotDisposed();
1166
+ try {
1167
+ this._onDidChangeDecorations.beginDeferredEmit();
1168
+ return this._changeDecorations(ownerId, callback);
1169
+ }
1170
+ finally {
1171
+ this._onDidChangeDecorations.endDeferredEmit();
1172
+ }
1173
+ }
1174
+ _changeDecorations(ownerId, callback) {
1175
+ const changeAccessor = {
1176
+ addDecoration: (range, options) => {
1177
+ return this._deltaDecorationsImpl(ownerId, [], [{ range: range, options: options }])[0];
1178
+ },
1179
+ changeDecoration: (id, newRange) => {
1180
+ this._changeDecorationImpl(id, newRange);
1181
+ },
1182
+ changeDecorationOptions: (id, options) => {
1183
+ this._changeDecorationOptionsImpl(id, _normalizeOptions(options));
1184
+ },
1185
+ removeDecoration: (id) => {
1186
+ this._deltaDecorationsImpl(ownerId, [id], []);
1187
+ },
1188
+ deltaDecorations: (oldDecorations, newDecorations) => {
1189
+ if (oldDecorations.length === 0 && newDecorations.length === 0) {
1190
+ return [];
1191
+ }
1192
+ return this._deltaDecorationsImpl(ownerId, oldDecorations, newDecorations);
1193
+ }
1194
+ };
1195
+ let result = null;
1196
+ try {
1197
+ result = callback(changeAccessor);
1198
+ }
1199
+ catch (e) {
1200
+ onUnexpectedError(e);
1201
+ }
1202
+ changeAccessor.addDecoration = invalidFunc;
1203
+ changeAccessor.changeDecoration = invalidFunc;
1204
+ changeAccessor.changeDecorationOptions = invalidFunc;
1205
+ changeAccessor.removeDecoration = invalidFunc;
1206
+ changeAccessor.deltaDecorations = invalidFunc;
1207
+ return result;
1208
+ }
1209
+ deltaDecorations(oldDecorations, newDecorations, ownerId = 0) {
1210
+ this._assertNotDisposed();
1211
+ if (!oldDecorations) {
1212
+ oldDecorations = [];
1213
+ }
1214
+ if (oldDecorations.length === 0 && newDecorations.length === 0) {
1215
+ return [];
1216
+ }
1217
+ try {
1218
+ this._deltaDecorationCallCnt++;
1219
+ if (this._deltaDecorationCallCnt > 1) {
1220
+ console.warn(`Invoking deltaDecorations recursively could lead to leaking decorations.`);
1221
+ onUnexpectedError(( (new Error(`Invoking deltaDecorations recursively could lead to leaking decorations.`))));
1222
+ }
1223
+ this._onDidChangeDecorations.beginDeferredEmit();
1224
+ return this._deltaDecorationsImpl(ownerId, oldDecorations, newDecorations);
1225
+ }
1226
+ finally {
1227
+ this._onDidChangeDecorations.endDeferredEmit();
1228
+ this._deltaDecorationCallCnt--;
1229
+ }
1230
+ }
1231
+ _getTrackedRange(id) {
1232
+ return this.getDecorationRange(id);
1233
+ }
1234
+ _setTrackedRange(id, newRange, newStickiness) {
1235
+ const node = (id ? this._decorations[id] : null);
1236
+ if (!node) {
1237
+ if (!newRange) {
1238
+ return null;
1239
+ }
1240
+ return this._deltaDecorationsImpl(0, [], [{ range: newRange, options: TRACKED_RANGE_OPTIONS[newStickiness] }])[0];
1241
+ }
1242
+ if (!newRange) {
1243
+ this._decorationsTree.delete(node);
1244
+ delete this._decorations[node.id];
1245
+ return null;
1246
+ }
1247
+ const range = this._validateRangeRelaxedNoAllocations(newRange);
1248
+ const startOffset = this._buffer.getOffsetAt(range.startLineNumber, range.startColumn);
1249
+ const endOffset = this._buffer.getOffsetAt(range.endLineNumber, range.endColumn);
1250
+ this._decorationsTree.delete(node);
1251
+ node.reset(this.getVersionId(), startOffset, endOffset, range);
1252
+ node.setOptions(TRACKED_RANGE_OPTIONS[newStickiness]);
1253
+ this._decorationsTree.insert(node);
1254
+ return node.id;
1255
+ }
1256
+ removeAllDecorationsWithOwnerId(ownerId) {
1257
+ if (this._isDisposed) {
1258
+ return;
1259
+ }
1260
+ const nodes = this._decorationsTree.collectNodesFromOwner(ownerId);
1261
+ for (let i = 0, len = nodes.length; i < len; i++) {
1262
+ const node = nodes[i];
1263
+ this._decorationsTree.delete(node);
1264
+ delete this._decorations[node.id];
1265
+ }
1266
+ }
1267
+ getDecorationOptions(decorationId) {
1268
+ const node = this._decorations[decorationId];
1269
+ if (!node) {
1270
+ return null;
1271
+ }
1272
+ return node.options;
1273
+ }
1274
+ getDecorationRange(decorationId) {
1275
+ const node = this._decorations[decorationId];
1276
+ if (!node) {
1277
+ return null;
1278
+ }
1279
+ return this._decorationsTree.getNodeRange(this, node);
1280
+ }
1281
+ getLineDecorations(lineNumber, ownerId = 0, filterOutValidation = false) {
1282
+ if (lineNumber < 1 || lineNumber > this.getLineCount()) {
1283
+ return [];
1284
+ }
1285
+ return this.getLinesDecorations(lineNumber, lineNumber, ownerId, filterOutValidation);
1286
+ }
1287
+ getLinesDecorations(_startLineNumber, _endLineNumber, ownerId = 0, filterOutValidation = false) {
1288
+ const lineCount = this.getLineCount();
1289
+ const startLineNumber = Math.min(lineCount, Math.max(1, _startLineNumber));
1290
+ const endLineNumber = Math.min(lineCount, Math.max(1, _endLineNumber));
1291
+ const endColumn = this.getLineMaxColumn(endLineNumber);
1292
+ const range = ( (new Range(startLineNumber, 1, endLineNumber, endColumn)));
1293
+ const decorations = this._getDecorationsInRange(range, ownerId, filterOutValidation);
1294
+ pushMany(decorations, this._decorationProvider.getDecorationsInRange(range, ownerId, filterOutValidation));
1295
+ return decorations;
1296
+ }
1297
+ getDecorationsInRange(range, ownerId = 0, filterOutValidation = false, onlyMinimapDecorations = false) {
1298
+ const validatedRange = this.validateRange(range);
1299
+ const decorations = this._getDecorationsInRange(validatedRange, ownerId, filterOutValidation);
1300
+ pushMany(decorations, this._decorationProvider.getDecorationsInRange(validatedRange, ownerId, filterOutValidation, onlyMinimapDecorations));
1301
+ return decorations;
1302
+ }
1303
+ getOverviewRulerDecorations(ownerId = 0, filterOutValidation = false) {
1304
+ return this._decorationsTree.getAll(this, ownerId, filterOutValidation, true);
1305
+ }
1306
+ getInjectedTextDecorations(ownerId = 0) {
1307
+ return this._decorationsTree.getAllInjectedText(this, ownerId);
1308
+ }
1309
+ _getInjectedTextInLine(lineNumber) {
1310
+ const startOffset = this._buffer.getOffsetAt(lineNumber, 1);
1311
+ const endOffset = startOffset + this._buffer.getLineLength(lineNumber);
1312
+ const result = this._decorationsTree.getInjectedTextInInterval(this, startOffset, endOffset, 0);
1313
+ return LineInjectedText.fromDecorations(result).filter(t => t.lineNumber === lineNumber);
1314
+ }
1315
+ getAllDecorations(ownerId = 0, filterOutValidation = false) {
1316
+ let result = this._decorationsTree.getAll(this, ownerId, filterOutValidation, false);
1317
+ result = result.concat(this._decorationProvider.getAllDecorations(ownerId, filterOutValidation));
1318
+ return result;
1319
+ }
1320
+ _getDecorationsInRange(filterRange, filterOwnerId, filterOutValidation) {
1321
+ const startOffset = this._buffer.getOffsetAt(filterRange.startLineNumber, filterRange.startColumn);
1322
+ const endOffset = this._buffer.getOffsetAt(filterRange.endLineNumber, filterRange.endColumn);
1323
+ return this._decorationsTree.getAllInInterval(this, startOffset, endOffset, filterOwnerId, filterOutValidation);
1324
+ }
1325
+ getRangeAt(start, end) {
1326
+ return this._buffer.getRangeAt(start, end - start);
1327
+ }
1328
+ _changeDecorationImpl(decorationId, _range) {
1329
+ const node = this._decorations[decorationId];
1330
+ if (!node) {
1331
+ return;
1332
+ }
1333
+ if (node.options.after) {
1334
+ const oldRange = this.getDecorationRange(decorationId);
1335
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(oldRange.endLineNumber);
1336
+ }
1337
+ if (node.options.before) {
1338
+ const oldRange = this.getDecorationRange(decorationId);
1339
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(oldRange.startLineNumber);
1340
+ }
1341
+ const range = this._validateRangeRelaxedNoAllocations(_range);
1342
+ const startOffset = this._buffer.getOffsetAt(range.startLineNumber, range.startColumn);
1343
+ const endOffset = this._buffer.getOffsetAt(range.endLineNumber, range.endColumn);
1344
+ this._decorationsTree.delete(node);
1345
+ node.reset(this.getVersionId(), startOffset, endOffset, range);
1346
+ this._decorationsTree.insert(node);
1347
+ this._onDidChangeDecorations.checkAffectedAndFire(node.options);
1348
+ if (node.options.after) {
1349
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(range.endLineNumber);
1350
+ }
1351
+ if (node.options.before) {
1352
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(range.startLineNumber);
1353
+ }
1354
+ }
1355
+ _changeDecorationOptionsImpl(decorationId, options) {
1356
+ const node = this._decorations[decorationId];
1357
+ if (!node) {
1358
+ return;
1359
+ }
1360
+ const nodeWasInOverviewRuler = (node.options.overviewRuler && node.options.overviewRuler.color ? true : false);
1361
+ const nodeIsInOverviewRuler = (options.overviewRuler && options.overviewRuler.color ? true : false);
1362
+ this._onDidChangeDecorations.checkAffectedAndFire(node.options);
1363
+ this._onDidChangeDecorations.checkAffectedAndFire(options);
1364
+ if (node.options.after || options.after) {
1365
+ const nodeRange = this._decorationsTree.getNodeRange(this, node);
1366
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(nodeRange.endLineNumber);
1367
+ }
1368
+ if (node.options.before || options.before) {
1369
+ const nodeRange = this._decorationsTree.getNodeRange(this, node);
1370
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(nodeRange.startLineNumber);
1371
+ }
1372
+ if (nodeWasInOverviewRuler !== nodeIsInOverviewRuler) {
1373
+ this._decorationsTree.delete(node);
1374
+ node.setOptions(options);
1375
+ this._decorationsTree.insert(node);
1376
+ }
1377
+ else {
1378
+ node.setOptions(options);
1379
+ }
1380
+ }
1381
+ _deltaDecorationsImpl(ownerId, oldDecorationsIds, newDecorations) {
1382
+ const versionId = this.getVersionId();
1383
+ const oldDecorationsLen = oldDecorationsIds.length;
1384
+ let oldDecorationIndex = 0;
1385
+ const newDecorationsLen = newDecorations.length;
1386
+ let newDecorationIndex = 0;
1387
+ this._onDidChangeDecorations.beginDeferredEmit();
1388
+ try {
1389
+ const result = ( (new Array(newDecorationsLen)));
1390
+ while (oldDecorationIndex < oldDecorationsLen || newDecorationIndex < newDecorationsLen) {
1391
+ let node = null;
1392
+ if (oldDecorationIndex < oldDecorationsLen) {
1393
+ do {
1394
+ node = this._decorations[oldDecorationsIds[oldDecorationIndex++]];
1395
+ } while (!node && oldDecorationIndex < oldDecorationsLen);
1396
+ if (node) {
1397
+ if (node.options.after) {
1398
+ const nodeRange = this._decorationsTree.getNodeRange(this, node);
1399
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(nodeRange.endLineNumber);
1400
+ }
1401
+ if (node.options.before) {
1402
+ const nodeRange = this._decorationsTree.getNodeRange(this, node);
1403
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(nodeRange.startLineNumber);
1404
+ }
1405
+ this._decorationsTree.delete(node);
1406
+ this._onDidChangeDecorations.checkAffectedAndFire(node.options);
1407
+ }
1408
+ }
1409
+ if (newDecorationIndex < newDecorationsLen) {
1410
+ if (!node) {
1411
+ const internalDecorationId = (++this._lastDecorationId);
1412
+ const decorationId = `${this._instanceId};${internalDecorationId}`;
1413
+ node = ( (new IntervalNode(decorationId, 0, 0)));
1414
+ this._decorations[decorationId] = node;
1415
+ }
1416
+ const newDecoration = newDecorations[newDecorationIndex];
1417
+ const range = this._validateRangeRelaxedNoAllocations(newDecoration.range);
1418
+ const options = _normalizeOptions(newDecoration.options);
1419
+ const startOffset = this._buffer.getOffsetAt(range.startLineNumber, range.startColumn);
1420
+ const endOffset = this._buffer.getOffsetAt(range.endLineNumber, range.endColumn);
1421
+ node.ownerId = ownerId;
1422
+ node.reset(versionId, startOffset, endOffset, range);
1423
+ node.setOptions(options);
1424
+ if (node.options.after) {
1425
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(range.endLineNumber);
1426
+ }
1427
+ if (node.options.before) {
1428
+ this._onDidChangeDecorations.recordLineAffectedByInjectedText(range.startLineNumber);
1429
+ }
1430
+ this._onDidChangeDecorations.checkAffectedAndFire(options);
1431
+ this._decorationsTree.insert(node);
1432
+ result[newDecorationIndex] = node.id;
1433
+ newDecorationIndex++;
1434
+ }
1435
+ else {
1436
+ if (node) {
1437
+ delete this._decorations[node.id];
1438
+ }
1439
+ }
1440
+ }
1441
+ return result;
1442
+ }
1443
+ finally {
1444
+ this._onDidChangeDecorations.endDeferredEmit();
1445
+ }
1446
+ }
1447
+ getLanguageId() {
1448
+ return this.tokenization.getLanguageId();
1449
+ }
1450
+ setMode(languageId, source) {
1451
+ this.tokenization.setLanguageId(languageId, source);
1452
+ }
1453
+ getLanguageIdAtPosition(lineNumber, column) {
1454
+ return this.tokenization.getLanguageIdAtPosition(lineNumber, column);
1455
+ }
1456
+ setLineTokens(lineNumber, tokens) {
1457
+ this._tokenizationTextModelPart.setLineTokens(lineNumber, tokens);
1458
+ }
1459
+ getWordAtPosition(position) {
1460
+ return this._tokenizationTextModelPart.getWordAtPosition(position);
1461
+ }
1462
+ getWordUntilPosition(position) {
1463
+ return this._tokenizationTextModelPart.getWordUntilPosition(position);
1464
+ }
1465
+ normalizePosition(position, affinity) {
1466
+ return position;
1467
+ }
1468
+ getLineIndentColumn(lineNumber) {
1469
+ return indentOfLine(this.getLineContent(lineNumber)) + 1;
1470
+ }
1471
+ };
1472
+ TextModel._MODEL_SYNC_LIMIT = 50 * 1024 * 1024;
1473
+ TextModel.LARGE_FILE_SIZE_THRESHOLD = 20 * 1024 * 1024;
1474
+ TextModel.LARGE_FILE_LINE_COUNT_THRESHOLD = 300 * 1000;
1475
+ TextModel.DEFAULT_CREATION_OPTIONS = {
1476
+ isForSimpleWidget: false,
1477
+ tabSize: EDITOR_MODEL_DEFAULTS.tabSize,
1478
+ indentSize: EDITOR_MODEL_DEFAULTS.indentSize,
1479
+ insertSpaces: EDITOR_MODEL_DEFAULTS.insertSpaces,
1480
+ detectIndentation: false,
1481
+ defaultEOL: 1 ,
1482
+ trimAutoWhitespace: EDITOR_MODEL_DEFAULTS.trimAutoWhitespace,
1483
+ largeFileOptimizations: EDITOR_MODEL_DEFAULTS.largeFileOptimizations,
1484
+ bracketPairColorizationOptions: EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions,
1485
+ };
1486
+ TextModel = ( (__decorate([
1487
+ ( (__param(4, IUndoRedoService))),
1488
+ ( (__param(5, ILanguageService))),
1489
+ ( (__param(6, ILanguageConfigurationService)))
1490
+ ], TextModel)));
1491
+ function indentOfLine(line) {
1492
+ let indent = 0;
1493
+ for (const c of line) {
1494
+ if (c === ' ' || c === '\t') {
1495
+ indent++;
1496
+ }
1497
+ else {
1498
+ break;
1499
+ }
1500
+ }
1501
+ return indent;
1502
+ }
1503
+ function isNodeInOverviewRuler(node) {
1504
+ return (node.options.overviewRuler && node.options.overviewRuler.color ? true : false);
1505
+ }
1506
+ function isNodeInjectedText(node) {
1507
+ return !!node.options.after || !!node.options.before;
1508
+ }
1509
+ class DecorationsTrees {
1510
+ constructor() {
1511
+ this._decorationsTree0 = ( (new IntervalTree()));
1512
+ this._decorationsTree1 = ( (new IntervalTree()));
1513
+ this._injectedTextDecorationsTree = ( (new IntervalTree()));
1514
+ }
1515
+ ensureAllNodesHaveRanges(host) {
1516
+ this.getAll(host, 0, false, false);
1517
+ }
1518
+ _ensureNodesHaveRanges(host, nodes) {
1519
+ for (const node of nodes) {
1520
+ if (node.range === null) {
1521
+ node.range = host.getRangeAt(node.cachedAbsoluteStart, node.cachedAbsoluteEnd);
1522
+ }
1523
+ }
1524
+ return nodes;
1525
+ }
1526
+ getAllInInterval(host, start, end, filterOwnerId, filterOutValidation) {
1527
+ const versionId = host.getVersionId();
1528
+ const result = this._intervalSearch(start, end, filterOwnerId, filterOutValidation, versionId);
1529
+ return this._ensureNodesHaveRanges(host, result);
1530
+ }
1531
+ _intervalSearch(start, end, filterOwnerId, filterOutValidation, cachedVersionId) {
1532
+ const r0 = this._decorationsTree0.intervalSearch(start, end, filterOwnerId, filterOutValidation, cachedVersionId);
1533
+ const r1 = this._decorationsTree1.intervalSearch(start, end, filterOwnerId, filterOutValidation, cachedVersionId);
1534
+ const r2 = this._injectedTextDecorationsTree.intervalSearch(start, end, filterOwnerId, filterOutValidation, cachedVersionId);
1535
+ return r0.concat(r1).concat(r2);
1536
+ }
1537
+ getInjectedTextInInterval(host, start, end, filterOwnerId) {
1538
+ const versionId = host.getVersionId();
1539
+ const result = this._injectedTextDecorationsTree.intervalSearch(start, end, filterOwnerId, false, versionId);
1540
+ return this._ensureNodesHaveRanges(host, result).filter((i) => i.options.showIfCollapsed || !i.range.isEmpty());
1541
+ }
1542
+ getAllInjectedText(host, filterOwnerId) {
1543
+ const versionId = host.getVersionId();
1544
+ const result = this._injectedTextDecorationsTree.search(filterOwnerId, false, versionId);
1545
+ return this._ensureNodesHaveRanges(host, result).filter((i) => i.options.showIfCollapsed || !i.range.isEmpty());
1546
+ }
1547
+ getAll(host, filterOwnerId, filterOutValidation, overviewRulerOnly) {
1548
+ const versionId = host.getVersionId();
1549
+ const result = this._search(filterOwnerId, filterOutValidation, overviewRulerOnly, versionId);
1550
+ return this._ensureNodesHaveRanges(host, result);
1551
+ }
1552
+ _search(filterOwnerId, filterOutValidation, overviewRulerOnly, cachedVersionId) {
1553
+ if (overviewRulerOnly) {
1554
+ return this._decorationsTree1.search(filterOwnerId, filterOutValidation, cachedVersionId);
1555
+ }
1556
+ else {
1557
+ const r0 = this._decorationsTree0.search(filterOwnerId, filterOutValidation, cachedVersionId);
1558
+ const r1 = this._decorationsTree1.search(filterOwnerId, filterOutValidation, cachedVersionId);
1559
+ const r2 = this._injectedTextDecorationsTree.search(filterOwnerId, filterOutValidation, cachedVersionId);
1560
+ return r0.concat(r1).concat(r2);
1561
+ }
1562
+ }
1563
+ collectNodesFromOwner(ownerId) {
1564
+ const r0 = this._decorationsTree0.collectNodesFromOwner(ownerId);
1565
+ const r1 = this._decorationsTree1.collectNodesFromOwner(ownerId);
1566
+ const r2 = this._injectedTextDecorationsTree.collectNodesFromOwner(ownerId);
1567
+ return r0.concat(r1).concat(r2);
1568
+ }
1569
+ collectNodesPostOrder() {
1570
+ const r0 = this._decorationsTree0.collectNodesPostOrder();
1571
+ const r1 = this._decorationsTree1.collectNodesPostOrder();
1572
+ const r2 = this._injectedTextDecorationsTree.collectNodesPostOrder();
1573
+ return r0.concat(r1).concat(r2);
1574
+ }
1575
+ insert(node) {
1576
+ if (isNodeInjectedText(node)) {
1577
+ this._injectedTextDecorationsTree.insert(node);
1578
+ }
1579
+ else if (isNodeInOverviewRuler(node)) {
1580
+ this._decorationsTree1.insert(node);
1581
+ }
1582
+ else {
1583
+ this._decorationsTree0.insert(node);
1584
+ }
1585
+ }
1586
+ delete(node) {
1587
+ if (isNodeInjectedText(node)) {
1588
+ this._injectedTextDecorationsTree.delete(node);
1589
+ }
1590
+ else if (isNodeInOverviewRuler(node)) {
1591
+ this._decorationsTree1.delete(node);
1592
+ }
1593
+ else {
1594
+ this._decorationsTree0.delete(node);
1595
+ }
1596
+ }
1597
+ getNodeRange(host, node) {
1598
+ const versionId = host.getVersionId();
1599
+ if (node.cachedVersionId !== versionId) {
1600
+ this._resolveNode(node, versionId);
1601
+ }
1602
+ if (node.range === null) {
1603
+ node.range = host.getRangeAt(node.cachedAbsoluteStart, node.cachedAbsoluteEnd);
1604
+ }
1605
+ return node.range;
1606
+ }
1607
+ _resolveNode(node, cachedVersionId) {
1608
+ if (isNodeInjectedText(node)) {
1609
+ this._injectedTextDecorationsTree.resolveNode(node, cachedVersionId);
1610
+ }
1611
+ else if (isNodeInOverviewRuler(node)) {
1612
+ this._decorationsTree1.resolveNode(node, cachedVersionId);
1613
+ }
1614
+ else {
1615
+ this._decorationsTree0.resolveNode(node, cachedVersionId);
1616
+ }
1617
+ }
1618
+ acceptReplace(offset, length, textLength, forceMoveMarkers) {
1619
+ this._decorationsTree0.acceptReplace(offset, length, textLength, forceMoveMarkers);
1620
+ this._decorationsTree1.acceptReplace(offset, length, textLength, forceMoveMarkers);
1621
+ this._injectedTextDecorationsTree.acceptReplace(offset, length, textLength, forceMoveMarkers);
1622
+ }
1623
+ }
1624
+ function cleanClassName(className) {
1625
+ return className.replace(/[^a-z0-9\-_]/gi, ' ');
1626
+ }
1627
+ class DecorationOptions {
1628
+ constructor(options) {
1629
+ this.color = options.color || '';
1630
+ this.darkColor = options.darkColor || '';
1631
+ }
1632
+ }
1633
+ class ModelDecorationOverviewRulerOptions extends DecorationOptions {
1634
+ constructor(options) {
1635
+ super(options);
1636
+ this._resolvedColor = null;
1637
+ this.position = (typeof options.position === 'number' ? options.position : OverviewRulerLane.Center);
1638
+ }
1639
+ getColor(theme) {
1640
+ if (!this._resolvedColor) {
1641
+ if (theme.type !== 'light' && this.darkColor) {
1642
+ this._resolvedColor = this._resolveColor(this.darkColor, theme);
1643
+ }
1644
+ else {
1645
+ this._resolvedColor = this._resolveColor(this.color, theme);
1646
+ }
1647
+ }
1648
+ return this._resolvedColor;
1649
+ }
1650
+ invalidateCachedColor() {
1651
+ this._resolvedColor = null;
1652
+ }
1653
+ _resolveColor(color, theme) {
1654
+ if (typeof color === 'string') {
1655
+ return color;
1656
+ }
1657
+ const c = color ? theme.getColor(color.id) : null;
1658
+ if (!c) {
1659
+ return '';
1660
+ }
1661
+ return (
1662
+ (c.toString())
1663
+ );
1664
+ }
1665
+ }
1666
+ class ModelDecorationMinimapOptions extends DecorationOptions {
1667
+ constructor(options) {
1668
+ super(options);
1669
+ this.position = options.position;
1670
+ }
1671
+ getColor(theme) {
1672
+ if (!this._resolvedColor) {
1673
+ if (theme.type !== 'light' && this.darkColor) {
1674
+ this._resolvedColor = this._resolveColor(this.darkColor, theme);
1675
+ }
1676
+ else {
1677
+ this._resolvedColor = this._resolveColor(this.color, theme);
1678
+ }
1679
+ }
1680
+ return this._resolvedColor;
1681
+ }
1682
+ invalidateCachedColor() {
1683
+ this._resolvedColor = undefined;
1684
+ }
1685
+ _resolveColor(color, theme) {
1686
+ if (typeof color === 'string') {
1687
+ return (
1688
+ (Color.fromHex(color))
1689
+ );
1690
+ }
1691
+ return theme.getColor(color.id);
1692
+ }
1693
+ }
1694
+ class ModelDecorationInjectedTextOptions {
1695
+ static from(options) {
1696
+ if (options instanceof ModelDecorationInjectedTextOptions) {
1697
+ return options;
1698
+ }
1699
+ return (
1700
+ (new ModelDecorationInjectedTextOptions(options))
1701
+ );
1702
+ }
1703
+ constructor(options) {
1704
+ this.content = options.content || '';
1705
+ this.inlineClassName = options.inlineClassName || null;
1706
+ this.inlineClassNameAffectsLetterSpacing = options.inlineClassNameAffectsLetterSpacing || false;
1707
+ this.attachedData = options.attachedData || null;
1708
+ this.cursorStops = options.cursorStops || null;
1709
+ }
1710
+ }
1711
+ class ModelDecorationOptions {
1712
+ static register(options) {
1713
+ return (
1714
+ (new ModelDecorationOptions(options))
1715
+ );
1716
+ }
1717
+ static createDynamic(options) {
1718
+ return (
1719
+ (new ModelDecorationOptions(options))
1720
+ );
1721
+ }
1722
+ constructor(options) {
1723
+ this.description = options.description;
1724
+ this.blockClassName = options.blockClassName ? cleanClassName(options.blockClassName) : null;
1725
+ this.blockIsAfterEnd = options.blockIsAfterEnd ?? null;
1726
+ this.stickiness = options.stickiness || 0 ;
1727
+ this.zIndex = options.zIndex || 0;
1728
+ this.className = options.className ? cleanClassName(options.className) : null;
1729
+ this.hoverMessage = options.hoverMessage || null;
1730
+ this.glyphMarginHoverMessage = options.glyphMarginHoverMessage || null;
1731
+ this.isWholeLine = options.isWholeLine || false;
1732
+ this.showIfCollapsed = options.showIfCollapsed || false;
1733
+ this.collapseOnReplaceEdit = options.collapseOnReplaceEdit || false;
1734
+ this.overviewRuler = options.overviewRuler ? ( (new ModelDecorationOverviewRulerOptions(options.overviewRuler))) : null;
1735
+ this.minimap = options.minimap ? ( (new ModelDecorationMinimapOptions(options.minimap))) : null;
1736
+ this.glyphMarginClassName = options.glyphMarginClassName ? cleanClassName(options.glyphMarginClassName) : null;
1737
+ this.linesDecorationsClassName = options.linesDecorationsClassName ? cleanClassName(options.linesDecorationsClassName) : null;
1738
+ this.firstLineDecorationClassName = options.firstLineDecorationClassName ? cleanClassName(options.firstLineDecorationClassName) : null;
1739
+ this.marginClassName = options.marginClassName ? cleanClassName(options.marginClassName) : null;
1740
+ this.inlineClassName = options.inlineClassName ? cleanClassName(options.inlineClassName) : null;
1741
+ this.inlineClassNameAffectsLetterSpacing = options.inlineClassNameAffectsLetterSpacing || false;
1742
+ this.beforeContentClassName = options.beforeContentClassName ? cleanClassName(options.beforeContentClassName) : null;
1743
+ this.afterContentClassName = options.afterContentClassName ? cleanClassName(options.afterContentClassName) : null;
1744
+ this.after = options.after ? ModelDecorationInjectedTextOptions.from(options.after) : null;
1745
+ this.before = options.before ? ModelDecorationInjectedTextOptions.from(options.before) : null;
1746
+ this.hideInCommentTokens = options.hideInCommentTokens ?? false;
1747
+ this.hideInStringTokens = options.hideInStringTokens ?? false;
1748
+ }
1749
+ }
1750
+ ModelDecorationOptions.EMPTY = ModelDecorationOptions.register({ description: 'empty' });
1751
+ const TRACKED_RANGE_OPTIONS = [
1752
+ ModelDecorationOptions.register({ description: 'tracked-range-always-grows-when-typing-at-edges', stickiness: 0 }),
1753
+ ModelDecorationOptions.register({ description: 'tracked-range-never-grows-when-typing-at-edges', stickiness: 1 }),
1754
+ ModelDecorationOptions.register({ description: 'tracked-range-grows-only-when-typing-before', stickiness: 2 }),
1755
+ ModelDecorationOptions.register({ description: 'tracked-range-grows-only-when-typing-after', stickiness: 3 }),
1756
+ ];
1757
+ function _normalizeOptions(options) {
1758
+ if (options instanceof ModelDecorationOptions) {
1759
+ return options;
1760
+ }
1761
+ return ModelDecorationOptions.createDynamic(options);
1762
+ }
1763
+ class DidChangeDecorationsEmitter extends Disposable {
1764
+ constructor(handleBeforeFire) {
1765
+ super();
1766
+ this.handleBeforeFire = handleBeforeFire;
1767
+ this._actual = this._register(( (new Emitter())));
1768
+ this.event = this._actual.event;
1769
+ this._affectedInjectedTextLines = null;
1770
+ this._deferredCnt = 0;
1771
+ this._shouldFireDeferred = false;
1772
+ this._affectsMinimap = false;
1773
+ this._affectsOverviewRuler = false;
1774
+ }
1775
+ hasListeners() {
1776
+ return this._actual.hasListeners();
1777
+ }
1778
+ beginDeferredEmit() {
1779
+ this._deferredCnt++;
1780
+ }
1781
+ endDeferredEmit() {
1782
+ this._deferredCnt--;
1783
+ if (this._deferredCnt === 0) {
1784
+ if (this._shouldFireDeferred) {
1785
+ this.doFire();
1786
+ }
1787
+ this._affectedInjectedTextLines?.clear();
1788
+ this._affectedInjectedTextLines = null;
1789
+ }
1790
+ }
1791
+ recordLineAffectedByInjectedText(lineNumber) {
1792
+ if (!this._affectedInjectedTextLines) {
1793
+ this._affectedInjectedTextLines = ( (new Set()));
1794
+ }
1795
+ this._affectedInjectedTextLines.add(lineNumber);
1796
+ }
1797
+ checkAffectedAndFire(options) {
1798
+ if (!this._affectsMinimap) {
1799
+ this._affectsMinimap = options.minimap && options.minimap.position ? true : false;
1800
+ }
1801
+ if (!this._affectsOverviewRuler) {
1802
+ this._affectsOverviewRuler = options.overviewRuler && options.overviewRuler.color ? true : false;
1803
+ }
1804
+ this.tryFire();
1805
+ }
1806
+ fire() {
1807
+ this._affectsMinimap = true;
1808
+ this._affectsOverviewRuler = true;
1809
+ this.tryFire();
1810
+ }
1811
+ tryFire() {
1812
+ if (this._deferredCnt === 0) {
1813
+ this.doFire();
1814
+ }
1815
+ else {
1816
+ this._shouldFireDeferred = true;
1817
+ }
1818
+ }
1819
+ doFire() {
1820
+ this.handleBeforeFire(this._affectedInjectedTextLines);
1821
+ const event = {
1822
+ affectsMinimap: this._affectsMinimap,
1823
+ affectsOverviewRuler: this._affectsOverviewRuler
1824
+ };
1825
+ this._shouldFireDeferred = false;
1826
+ this._affectsMinimap = false;
1827
+ this._affectsOverviewRuler = false;
1828
+ this._actual.fire(event);
1829
+ }
1830
+ }
1831
+ class DidChangeContentEmitter extends Disposable {
1832
+ constructor() {
1833
+ super();
1834
+ this._fastEmitter = this._register(( (new Emitter())));
1835
+ this.fastEvent = this._fastEmitter.event;
1836
+ this._slowEmitter = this._register(( (new Emitter())));
1837
+ this.slowEvent = this._slowEmitter.event;
1838
+ this._deferredCnt = 0;
1839
+ this._deferredEvent = null;
1840
+ }
1841
+ hasListeners() {
1842
+ return (this._fastEmitter.hasListeners()
1843
+ || this._slowEmitter.hasListeners());
1844
+ }
1845
+ beginDeferredEmit() {
1846
+ this._deferredCnt++;
1847
+ }
1848
+ endDeferredEmit(resultingSelection = null) {
1849
+ this._deferredCnt--;
1850
+ if (this._deferredCnt === 0) {
1851
+ if (this._deferredEvent !== null) {
1852
+ this._deferredEvent.rawContentChangedEvent.resultingSelection = resultingSelection;
1853
+ const e = this._deferredEvent;
1854
+ this._deferredEvent = null;
1855
+ this._fastEmitter.fire(e);
1856
+ this._slowEmitter.fire(e);
1857
+ }
1858
+ }
1859
+ }
1860
+ fire(e) {
1861
+ if (this._deferredCnt > 0) {
1862
+ if (this._deferredEvent) {
1863
+ this._deferredEvent = this._deferredEvent.merge(e);
1864
+ }
1865
+ else {
1866
+ this._deferredEvent = e;
1867
+ }
1868
+ return;
1869
+ }
1870
+ this._fastEmitter.fire(e);
1871
+ this._slowEmitter.fire(e);
1872
+ }
1873
+ }
1874
+ class EditorModel extends Disposable {
1875
+ constructor() {
1876
+ super(...arguments);
1877
+ this._onWillDispose = this._register(( (new Emitter())));
1878
+ this.onWillDispose = this._onWillDispose.event;
1879
+ this.disposed = false;
1880
+ this.resolved = false;
1881
+ }
1882
+ async resolve() {
1883
+ this.resolved = true;
1884
+ }
1885
+ isResolved() {
1886
+ return this.resolved;
1887
+ }
1888
+ isDisposed() {
1889
+ return this.disposed;
1890
+ }
1891
+ dispose() {
1892
+ this.disposed = true;
1893
+ this._onWillDispose.fire();
1894
+ super.dispose();
1895
+ }
1896
+ }
1897
+ let BaseTextEditorModel = class BaseTextEditorModel extends EditorModel {
1898
+ constructor(modelService, languageService, languageDetectionService, accessibilityService, textEditorModelHandle) {
1899
+ super();
1900
+ this.modelService = modelService;
1901
+ this.languageService = languageService;
1902
+ this.languageDetectionService = languageDetectionService;
1903
+ this.accessibilityService = accessibilityService;
1904
+ this.textEditorModelHandle = undefined;
1905
+ this.modelDisposeListener = this._register(( (new MutableDisposable())));
1906
+ this.autoDetectLanguageThrottler = this._register(( (new ThrottledDelayer(BaseTextEditorModel.AUTO_DETECT_LANGUAGE_THROTTLE_DELAY))));
1907
+ this._hasLanguageSetExplicitly = false;
1908
+ if (textEditorModelHandle) {
1909
+ this.handleExistingModel(textEditorModelHandle);
1910
+ }
1911
+ }
1912
+ handleExistingModel(textEditorModelHandle) {
1913
+ const model = this.modelService.getModel(textEditorModelHandle);
1914
+ if (!model) {
1915
+ throw new Error(`Document with resource ${textEditorModelHandle.toString(true)} does not exist`);
1916
+ }
1917
+ this.textEditorModelHandle = textEditorModelHandle;
1918
+ this.registerModelDisposeListener(model);
1919
+ }
1920
+ registerModelDisposeListener(model) {
1921
+ this.modelDisposeListener.value = model.onWillDispose(() => {
1922
+ this.textEditorModelHandle = undefined;
1923
+ this.dispose();
1924
+ });
1925
+ }
1926
+ get textEditorModel() {
1927
+ return this.textEditorModelHandle ? this.modelService.getModel(this.textEditorModelHandle) : null;
1928
+ }
1929
+ isReadonly() {
1930
+ return true;
1931
+ }
1932
+ get hasLanguageSetExplicitly() { return this._hasLanguageSetExplicitly; }
1933
+ setLanguageId(languageId, source) {
1934
+ this._hasLanguageSetExplicitly = true;
1935
+ this.setLanguageIdInternal(languageId, source);
1936
+ }
1937
+ setLanguageIdInternal(languageId, source) {
1938
+ if (!this.isResolved()) {
1939
+ return;
1940
+ }
1941
+ if (!languageId || languageId === this.textEditorModel.getLanguageId()) {
1942
+ return;
1943
+ }
1944
+ this.modelService.setMode(this.textEditorModel, this.languageService.createById(languageId), source);
1945
+ }
1946
+ installModelListeners(model) {
1947
+ const disposable = this._register(model.onDidChangeLanguage((e) => {
1948
+ if (e.source === LanguageDetectionLanguageEventSource) {
1949
+ return;
1950
+ }
1951
+ this._hasLanguageSetExplicitly = true;
1952
+ disposable.dispose();
1953
+ }));
1954
+ }
1955
+ getLanguageId() {
1956
+ return this.textEditorModel?.getLanguageId();
1957
+ }
1958
+ autoDetectLanguage() {
1959
+ return this.autoDetectLanguageThrottler.trigger(() => this.doAutoDetectLanguage());
1960
+ }
1961
+ async doAutoDetectLanguage() {
1962
+ if (this.hasLanguageSetExplicitly ||
1963
+ !this.textEditorModelHandle ||
1964
+ !this.languageDetectionService.isEnabledForLanguage(this.getLanguageId() ?? PLAINTEXT_LANGUAGE_ID)
1965
+ ) {
1966
+ return;
1967
+ }
1968
+ const lang = await this.languageDetectionService.detectLanguage(this.textEditorModelHandle);
1969
+ if (lang && !this.isDisposed()) {
1970
+ this.setLanguageIdInternal(lang, LanguageDetectionLanguageEventSource);
1971
+ const languageName = this.languageService.getLanguageName(lang);
1972
+ if (languageName) {
1973
+ this.accessibilityService.alert(( (localize(
1974
+ 'languageAutoDetected',
1975
+ "Language {0} was automatically detected and set as the language mode.",
1976
+ languageName
1977
+ ))));
1978
+ }
1979
+ }
1980
+ }
1981
+ createTextEditorModel(value, resource, preferredLanguageId) {
1982
+ const firstLineText = this.getFirstLineText(value);
1983
+ const languageSelection = this.getOrCreateLanguage(resource, this.languageService, preferredLanguageId, firstLineText);
1984
+ return this.doCreateTextEditorModel(value, languageSelection, resource);
1985
+ }
1986
+ doCreateTextEditorModel(value, languageSelection, resource) {
1987
+ let model = resource && this.modelService.getModel(resource);
1988
+ if (!model) {
1989
+ model = this.modelService.createModel(value, languageSelection, resource);
1990
+ this.createdEditorModel = true;
1991
+ this.registerModelDisposeListener(model);
1992
+ }
1993
+ else {
1994
+ this.updateTextEditorModel(value, languageSelection.languageId);
1995
+ }
1996
+ this.textEditorModelHandle = model.uri;
1997
+ return model;
1998
+ }
1999
+ getFirstLineText(value) {
2000
+ const textBufferFactory = value;
2001
+ if (typeof textBufferFactory.getFirstLineText === 'function') {
2002
+ return textBufferFactory.getFirstLineText(1000 );
2003
+ }
2004
+ const textSnapshot = value;
2005
+ return textSnapshot.getLineContent(1).substr(0, 1000 );
2006
+ }
2007
+ getOrCreateLanguage(resource, languageService, preferredLanguage, firstLineText) {
2008
+ if (!preferredLanguage || preferredLanguage === PLAINTEXT_LANGUAGE_ID) {
2009
+ return languageService.createByFilepathOrFirstLine(withUndefinedAsNull(resource), firstLineText);
2010
+ }
2011
+ return languageService.createById(preferredLanguage);
2012
+ }
2013
+ updateTextEditorModel(newValue, preferredLanguageId) {
2014
+ if (!this.isResolved()) {
2015
+ return;
2016
+ }
2017
+ if (newValue) {
2018
+ this.modelService.updateModel(this.textEditorModel, newValue);
2019
+ }
2020
+ if (preferredLanguageId && preferredLanguageId !== PLAINTEXT_LANGUAGE_ID && this.textEditorModel.getLanguageId() !== preferredLanguageId) {
2021
+ this.modelService.setMode(this.textEditorModel, this.languageService.createById(preferredLanguageId));
2022
+ }
2023
+ }
2024
+ createSnapshot() {
2025
+ if (!this.textEditorModel) {
2026
+ return null;
2027
+ }
2028
+ return this.textEditorModel.createSnapshot(true );
2029
+ }
2030
+ isResolved() {
2031
+ return !!this.textEditorModelHandle;
2032
+ }
2033
+ dispose() {
2034
+ this.modelDisposeListener.dispose();
2035
+ if (this.textEditorModelHandle && this.createdEditorModel) {
2036
+ this.modelService.destroyModel(this.textEditorModelHandle);
2037
+ }
2038
+ this.textEditorModelHandle = undefined;
2039
+ this.createdEditorModel = false;
2040
+ super.dispose();
2041
+ }
2042
+ };
2043
+ BaseTextEditorModel.AUTO_DETECT_LANGUAGE_THROTTLE_DELAY = 600;
2044
+ BaseTextEditorModel = ( (__decorate([
2045
+ ( (__param(0, IModelService))),
2046
+ ( (__param(1, ILanguageService))),
2047
+ ( (__param(2, ILanguageDetectionService))),
2048
+ ( (__param(3, IAccessibilityService)))
2049
+ ], BaseTextEditorModel)));
2050
+ const NO_TYPE_ID = '';
2051
+ const UTF8 = 'utf8';
2052
+ const UTF8_with_bom = 'utf8bom';
2053
+ const UTF16be = 'utf16be';
2054
+ const UTF16le = 'utf16le';
2055
+ const UTF16be_BOM = [0xFE, 0xFF];
2056
+ const UTF16le_BOM = [0xFF, 0xFE];
2057
+ const UTF8_BOM = [0xEF, 0xBB, 0xBF];
2058
+ const ZERO_BYTE_DETECTION_BUFFER_MAX_LEN = 512;
2059
+ const NO_ENCODING_GUESS_MIN_BYTES = 512;
2060
+ const AUTO_ENCODING_GUESS_MIN_BYTES = 512 * 8;
2061
+ const AUTO_ENCODING_GUESS_MAX_BYTES = 512 * 128;
2062
+ class DecodeStreamError extends Error {
2063
+ constructor(message, decodeStreamErrorKind) {
2064
+ super(message);
2065
+ this.decodeStreamErrorKind = decodeStreamErrorKind;
2066
+ }
2067
+ }
2068
+ class DecoderStream {
2069
+ static async create(encoding) {
2070
+ let decoder = undefined;
2071
+ if (encoding !== UTF8) {
2072
+ const iconv = await import('./iconv.js').then(module => module.default ?? module);
2073
+ decoder = iconv.getDecoder(toNodeEncoding(encoding));
2074
+ }
2075
+ else {
2076
+ const utf8TextDecoder = ( (new TextDecoder()));
2077
+ decoder = {
2078
+ write(buffer) {
2079
+ return utf8TextDecoder.decode(buffer, {
2080
+ stream: true
2081
+ });
2082
+ },
2083
+ end() {
2084
+ return utf8TextDecoder.decode();
2085
+ }
2086
+ };
2087
+ }
2088
+ return (
2089
+ (new DecoderStream(decoder))
2090
+ );
2091
+ }
2092
+ constructor(iconvLiteDecoder) {
2093
+ this.iconvLiteDecoder = iconvLiteDecoder;
2094
+ }
2095
+ write(buffer) {
2096
+ return this.iconvLiteDecoder.write(buffer);
2097
+ }
2098
+ end() {
2099
+ return this.iconvLiteDecoder.end();
2100
+ }
2101
+ }
2102
+ function toDecodeStream(source, options) {
2103
+ const minBytesRequiredForDetection = options.minBytesRequiredForDetection ?? options.guessEncoding ? AUTO_ENCODING_GUESS_MIN_BYTES : NO_ENCODING_GUESS_MIN_BYTES;
2104
+ return (
2105
+ (new Promise((resolve, reject) => {
2106
+ const target = newWriteableStream(strings => strings.join(''));
2107
+ const bufferedChunks = [];
2108
+ let bytesBuffered = 0;
2109
+ let decoder = undefined;
2110
+ const createDecoder = async () => {
2111
+ try {
2112
+ const detected = await detectEncodingFromBuffer({
2113
+ buffer: VSBuffer.concat(bufferedChunks),
2114
+ bytesRead: bytesBuffered
2115
+ }, options.guessEncoding);
2116
+ if (detected.seemsBinary && options.acceptTextOnly) {
2117
+ throw new DecodeStreamError('Stream is binary but only text is accepted for decoding', 1 );
2118
+ }
2119
+ detected.encoding = await options.overwriteEncoding(detected.encoding);
2120
+ decoder = await DecoderStream.create(detected.encoding);
2121
+ const decoded = decoder.write(VSBuffer.concat(bufferedChunks).buffer);
2122
+ target.write(decoded);
2123
+ bufferedChunks.length = 0;
2124
+ bytesBuffered = 0;
2125
+ resolve({
2126
+ stream: target,
2127
+ detected
2128
+ });
2129
+ }
2130
+ catch (error) {
2131
+ sourceListener?.dispose();
2132
+ target.destroy();
2133
+ reject(error);
2134
+ }
2135
+ };
2136
+ const sourceListener = listenStream(source, {
2137
+ onData: async (chunk) => {
2138
+ if (decoder) {
2139
+ target.write(decoder.write(chunk.buffer));
2140
+ }
2141
+ else {
2142
+ bufferedChunks.push(chunk);
2143
+ bytesBuffered += chunk.byteLength;
2144
+ if (bytesBuffered >= minBytesRequiredForDetection) {
2145
+ source.pause();
2146
+ await createDecoder();
2147
+ setTimeout(() => source.resume());
2148
+ }
2149
+ }
2150
+ },
2151
+ onError: error => target.error(error),
2152
+ onEnd: async () => {
2153
+ if (!decoder) {
2154
+ await createDecoder();
2155
+ }
2156
+ target.end(decoder?.end());
2157
+ }
2158
+ });
2159
+ }))
2160
+ );
2161
+ }
2162
+ async function toEncodeReadable(readable, encoding, options) {
2163
+ const iconv = await import('./iconv.js').then(module => module.default ?? module);
2164
+ const encoder = iconv.getEncoder(toNodeEncoding(encoding), options);
2165
+ let bytesWritten = false;
2166
+ let done = false;
2167
+ return {
2168
+ read() {
2169
+ if (done) {
2170
+ return null;
2171
+ }
2172
+ const chunk = readable.read();
2173
+ if (typeof chunk !== 'string') {
2174
+ done = true;
2175
+ if (!bytesWritten && options?.addBOM) {
2176
+ switch (encoding) {
2177
+ case UTF8:
2178
+ case UTF8_with_bom:
2179
+ return VSBuffer.wrap(Uint8Array.from(UTF8_BOM));
2180
+ case UTF16be:
2181
+ return VSBuffer.wrap(Uint8Array.from(UTF16be_BOM));
2182
+ case UTF16le:
2183
+ return VSBuffer.wrap(Uint8Array.from(UTF16le_BOM));
2184
+ }
2185
+ }
2186
+ const leftovers = encoder.end();
2187
+ if (leftovers && leftovers.length > 0) {
2188
+ bytesWritten = true;
2189
+ return VSBuffer.wrap(leftovers);
2190
+ }
2191
+ return null;
2192
+ }
2193
+ bytesWritten = true;
2194
+ return VSBuffer.wrap(encoder.write(chunk));
2195
+ }
2196
+ };
2197
+ }
2198
+ async function encodingExists(encoding) {
2199
+ const iconv = await import('./iconv.js').then(module => module.default ?? module);
2200
+ return iconv.encodingExists(toNodeEncoding(encoding));
2201
+ }
2202
+ function toNodeEncoding(enc) {
2203
+ if (enc === UTF8_with_bom || enc === null) {
2204
+ return UTF8;
2205
+ }
2206
+ return enc;
2207
+ }
2208
+ function detectEncodingByBOMFromBuffer(buffer, bytesRead) {
2209
+ if (!buffer || bytesRead < UTF16be_BOM.length) {
2210
+ return null;
2211
+ }
2212
+ const b0 = buffer.readUInt8(0);
2213
+ const b1 = buffer.readUInt8(1);
2214
+ if (b0 === UTF16be_BOM[0] && b1 === UTF16be_BOM[1]) {
2215
+ return UTF16be;
2216
+ }
2217
+ if (b0 === UTF16le_BOM[0] && b1 === UTF16le_BOM[1]) {
2218
+ return UTF16le;
2219
+ }
2220
+ if (bytesRead < UTF8_BOM.length) {
2221
+ return null;
2222
+ }
2223
+ const b2 = buffer.readUInt8(2);
2224
+ if (b0 === UTF8_BOM[0] && b1 === UTF8_BOM[1] && b2 === UTF8_BOM[2]) {
2225
+ return UTF8_with_bom;
2226
+ }
2227
+ return null;
2228
+ }
2229
+ const IGNORE_ENCODINGS = ['ascii', 'utf-16', 'utf-32'];
2230
+ async function guessEncodingByBuffer(buffer) {
2231
+ const jschardet = await import('./jschardet.js').then(module => module.default ?? module);
2232
+ const limitedBuffer = buffer.slice(0, AUTO_ENCODING_GUESS_MAX_BYTES);
2233
+ const binaryString = encodeLatin1(limitedBuffer.buffer);
2234
+ const guessed = jschardet.detect(binaryString);
2235
+ if (!guessed || !guessed.encoding) {
2236
+ return null;
2237
+ }
2238
+ const enc = guessed.encoding.toLowerCase();
2239
+ if (0 <= IGNORE_ENCODINGS.indexOf(enc)) {
2240
+ return null;
2241
+ }
2242
+ return toIconvLiteEncoding(guessed.encoding);
2243
+ }
2244
+ const JSCHARDET_TO_ICONV_ENCODINGS = {
2245
+ 'ibm866': 'cp866',
2246
+ 'big5': 'cp950'
2247
+ };
2248
+ function toIconvLiteEncoding(encodingName) {
2249
+ const normalizedEncodingName = encodingName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
2250
+ const mapped = JSCHARDET_TO_ICONV_ENCODINGS[normalizedEncodingName];
2251
+ return mapped || normalizedEncodingName;
2252
+ }
2253
+ function encodeLatin1(buffer) {
2254
+ let result = '';
2255
+ for (let i = 0; i < buffer.length; i++) {
2256
+ result += String.fromCharCode(buffer[i]);
2257
+ }
2258
+ return result;
2259
+ }
2260
+ function detectEncodingFromBuffer({ buffer, bytesRead }, autoGuessEncoding) {
2261
+ let encoding = detectEncodingByBOMFromBuffer(buffer, bytesRead);
2262
+ let seemsBinary = false;
2263
+ if (encoding !== UTF16be && encoding !== UTF16le && buffer) {
2264
+ let couldBeUTF16LE = true;
2265
+ let couldBeUTF16BE = true;
2266
+ let containsZeroByte = false;
2267
+ for (let i = 0; i < bytesRead && i < ZERO_BYTE_DETECTION_BUFFER_MAX_LEN; i++) {
2268
+ const isEndian = (i % 2 === 1);
2269
+ const isZeroByte = (buffer.readUInt8(i) === 0);
2270
+ if (isZeroByte) {
2271
+ containsZeroByte = true;
2272
+ }
2273
+ if (couldBeUTF16LE && (isEndian && !isZeroByte || !isEndian && isZeroByte)) {
2274
+ couldBeUTF16LE = false;
2275
+ }
2276
+ if (couldBeUTF16BE && (isEndian && isZeroByte || !isEndian && !isZeroByte)) {
2277
+ couldBeUTF16BE = false;
2278
+ }
2279
+ if (isZeroByte && !couldBeUTF16LE && !couldBeUTF16BE) {
2280
+ break;
2281
+ }
2282
+ }
2283
+ if (containsZeroByte) {
2284
+ if (couldBeUTF16LE) {
2285
+ encoding = UTF16le;
2286
+ }
2287
+ else if (couldBeUTF16BE) {
2288
+ encoding = UTF16be;
2289
+ }
2290
+ else {
2291
+ seemsBinary = true;
2292
+ }
2293
+ }
2294
+ }
2295
+ if (autoGuessEncoding && !seemsBinary && !encoding && buffer) {
2296
+ return guessEncodingByBuffer(buffer.slice(0, bytesRead)).then(guessedEncoding => {
2297
+ return {
2298
+ seemsBinary: false,
2299
+ encoding: guessedEncoding
2300
+ };
2301
+ });
2302
+ }
2303
+ return { seemsBinary, encoding };
2304
+ }
2305
+ let TextFileEditorModel = class TextFileEditorModel extends BaseTextEditorModel {
2306
+ constructor(resource, preferredEncoding,
2307
+ preferredLanguageId, languageService, modelService, fileService, textFileService, workingCopyBackupService, logService, workingCopyService, filesConfigurationService, labelService, languageDetectionService, accessibilityService, pathService, extensionService) {
2308
+ super(modelService, languageService, languageDetectionService, accessibilityService);
2309
+ this.resource = resource;
2310
+ this.preferredEncoding = preferredEncoding;
2311
+ this.preferredLanguageId = preferredLanguageId;
2312
+ this.fileService = fileService;
2313
+ this.textFileService = textFileService;
2314
+ this.workingCopyBackupService = workingCopyBackupService;
2315
+ this.logService = logService;
2316
+ this.workingCopyService = workingCopyService;
2317
+ this.filesConfigurationService = filesConfigurationService;
2318
+ this.labelService = labelService;
2319
+ this.pathService = pathService;
2320
+ this.extensionService = extensionService;
2321
+ this._onDidChangeContent = this._register(( (new Emitter())));
2322
+ this.onDidChangeContent = this._onDidChangeContent.event;
2323
+ this._onDidResolve = this._register(( (new Emitter())));
2324
+ this.onDidResolve = this._onDidResolve.event;
2325
+ this._onDidChangeDirty = this._register(( (new Emitter())));
2326
+ this.onDidChangeDirty = this._onDidChangeDirty.event;
2327
+ this._onDidSaveError = this._register(( (new Emitter())));
2328
+ this.onDidSaveError = this._onDidSaveError.event;
2329
+ this._onDidSave = this._register(( (new Emitter())));
2330
+ this.onDidSave = this._onDidSave.event;
2331
+ this._onDidRevert = this._register(( (new Emitter())));
2332
+ this.onDidRevert = this._onDidRevert.event;
2333
+ this._onDidChangeEncoding = this._register(( (new Emitter())));
2334
+ this.onDidChangeEncoding = this._onDidChangeEncoding.event;
2335
+ this._onDidChangeOrphaned = this._register(( (new Emitter())));
2336
+ this.onDidChangeOrphaned = this._onDidChangeOrphaned.event;
2337
+ this._onDidChangeReadonly = this._register(( (new Emitter())));
2338
+ this.onDidChangeReadonly = this._onDidChangeReadonly.event;
2339
+ this.typeId = NO_TYPE_ID;
2340
+ this.capabilities = 0 ;
2341
+ this.name = basename(this.labelService.getUriLabel(this.resource));
2342
+ this.resourceHasExtension = !!extUri.extname(this.resource);
2343
+ this.versionId = 0;
2344
+ this.ignoreDirtyOnModelContentChange = false;
2345
+ this.ignoreSaveFromSaveParticipants = false;
2346
+ this.lastModelContentChangeFromUndoRedo = undefined;
2347
+ this.saveSequentializer = ( (new TaskSequentializer()));
2348
+ this.dirty = false;
2349
+ this.inConflictMode = false;
2350
+ this.inOrphanMode = false;
2351
+ this.inErrorMode = false;
2352
+ this.hasEncodingSetExplicitly = false;
2353
+ this._register(this.workingCopyService.registerWorkingCopy(this));
2354
+ this.registerListeners();
2355
+ }
2356
+ registerListeners() {
2357
+ this._register(this.fileService.onDidFilesChange(e => this.onDidFilesChange(e)));
2358
+ this._register(this.filesConfigurationService.onFilesAssociationChange(() => this.onFilesAssociationChange()));
2359
+ }
2360
+ async onDidFilesChange(e) {
2361
+ let fileEventImpactsModel = false;
2362
+ let newInOrphanModeGuess;
2363
+ if (this.inOrphanMode) {
2364
+ const modelFileAdded = e.contains(this.resource, 1 );
2365
+ if (modelFileAdded) {
2366
+ newInOrphanModeGuess = false;
2367
+ fileEventImpactsModel = true;
2368
+ }
2369
+ }
2370
+ else {
2371
+ const modelFileDeleted = e.contains(this.resource, 2 );
2372
+ if (modelFileDeleted) {
2373
+ newInOrphanModeGuess = true;
2374
+ fileEventImpactsModel = true;
2375
+ }
2376
+ }
2377
+ if (fileEventImpactsModel && this.inOrphanMode !== newInOrphanModeGuess) {
2378
+ let newInOrphanModeValidated = false;
2379
+ if (newInOrphanModeGuess) {
2380
+ await timeout(100);
2381
+ if (this.isDisposed()) {
2382
+ newInOrphanModeValidated = true;
2383
+ }
2384
+ else {
2385
+ const exists = await this.fileService.exists(this.resource);
2386
+ newInOrphanModeValidated = !exists;
2387
+ }
2388
+ }
2389
+ if (this.inOrphanMode !== newInOrphanModeValidated && !this.isDisposed()) {
2390
+ this.setOrphaned(newInOrphanModeValidated);
2391
+ }
2392
+ }
2393
+ }
2394
+ setOrphaned(orphaned) {
2395
+ if (this.inOrphanMode !== orphaned) {
2396
+ this.inOrphanMode = orphaned;
2397
+ this._onDidChangeOrphaned.fire();
2398
+ }
2399
+ }
2400
+ onFilesAssociationChange() {
2401
+ if (!this.isResolved()) {
2402
+ return;
2403
+ }
2404
+ const firstLineText = this.getFirstLineText(this.textEditorModel);
2405
+ const languageSelection = this.getOrCreateLanguage(this.resource, this.languageService, this.preferredLanguageId, firstLineText);
2406
+ this.modelService.setMode(this.textEditorModel, languageSelection);
2407
+ }
2408
+ setLanguageId(languageId, source) {
2409
+ super.setLanguageId(languageId, source);
2410
+ this.preferredLanguageId = languageId;
2411
+ }
2412
+ async backup(token) {
2413
+ let meta = undefined;
2414
+ if (this.lastResolvedFileStat) {
2415
+ meta = {
2416
+ mtime: this.lastResolvedFileStat.mtime,
2417
+ ctime: this.lastResolvedFileStat.ctime,
2418
+ size: this.lastResolvedFileStat.size,
2419
+ etag: this.lastResolvedFileStat.etag,
2420
+ orphaned: this.inOrphanMode
2421
+ };
2422
+ }
2423
+ const content = await this.textFileService.getEncodedReadable(this.resource, withNullAsUndefined(this.createSnapshot()), { encoding: UTF8 });
2424
+ return { meta, content };
2425
+ }
2426
+ async revert(options) {
2427
+ if (!this.isResolved()) {
2428
+ return;
2429
+ }
2430
+ const wasDirty = this.dirty;
2431
+ const undo = this.doSetDirty(false);
2432
+ const softUndo = options?.soft;
2433
+ if (!softUndo) {
2434
+ try {
2435
+ await this.forceResolveFromFile();
2436
+ }
2437
+ catch (error) {
2438
+ if (error.fileOperationResult !== 1 ) {
2439
+ undo();
2440
+ throw error;
2441
+ }
2442
+ }
2443
+ }
2444
+ this._onDidRevert.fire();
2445
+ if (wasDirty) {
2446
+ this._onDidChangeDirty.fire();
2447
+ }
2448
+ }
2449
+ async resolve(options) {
2450
+ this.trace('resolve() - enter');
2451
+ if (this.isDisposed()) {
2452
+ this.trace('resolve() - exit - without resolving because model is disposed');
2453
+ return;
2454
+ }
2455
+ if (!options?.contents && (this.dirty || this.saveSequentializer.hasPending())) {
2456
+ this.trace('resolve() - exit - without resolving because model is dirty or being saved');
2457
+ return;
2458
+ }
2459
+ return this.doResolve(options);
2460
+ }
2461
+ async doResolve(options) {
2462
+ if (options?.contents) {
2463
+ return this.resolveFromBuffer(options.contents, options);
2464
+ }
2465
+ const isNewModel = !this.isResolved();
2466
+ if (isNewModel) {
2467
+ const resolvedFromBackup = await this.resolveFromBackup(options);
2468
+ if (resolvedFromBackup) {
2469
+ return;
2470
+ }
2471
+ }
2472
+ return this.resolveFromFile(options);
2473
+ }
2474
+ async resolveFromBuffer(buffer, options) {
2475
+ this.trace('resolveFromBuffer()');
2476
+ let mtime;
2477
+ let ctime;
2478
+ let size;
2479
+ let etag;
2480
+ try {
2481
+ const metadata = await this.fileService.stat(this.resource);
2482
+ mtime = metadata.mtime;
2483
+ ctime = metadata.ctime;
2484
+ size = metadata.size;
2485
+ etag = metadata.etag;
2486
+ this.setOrphaned(false);
2487
+ }
2488
+ catch (error) {
2489
+ mtime = Date.now();
2490
+ ctime = Date.now();
2491
+ size = 0;
2492
+ etag = ETAG_DISABLED;
2493
+ this.setOrphaned(error.fileOperationResult === 1 );
2494
+ }
2495
+ const preferredEncoding = await this.textFileService.encoding.getPreferredWriteEncoding(this.resource, this.preferredEncoding);
2496
+ this.resolveFromContent({
2497
+ resource: this.resource,
2498
+ name: this.name,
2499
+ mtime,
2500
+ ctime,
2501
+ size,
2502
+ etag,
2503
+ value: buffer,
2504
+ encoding: preferredEncoding.encoding,
2505
+ readonly: false
2506
+ }, true , options);
2507
+ }
2508
+ async resolveFromBackup(options) {
2509
+ const backup = await this.workingCopyBackupService.resolve(this);
2510
+ let encoding = UTF8;
2511
+ if (backup) {
2512
+ encoding = (await this.textFileService.encoding.getPreferredWriteEncoding(this.resource, this.preferredEncoding)).encoding;
2513
+ }
2514
+ const isNewModel = !this.isResolved();
2515
+ if (!isNewModel) {
2516
+ this.trace('resolveFromBackup() - exit - without resolving because previously new model got created meanwhile');
2517
+ return true;
2518
+ }
2519
+ if (backup) {
2520
+ await this.doResolveFromBackup(backup, encoding, options);
2521
+ return true;
2522
+ }
2523
+ return false;
2524
+ }
2525
+ async doResolveFromBackup(backup, encoding, options) {
2526
+ this.trace('doResolveFromBackup()');
2527
+ this.resolveFromContent({
2528
+ resource: this.resource,
2529
+ name: this.name,
2530
+ mtime: backup.meta ? backup.meta.mtime : Date.now(),
2531
+ ctime: backup.meta ? backup.meta.ctime : Date.now(),
2532
+ size: backup.meta ? backup.meta.size : 0,
2533
+ etag: backup.meta ? backup.meta.etag : ETAG_DISABLED,
2534
+ value: await createTextBufferFactoryFromStream(await this.textFileService.getDecodedStream(this.resource, backup.value, { encoding: UTF8 })),
2535
+ encoding,
2536
+ readonly: false
2537
+ }, true , options);
2538
+ if (backup.meta?.orphaned) {
2539
+ this.setOrphaned(true);
2540
+ }
2541
+ }
2542
+ async resolveFromFile(options) {
2543
+ this.trace('resolveFromFile()');
2544
+ const forceReadFromFile = options?.forceReadFromFile;
2545
+ const allowBinary = this.isResolved() || options?.allowBinary;
2546
+ let etag;
2547
+ if (forceReadFromFile) {
2548
+ etag = ETAG_DISABLED;
2549
+ }
2550
+ else if (this.lastResolvedFileStat) {
2551
+ etag = this.lastResolvedFileStat.etag;
2552
+ }
2553
+ const currentVersionId = this.versionId;
2554
+ try {
2555
+ const content = await this.textFileService.readStream(this.resource, {
2556
+ acceptTextOnly: !allowBinary,
2557
+ etag, encoding: this.preferredEncoding,
2558
+ limits: options?.limits
2559
+ });
2560
+ this.setOrphaned(false);
2561
+ if (currentVersionId !== this.versionId) {
2562
+ this.trace('resolveFromFile() - exit - without resolving because model content changed');
2563
+ return;
2564
+ }
2565
+ return this.resolveFromContent(content, false , options);
2566
+ }
2567
+ catch (error) {
2568
+ const result = error.fileOperationResult;
2569
+ this.setOrphaned(result === 1 );
2570
+ if (this.isResolved() && result === 2 ) {
2571
+ if (error instanceof NotModifiedSinceFileOperationError) {
2572
+ this.updateLastResolvedFileStat(error.stat);
2573
+ }
2574
+ return;
2575
+ }
2576
+ if (this.isResolved() && result === 1 && !forceReadFromFile) {
2577
+ return;
2578
+ }
2579
+ throw error;
2580
+ }
2581
+ }
2582
+ resolveFromContent(content, dirty, options) {
2583
+ this.trace('resolveFromContent() - enter');
2584
+ if (this.isDisposed()) {
2585
+ this.trace('resolveFromContent() - exit - because model is disposed');
2586
+ return;
2587
+ }
2588
+ this.updateLastResolvedFileStat({
2589
+ resource: this.resource,
2590
+ name: content.name,
2591
+ mtime: content.mtime,
2592
+ ctime: content.ctime,
2593
+ size: content.size,
2594
+ etag: content.etag,
2595
+ readonly: content.readonly,
2596
+ isFile: true,
2597
+ isDirectory: false,
2598
+ isSymbolicLink: false,
2599
+ children: undefined
2600
+ });
2601
+ const oldEncoding = this.contentEncoding;
2602
+ this.contentEncoding = content.encoding;
2603
+ if (this.preferredEncoding) {
2604
+ this.updatePreferredEncoding(this.contentEncoding);
2605
+ }
2606
+ else if (oldEncoding !== this.contentEncoding) {
2607
+ this._onDidChangeEncoding.fire();
2608
+ }
2609
+ if (this.textEditorModel) {
2610
+ this.doUpdateTextModel(content.value);
2611
+ }
2612
+ else {
2613
+ this.doCreateTextModel(content.resource, content.value);
2614
+ }
2615
+ this.setDirty(!!dirty);
2616
+ this._onDidResolve.fire(options?.reason ?? 3 );
2617
+ }
2618
+ doCreateTextModel(resource, value) {
2619
+ this.trace('doCreateTextModel()');
2620
+ const textModel = this.createTextEditorModel(value, resource, this.preferredLanguageId);
2621
+ this.installModelListeners(textModel);
2622
+ this.autoDetectLanguage();
2623
+ }
2624
+ doUpdateTextModel(value) {
2625
+ this.trace('doUpdateTextModel()');
2626
+ this.ignoreDirtyOnModelContentChange = true;
2627
+ try {
2628
+ this.updateTextEditorModel(value, this.preferredLanguageId);
2629
+ }
2630
+ finally {
2631
+ this.ignoreDirtyOnModelContentChange = false;
2632
+ }
2633
+ }
2634
+ installModelListeners(model) {
2635
+ this._register(model.onDidChangeContent(e => this.onModelContentChanged(model, e.isUndoing || e.isRedoing)));
2636
+ this._register(model.onDidChangeLanguage(() => this.onMaybeShouldChangeEncoding()));
2637
+ super.installModelListeners(model);
2638
+ }
2639
+ onModelContentChanged(model, isUndoingOrRedoing) {
2640
+ this.trace(`onModelContentChanged() - enter`);
2641
+ this.versionId++;
2642
+ this.trace(`onModelContentChanged() - new versionId ${this.versionId}`);
2643
+ if (isUndoingOrRedoing) {
2644
+ this.lastModelContentChangeFromUndoRedo = Date.now();
2645
+ }
2646
+ if (!this.ignoreDirtyOnModelContentChange && !this.isReadonly()) {
2647
+ if (model.getAlternativeVersionId() === this.bufferSavedVersionId) {
2648
+ this.trace('onModelContentChanged() - model content changed back to last saved version');
2649
+ const wasDirty = this.dirty;
2650
+ this.setDirty(false);
2651
+ if (wasDirty) {
2652
+ this._onDidRevert.fire();
2653
+ }
2654
+ }
2655
+ else {
2656
+ this.trace('onModelContentChanged() - model content changed and marked as dirty');
2657
+ this.setDirty(true);
2658
+ }
2659
+ }
2660
+ this._onDidChangeContent.fire();
2661
+ this.autoDetectLanguage();
2662
+ }
2663
+ async autoDetectLanguage() {
2664
+ await this.extensionService?.whenInstalledExtensionsRegistered();
2665
+ const languageId = this.getLanguageId();
2666
+ if (this.resource.scheme === this.pathService.defaultUriScheme &&
2667
+ (!languageId || languageId === PLAINTEXT_LANGUAGE_ID) &&
2668
+ !this.resourceHasExtension
2669
+ ) {
2670
+ return super.autoDetectLanguage();
2671
+ }
2672
+ }
2673
+ async forceResolveFromFile() {
2674
+ if (this.isDisposed()) {
2675
+ return;
2676
+ }
2677
+ await this.textFileService.files.resolve(this.resource, {
2678
+ reload: { async: false },
2679
+ forceReadFromFile: true
2680
+ });
2681
+ }
2682
+ isDirty() {
2683
+ return this.dirty;
2684
+ }
2685
+ setDirty(dirty) {
2686
+ if (!this.isResolved()) {
2687
+ return;
2688
+ }
2689
+ const wasDirty = this.dirty;
2690
+ this.doSetDirty(dirty);
2691
+ if (dirty !== wasDirty) {
2692
+ this._onDidChangeDirty.fire();
2693
+ }
2694
+ }
2695
+ doSetDirty(dirty) {
2696
+ const wasDirty = this.dirty;
2697
+ const wasInConflictMode = this.inConflictMode;
2698
+ const wasInErrorMode = this.inErrorMode;
2699
+ const oldBufferSavedVersionId = this.bufferSavedVersionId;
2700
+ if (!dirty) {
2701
+ this.dirty = false;
2702
+ this.inConflictMode = false;
2703
+ this.inErrorMode = false;
2704
+ this.updateSavedVersionId();
2705
+ }
2706
+ else {
2707
+ this.dirty = true;
2708
+ }
2709
+ return () => {
2710
+ this.dirty = wasDirty;
2711
+ this.inConflictMode = wasInConflictMode;
2712
+ this.inErrorMode = wasInErrorMode;
2713
+ this.bufferSavedVersionId = oldBufferSavedVersionId;
2714
+ };
2715
+ }
2716
+ async save(options = Object.create(null)) {
2717
+ if (!this.isResolved()) {
2718
+ return false;
2719
+ }
2720
+ if (this.isReadonly()) {
2721
+ this.trace('save() - ignoring request for readonly resource');
2722
+ return false;
2723
+ }
2724
+ if ((this.hasState(3 ) || this.hasState(5 )) &&
2725
+ ((options.reason === 2 || options.reason === 3 || options.reason === 4) )) {
2726
+ this.trace('save() - ignoring auto save request for model that is in conflict or error');
2727
+ return false;
2728
+ }
2729
+ this.trace('save() - enter');
2730
+ await this.doSave(options);
2731
+ this.trace('save() - exit');
2732
+ return this.hasState(0 );
2733
+ }
2734
+ async doSave(options) {
2735
+ if (typeof options.reason !== 'number') {
2736
+ options.reason = 1 ;
2737
+ }
2738
+ let versionId = this.versionId;
2739
+ this.trace(`doSave(${versionId}) - enter with versionId ${versionId}`);
2740
+ if (this.ignoreSaveFromSaveParticipants) {
2741
+ this.trace(`doSave(${versionId}) - exit - refusing to save() recursively from save participant`);
2742
+ return;
2743
+ }
2744
+ if (this.saveSequentializer.hasPending(versionId)) {
2745
+ this.trace(`doSave(${versionId}) - exit - found a pending save for versionId ${versionId}`);
2746
+ return this.saveSequentializer.pending;
2747
+ }
2748
+ if (!options.force && !this.dirty) {
2749
+ this.trace(`doSave(${versionId}) - exit - because not dirty and/or versionId is different (this.isDirty: ${this.dirty}, this.versionId: ${this.versionId})`);
2750
+ return;
2751
+ }
2752
+ if (this.saveSequentializer.hasPending()) {
2753
+ this.trace(`doSave(${versionId}) - exit - because busy saving`);
2754
+ this.saveSequentializer.cancelPending();
2755
+ return this.saveSequentializer.setNext(() => this.doSave(options));
2756
+ }
2757
+ if (this.isResolved()) {
2758
+ this.textEditorModel.pushStackElement();
2759
+ }
2760
+ const saveCancellation = ( (new CancellationTokenSource()));
2761
+ return this.saveSequentializer.setPending(versionId, (async () => {
2762
+ if (this.isResolved() && !options.skipSaveParticipants) {
2763
+ try {
2764
+ if (options.reason === 2 && typeof this.lastModelContentChangeFromUndoRedo === 'number') {
2765
+ const timeFromUndoRedoToSave = Date.now() - this.lastModelContentChangeFromUndoRedo;
2766
+ if (timeFromUndoRedoToSave < TextFileEditorModel.UNDO_REDO_SAVE_PARTICIPANTS_AUTO_SAVE_THROTTLE_THRESHOLD) {
2767
+ await timeout(TextFileEditorModel.UNDO_REDO_SAVE_PARTICIPANTS_AUTO_SAVE_THROTTLE_THRESHOLD - timeFromUndoRedoToSave);
2768
+ }
2769
+ }
2770
+ if (!saveCancellation.token.isCancellationRequested) {
2771
+ this.ignoreSaveFromSaveParticipants = true;
2772
+ try {
2773
+ await this.textFileService.files.runSaveParticipants(this, { reason: options.reason ?? 1 }, saveCancellation.token);
2774
+ }
2775
+ finally {
2776
+ this.ignoreSaveFromSaveParticipants = false;
2777
+ }
2778
+ }
2779
+ }
2780
+ catch (error) {
2781
+ this.logService.error(`[text file model] runSaveParticipants(${versionId}) - resulted in an error: ${( ( error.toString()))}`, ( (this.resource.toString())));
2782
+ }
2783
+ }
2784
+ if (saveCancellation.token.isCancellationRequested) {
2785
+ return;
2786
+ }
2787
+ else {
2788
+ saveCancellation.dispose();
2789
+ }
2790
+ if (this.isDisposed()) {
2791
+ return;
2792
+ }
2793
+ if (!this.isResolved()) {
2794
+ return;
2795
+ }
2796
+ versionId = this.versionId;
2797
+ this.inErrorMode = false;
2798
+ this.trace(`doSave(${versionId}) - before write()`);
2799
+ const lastResolvedFileStat = assertIsDefined(this.lastResolvedFileStat);
2800
+ const resolvedTextFileEditorModel = this;
2801
+ return this.saveSequentializer.setPending(versionId, (async () => {
2802
+ try {
2803
+ const stat = await this.textFileService.write(lastResolvedFileStat.resource, resolvedTextFileEditorModel.createSnapshot(), {
2804
+ mtime: lastResolvedFileStat.mtime,
2805
+ encoding: this.getEncoding(),
2806
+ etag: (options.ignoreModifiedSince || !this.filesConfigurationService.preventSaveConflicts(lastResolvedFileStat.resource, resolvedTextFileEditorModel.getLanguageId())) ? ETAG_DISABLED : lastResolvedFileStat.etag,
2807
+ unlock: options.writeUnlock,
2808
+ writeElevated: options.writeElevated
2809
+ });
2810
+ this.handleSaveSuccess(stat, versionId, options);
2811
+ }
2812
+ catch (error) {
2813
+ this.handleSaveError(error, versionId, options);
2814
+ }
2815
+ })());
2816
+ })(), () => saveCancellation.cancel());
2817
+ }
2818
+ handleSaveSuccess(stat, versionId, options) {
2819
+ this.updateLastResolvedFileStat(stat);
2820
+ if (versionId === this.versionId) {
2821
+ this.trace(`handleSaveSuccess(${versionId}) - setting dirty to false because versionId did not change`);
2822
+ this.setDirty(false);
2823
+ }
2824
+ else {
2825
+ this.trace(`handleSaveSuccess(${versionId}) - not setting dirty to false because versionId did change meanwhile`);
2826
+ }
2827
+ this.setOrphaned(false);
2828
+ this._onDidSave.fire({ reason: options.reason, stat, source: options.source });
2829
+ }
2830
+ handleSaveError(error, versionId, options) {
2831
+ (options.ignoreErrorHandler ? this.logService.trace : this.logService.error).apply(this.logService, [`[text file model] handleSaveError(${versionId}) - exit - resulted in a save error: ${( ( error.toString()))}`, ( (this.resource.toString()))]);
2832
+ if (options.ignoreErrorHandler) {
2833
+ throw error;
2834
+ }
2835
+ this.setDirty(true);
2836
+ this.inErrorMode = true;
2837
+ if (error.fileOperationResult === 3 ) {
2838
+ this.inConflictMode = true;
2839
+ }
2840
+ this.textFileService.files.saveErrorHandler.onSaveError(error, this);
2841
+ this._onDidSaveError.fire();
2842
+ }
2843
+ updateSavedVersionId() {
2844
+ if (this.isResolved()) {
2845
+ this.bufferSavedVersionId = this.textEditorModel.getAlternativeVersionId();
2846
+ }
2847
+ }
2848
+ updateLastResolvedFileStat(newFileStat) {
2849
+ const oldReadonly = this.isReadonly();
2850
+ if (!this.lastResolvedFileStat) {
2851
+ this.lastResolvedFileStat = newFileStat;
2852
+ }
2853
+ else if (this.lastResolvedFileStat.mtime <= newFileStat.mtime) {
2854
+ this.lastResolvedFileStat = newFileStat;
2855
+ }
2856
+ if (this.isReadonly() !== oldReadonly) {
2857
+ this._onDidChangeReadonly.fire();
2858
+ }
2859
+ }
2860
+ hasState(state) {
2861
+ switch (state) {
2862
+ case 3 :
2863
+ return this.inConflictMode;
2864
+ case 1 :
2865
+ return this.dirty;
2866
+ case 5 :
2867
+ return this.inErrorMode;
2868
+ case 4 :
2869
+ return this.inOrphanMode;
2870
+ case 2 :
2871
+ return this.saveSequentializer.hasPending();
2872
+ case 0 :
2873
+ return !this.dirty;
2874
+ }
2875
+ }
2876
+ async joinState(state) {
2877
+ return this.saveSequentializer.pending;
2878
+ }
2879
+ getLanguageId() {
2880
+ if (this.textEditorModel) {
2881
+ return this.textEditorModel.getLanguageId();
2882
+ }
2883
+ return this.preferredLanguageId;
2884
+ }
2885
+ async onMaybeShouldChangeEncoding() {
2886
+ if (this.hasEncodingSetExplicitly) {
2887
+ this.trace('onMaybeShouldChangeEncoding() - ignoring because encoding was set explicitly');
2888
+ return;
2889
+ }
2890
+ if (this.contentEncoding === UTF8_with_bom || this.contentEncoding === UTF16be || this.contentEncoding === UTF16le) {
2891
+ this.trace('onMaybeShouldChangeEncoding() - ignoring because content encoding has a BOM');
2892
+ return;
2893
+ }
2894
+ const { encoding } = await this.textFileService.encoding.getPreferredReadEncoding(this.resource);
2895
+ if (typeof encoding !== 'string' || !this.isNewEncoding(encoding)) {
2896
+ this.trace(`onMaybeShouldChangeEncoding() - ignoring because preferred encoding ${encoding} is not new`);
2897
+ return;
2898
+ }
2899
+ if (this.isDirty()) {
2900
+ this.trace('onMaybeShouldChangeEncoding() - ignoring because model is dirty');
2901
+ return;
2902
+ }
2903
+ this.logService.info(`Adjusting encoding based on configured language override to '${encoding}' for ${( ( this.resource.toString(true)))}.`);
2904
+ return this.setEncodingInternal(encoding, 1 );
2905
+ }
2906
+ setEncoding(encoding, mode) {
2907
+ this.hasEncodingSetExplicitly = true;
2908
+ return this.setEncodingInternal(encoding, mode);
2909
+ }
2910
+ async setEncodingInternal(encoding, mode) {
2911
+ if (mode === 0 ) {
2912
+ this.updatePreferredEncoding(encoding);
2913
+ if (!this.isDirty()) {
2914
+ this.versionId++;
2915
+ this.setDirty(true);
2916
+ }
2917
+ if (!this.inConflictMode) {
2918
+ await this.save({ source: TextFileEditorModel.TEXTFILE_SAVE_ENCODING_SOURCE });
2919
+ }
2920
+ }
2921
+ else {
2922
+ if (!this.isNewEncoding(encoding)) {
2923
+ return;
2924
+ }
2925
+ if (this.isDirty() && !this.inConflictMode) {
2926
+ await this.save();
2927
+ }
2928
+ this.updatePreferredEncoding(encoding);
2929
+ await this.forceResolveFromFile();
2930
+ }
2931
+ }
2932
+ updatePreferredEncoding(encoding) {
2933
+ if (!this.isNewEncoding(encoding)) {
2934
+ return;
2935
+ }
2936
+ this.preferredEncoding = encoding;
2937
+ this._onDidChangeEncoding.fire();
2938
+ }
2939
+ isNewEncoding(encoding) {
2940
+ if (this.preferredEncoding === encoding) {
2941
+ return false;
2942
+ }
2943
+ if (!this.preferredEncoding && this.contentEncoding === encoding) {
2944
+ return false;
2945
+ }
2946
+ return true;
2947
+ }
2948
+ getEncoding() {
2949
+ return this.preferredEncoding || this.contentEncoding;
2950
+ }
2951
+ trace(msg) {
2952
+ this.logService.trace(`[text file model] ${msg}`, ( (this.resource.toString())));
2953
+ }
2954
+ isResolved() {
2955
+ return !!this.textEditorModel;
2956
+ }
2957
+ isReadonly() {
2958
+ return this.lastResolvedFileStat?.readonly || this.fileService.hasCapability(this.resource, 2048 );
2959
+ }
2960
+ dispose() {
2961
+ this.trace('dispose()');
2962
+ this.inConflictMode = false;
2963
+ this.inOrphanMode = false;
2964
+ this.inErrorMode = false;
2965
+ super.dispose();
2966
+ }
2967
+ };
2968
+ TextFileEditorModel.TEXTFILE_SAVE_ENCODING_SOURCE = SaveSourceRegistry.registerSource('textFileEncoding.source', ( (localize('textFileCreate.source', "File Encoding Changed"))));
2969
+ TextFileEditorModel.UNDO_REDO_SAVE_PARTICIPANTS_AUTO_SAVE_THROTTLE_THRESHOLD = 500;
2970
+ TextFileEditorModel = ( (__decorate([
2971
+ ( (__param(3, ILanguageService))),
2972
+ ( (__param(4, IModelService))),
2973
+ ( (__param(5, IFileService))),
2974
+ ( (__param(6, ITextFileService))),
2975
+ ( (__param(7, IWorkingCopyBackupService))),
2976
+ ( (__param(8, ILogService))),
2977
+ ( (__param(9, IWorkingCopyService))),
2978
+ ( (__param(10, IFilesConfigurationService))),
2979
+ ( (__param(11, ILabelService))),
2980
+ ( (__param(12, ILanguageDetectionService))),
2981
+ ( (__param(13, IAccessibilityService))),
2982
+ ( (__param(14, IPathService))),
2983
+ ( (__param(15, IExtensionService)))
2984
+ ], TextFileEditorModel)));
2985
+ export { BaseTextEditorModel as B, NO_TYPE_ID as N, TextFileEditorModel as T, UTF8 as U, toDecodeStream as a, UTF16be as b, createTextBufferFactoryFromStream as c, UTF16le as d, UTF8_with_bom as e, encodingExists as f, toEncodeReadable as t };