modelService.ts ×14

Frontier kind: Code frontier

unlabeled · c_e1ca857503aa

3 tests · 42786 LOC · 238 files · introduces 0 tests · 88 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
24 ranges88 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5551 ranges42786 lines · 238 files · Browse complete extent
All tests (intent)
3 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 88 introduced LOC across 24 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/services/modelService.ts 57 introduced LOC · 14 ranges

Open complete file

71 class DisposedModelInfo {
72 constructor(
73 > public readonly uri: URI, modelService.ts
74 > public readonly initialUndoRedoSnapshot: ResourceEditStackSnapshot | null,
75 > public readonly time: number,
76 > public readonly sharesUndoRedoStack: boolean,
77 > public readonly heapSize: number,
78 > public readonly sha1: string,
79 > public readonly versionId: number,
80 > public readonly alternativeVersionId: number,
81 > ) { }
82 }
83
272
273 private _insertDisposedModel(disposedModelData: DisposedModelInfo): void {
274 > this._disposedModels.set(MODEL_ID(disposedModelData.uri), disposedModelData); modelService.ts
275 > this._disposedModelsHeapSize += disposedModelData.heapSize;
276 > }
277
278 private _removeDisposedModel(resource: URI): DisposedModelInfo | undefined {
279 > const disposedModelData = this._disposedModels.get(MODEL_ID(resource)); modelService.ts
280 > if (disposedModelData) {
281 > this._disposedModelsHeapSize -= disposedModelData.heapSize;
282 > }
283 > this._disposedModels.delete(MODEL_ID(resource));
284 > return disposedModelData;
285 > }
286
287 private _ensureDisposedModelsHeapSize(maxModelsHeapSize: number): void {
288 > if (this._disposedModelsHeapSize > maxModelsHeapSize) { modelService.ts
289 // we must remove some old undo stack elements to free up some memory
290 const disposedModels: DisposedModelInfo[] = [];
303 }
304 }
305 > } modelService.ts
306
307 private _createModelData(value: string | ITextBufferFactory, languageIdOrSelection: string | ILanguageSelection, resource: URI | undefined, isForSimpleWidget: boolean): ModelData {
315 );
316 if (resource && this._disposedModels.has(MODEL_ID(resource))) {
317 > const disposedModelData = this._removeDisposedModel(resource)!; modelService.ts
318 > const elements = this._undoRedoService.getElements(resource);
319 > const sha1Computer = this._getSHA1Computer();
320 > const sha1IsEqual = (
321 > sha1Computer.canComputeSHA1(model)
322 > ? sha1Computer.computeSHA1(model) === disposedModelData.sha1
323 : false
324 > ); modelService.ts
325 > if (sha1IsEqual || disposedModelData.sharesUndoRedoStack) {
326 for (const element of elements.past) {
327 if (isEditStackElement(element) && element.matchesResource(resource)) {
340 model._overwriteInitialUndoRedoSnapshot(disposedModelData.initialUndoRedoSnapshot);
341 }
342 > } else { modelService.ts
343 if (disposedModelData.initialUndoRedoSnapshot !== null) {
344 this._undoRedoService.restoreSnapshot(disposedModelData.initialUndoRedoSnapshot);
345 }
346 }
347 > } modelService.ts
348 const modelId = MODEL_ID(model.uri);
349
504 const elements = this._undoRedoService.getElements(model.uri);
505 if (elements.past.length > 0 || elements.future.length > 0) {
506 > for (const element of elements.past) { modelService.ts
507 > if (isEditStackElement(element) && element.matchesResource(model.uri)) {
508 > maintainUndoRedoStack = true;
509 > heapSize += element.heapSize(model.uri);
510 > element.setModel(model.uri); // remove reference from text buffer instance
511 > }
512 > }
513 > for (const element of elements.future) {
514 if (isEditStackElement(element) && element.matchesResource(model.uri)) {
515 maintainUndoRedoStack = true;
536 this._undoRedoService.restoreSnapshot(initialUndoRedoSnapshot);
537 }
538 > } else { modelService.ts
539 > this._ensureDisposedModelsHeapSize(maxMemory - heapSize);
540 > // We only invalidate the elements, but they remain in the undo-redo service.
541 > this._undoRedoService.setElementsValidFlag(model.uri, false, (element) => (isEditStackElement(element) && element.matchesResource(model.uri)));
542 > this._insertDisposedModel(new DisposedModelInfo(model.uri, modelData.model.getInitialUndoRedoSnapshot(), Date.now(), sharesUndoRedoStack, heapSize, sha1Computer.computeSHA1(model), model.getVersionId(), model.getAlternativeVersionId()));
543 > }
544
545 delete this._models[modelId];
576
577 canComputeSHA1(model: ITextModel): boolean {
578 > return (model.getValueLength() <= DefaultModelSHA1Computer.MAX_MODEL_SIZE); modelService.ts
579 > }
580
581 computeSHA1(model: ITextModel): string {
582 > // compute the sha1 modelService.ts
583 > const shaComputer = new StringSHA1();
584 > const snapshot = model.createSnapshot();
585 > let text: string | null;
586 > while ((text = snapshot.read())) {
587 > shaComputer.update(text);
588 > }
589 > return shaComputer.digest();
590 > }
591 }
src/vs/platform/undoRedo/common/undoRedoService.ts 21 introduced LOC · 7 ranges

Open complete file

56
57 public setValid(isValid: boolean): void {
58 > this.isValid = isValid; undoRedoService.ts
59 > }
60
61 public toString(): string {
262
263 private _setElementValidFlag(element: StackElement, isValid: boolean): void {
264 > if (element.type === UndoRedoElementType.Workspace) { undoRedoService.ts
265 element.setValid(this.resourceLabel, this.strResource, isValid);
266 > } else { undoRedoService.ts
267 > element.setValid(isValid);
268 > }
269 > }
270
271 public setElementsValidFlag(isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void {
272 > for (const element of this._past) { undoRedoService.ts
273 > if (filter(element.actual)) {
274 > this._setElementValidFlag(element, isValid);
275 > }
276 > }
277 > for (const element of this._future) {
278 if (filter(element.actual)) {
279 this._setElementValidFlag(element, isValid);
280 }
281 }
283
284 public pushElement(element: StackElement): void {
616
617 public setElementsValidFlag(resource: URI, isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void {
618 > const strResource = this.getUriComparisonKey(resource); undoRedoService.ts
619 > if (this._editStacks.has(strResource)) {
620 > const editStack = this._editStacks.get(strResource)!;
621 > editStack.setElementsValidFlag(isValid, filter);
622 > }
623 > if (DEBUG) {
624 this._print('setElementsValidFlag');
625 }
627
628 public hasElements(resource: URI): boolean {
src/vs/editor/common/model/editStack.ts 10 introduced LOC · 3 ranges

Open complete file

179
180 public matchesResource(resource: URI): boolean {
181 > const uri = (URI.isUri(this.model) ? this.model : this.model.uri); editStack.ts
182 > return (uri.toString() === resource.toString());
183 > }
184
185 public setModel(model: ITextModel | URI): void {
186 > this.model = model; editStack.ts
187 > }
188
189 public canAppend(model: ITextModel): boolean {
234
235 public heapSize(): number {
236 > if (this._data instanceof SingleModelEditStackData) { editStack.ts
237 > this._data = this._data.serialize();
238 > }
239 > return this._data.byteLength + 168/*heap overhead*/;
240 > }
241 }
242