modelService.ts ×29

Frontier kind: Code frontier

unlabeled · c_d0cac856be79

5 tests · 41187 LOC · 238 files · introduces 0 tests · 139 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
32 ranges139 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5110 ranges41187 lines · 238 files · Browse complete extent
All tests (intent)
5 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: 139 introduced LOC across 32 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/services/modelService.ts 132 introduced LOC · 29 ranges

Open complete file

37
38 constructor(
39 > public readonly model: TextModel, modelService.ts
40 > onWillDispose: (model: ITextModel) => void,
41 > onDidChangeLanguage: (model: ITextModel, e: IModelLanguageChangedEvent) => void
42 > ) {
43 > this.model = model;
44 > this._modelEventListeners.add(model.onWillDispose(() => onWillDispose(model)));
45 > this._modelEventListeners.add(model.onDidChangeLanguage((e) => onDidChangeLanguage(model, e)));
46 > }
47
48 public dispose(): void {
49 > this._modelEventListeners.dispose(); modelService.ts
50 > }
51 }
52
123
124 private static _readModelOptions(config: IRawConfig, isForSimpleWidget: boolean): ITextModelCreationOptions {
125 > let tabSize = EDITOR_MODEL_DEFAULTS.tabSize; modelService.ts
126 > if (config.editor && typeof config.editor.tabSize !== 'undefined') {
127 tabSize = clampedInt(config.editor.tabSize, EDITOR_MODEL_DEFAULTS.tabSize, 1, 100);
128 }
130 > let indentSize: number | 'tabSize' = 'tabSize';
131 > if (config.editor && typeof config.editor.indentSize !== 'undefined' && config.editor.indentSize !== 'tabSize') {
132 indentSize = clampedInt(config.editor.indentSize, 'tabSize', 1, 100);
133 }
135 > let insertSpaces = EDITOR_MODEL_DEFAULTS.insertSpaces;
136 > if (config.editor && typeof config.editor.insertSpaces !== 'undefined') {
137 insertSpaces = (config.editor.insertSpaces === 'false' ? false : Boolean(config.editor.insertSpaces));
138 }
140 > let newDefaultEOL = DEFAULT_EOL;
141 > const eol = config.eol;
142 > if (eol === '\r\n') {
143 newDefaultEOL = DefaultEndOfLine.CRLF;
144 > } else if (eol === '\n') { modelService.ts
145 > newDefaultEOL = DefaultEndOfLine.LF;
146 > }
147 >
148 > let trimAutoWhitespace = EDITOR_MODEL_DEFAULTS.trimAutoWhitespace;
149 > if (config.editor && typeof config.editor.trimAutoWhitespace !== 'undefined') {
150 trimAutoWhitespace = (config.editor.trimAutoWhitespace === 'false' ? false : Boolean(config.editor.trimAutoWhitespace));
151 }
153 > let detectIndentation = EDITOR_MODEL_DEFAULTS.detectIndentation;
154 > if (config.editor && typeof config.editor.detectIndentation !== 'undefined') {
155 detectIndentation = (config.editor.detectIndentation === 'false' ? false : Boolean(config.editor.detectIndentation));
156 }
158 > let largeFileOptimizations = EDITOR_MODEL_DEFAULTS.largeFileOptimizations;
159 > if (config.editor && typeof config.editor.largeFileOptimizations !== 'undefined') {
160 largeFileOptimizations = (config.editor.largeFileOptimizations === 'false' ? false : Boolean(config.editor.largeFileOptimizations));
161 }
162 > let bracketPairColorizationOptions = EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions; modelService.ts
163 > if (config.editor?.bracketPairColorization && typeof config.editor.bracketPairColorization === 'object') {
164 const bpConfig = config.editor.bracketPairColorization as { enabled?: unknown; independentColorPoolPerBracketType?: unknown };
165 bracketPairColorizationOptions = {
168 };
169 }
171 > return {
172 > isForSimpleWidget: isForSimpleWidget,
173 > tabSize: tabSize,
174 > indentSize: indentSize,
175 > insertSpaces: insertSpaces,
176 > detectIndentation: detectIndentation,
177 > defaultEOL: newDefaultEOL,
178 > trimAutoWhitespace: trimAutoWhitespace,
179 > largeFileOptimizations: largeFileOptimizations,
180 > bracketPairColorizationOptions
181 > };
182 > }
183
184 private _getEOL(resource: URI | undefined, language: string): string {
185 > if (resource) { modelService.ts
186 > return this._resourcePropertiesService.getEOL(resource, language);
187 > }
188 const eol = this._configurationService.getValue('files.eol', { overrideIdentifier: language });
189 > if (eol && typeof eol === 'string' && eol !== 'auto') { modelService.ts
190 return eol;
191 }
192 > return platform.OS === platform.OperatingSystem.Linux || platform.OS === platform.OperatingSystem.Macintosh ? '\n' : '\r\n'; modelService.ts
193 > }
194
195 private _shouldRestoreUndoStack(): boolean {
196 > const result = this._configurationService.getValue('files.restoreUndoStack'); modelService.ts
197 > if (typeof result === 'boolean') {
198 return result;
199 }
200 > return true; modelService.ts
201 > }
202
203 public getCreationOptions(languageIdOrSelection: string | ILanguageSelection, resource: URI | undefined, isForSimpleWidget: boolean): ITextModelCreationOptions {
204 > const language = (typeof languageIdOrSelection === 'string' ? languageIdOrSelection : languageIdOrSelection.languageId); modelService.ts
205 > let creationOptions = this._modelCreationOptionsByLanguageAndResource[language + resource];
206 > if (!creationOptions) {
207 > const editor = this._configurationService.getValue<IRawEditorConfig>('editor', { overrideIdentifier: language, resource });
208 > const eol = this._getEOL(resource, language);
209 > creationOptions = ModelService._readModelOptions({ editor, eol }, isForSimpleWidget);
210 > this._modelCreationOptionsByLanguageAndResource[language + resource] = creationOptions;
211 > }
212 > return creationOptions;
213 > }
214
215 private _updateModelOptions(e: IConfigurationChangeEvent | undefined): void {
306
307 private _createModelData(value: string | ITextBufferFactory, languageIdOrSelection: string | ILanguageSelection, resource: URI | undefined, isForSimpleWidget: boolean): ModelData {
308 > // create & save the model modelService.ts
309 > const options = this.getCreationOptions(languageIdOrSelection, resource, isForSimpleWidget);
310 > const model: TextModel = this._instantiationService.createInstance(TextModel,
311 > value,
312 > languageIdOrSelection,
313 > options,
314 > resource
315 > );
316 > if (resource && this._disposedModels.has(MODEL_ID(resource))) {
317 const disposedModelData = this._removeDisposedModel(resource)!;
318 const elements = this._undoRedoService.getElements(resource);
346 }
347 }
348 > const modelId = MODEL_ID(model.uri); modelService.ts
349 >
350 > if (this._models[modelId]) {
351 // There already exists a model with this id => this is a programmer error
352 throw new Error('ModelService: Cannot add model because it already exists!');
353 }
355 > const modelData = new ModelData(
356 > model,
357 > (model) => this._onWillDispose(model),
358 > (model, e) => this._onDidChangeLanguage(model, e)
359 > );
360 > this._models[modelId] = modelData;
361 >
362 > return modelData;
363 > }
364
365 public updateModel(model: ITextModel, value: string | ITextBufferFactory, reason: TextModelEditSource = EditSources.unknown({ name: 'updateModel' })): void {
439
440 public createModel(value: string | ITextBufferFactory, languageSelection: ILanguageSelection | null, resource?: URI, isForSimpleWidget: boolean = false): ITextModel {
441 > let modelData: ModelData; modelService.ts
442 >
443 > if (languageSelection) {
444 modelData = this._createModelData(value, languageSelection, resource, isForSimpleWidget);
445 > } else { modelService.ts
446 > modelData = this._createModelData(value, PLAINTEXT_LANGUAGE_ID, resource, isForSimpleWidget);
447 > }
448 >
449 > this._onModelAdded.fire(modelData.model);
450 >
451 > return modelData.model;
452 > }
453
454 public destroyModel(resource: URI): void {
485
486 protected _schemaShouldMaintainUndoRedoElements(resource: URI) {
487 > return ( modelService.ts
488 > resource.scheme === Schemas.file
489 || resource.scheme === Schemas.vscodeRemote
490 || resource.scheme === Schemas.vscodeUserData
491 || resource.scheme === Schemas.vscodeNotebookCell
492 || resource.scheme === 'fake-fs' // for tests
493 > ); modelService.ts
494 > }
495
496 private _onWillDispose(model: ITextModel): void {
497 > const modelId = MODEL_ID(model.uri); modelService.ts
498 > const modelData = this._models[modelId];
499 >
500 > const sharesUndoRedoStack = (this._undoRedoService.getUriComparisonKey(model.uri) !== model.uri.toString());
501 > let maintainUndoRedoStack = false;
502 > let heapSize = 0;
503 > if (sharesUndoRedoStack || (this._shouldRestoreUndoStack() && this._schemaShouldMaintainUndoRedoElements(model.uri))) {
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) {
507 if (isEditStackElement(element) && element.matchesResource(model.uri)) {
519 }
520 }
521 > } modelService.ts
522 >
523 > const maxMemory = ModelService.MAX_MEMORY_FOR_CLOSED_FILES_UNDO_STACK;
524 > const sha1Computer = this._getSHA1Computer();
525 > if (!maintainUndoRedoStack) {
526 if (!sharesUndoRedoStack) {
527 const initialUndoRedoSnapshot = modelData.model.getInitialUndoRedoSnapshot();
530 }
531 }
532 > } else if (!sharesUndoRedoStack && (heapSize > maxMemory || !sha1Computer.canComputeSHA1(model))) { modelService.ts
533 // the undo stack for this file would never fit in the configured memory or the file is very large, so don't bother with it.
534 const initialUndoRedoSnapshot = modelData.model.getInitialUndoRedoSnapshot();
542 this._insertDisposedModel(new DisposedModelInfo(model.uri, modelData.model.getInitialUndoRedoSnapshot(), Date.now(), sharesUndoRedoStack, heapSize, sha1Computer.computeSHA1(model), model.getVersionId(), model.getAlternativeVersionId()));
543 }
545 > delete this._models[modelId];
546 > modelData.dispose();
547 >
548 > // clean up cache
549 > delete this._modelCreationOptionsByLanguageAndResource[model.getLanguageId() + model.uri];
550 >
551 > this._onModelRemoved.fire(model);
552 > }
553
554 private _onDidChangeLanguage(model: ITextModel, e: IModelLanguageChangedEvent): void {
562
563 protected _getSHA1Computer(): ITextModelSHA1Computer {
564 > return new DefaultModelSHA1Computer(); modelService.ts
565 > }
566 }
567
src/vs/editor/common/model/textModel.ts 5 introduced LOC · 2 ranges

Open complete file

322 this._associatedResource = URI.parse('inmemory://model/' + MODEL_ID);
323 } else {
324 > this._associatedResource = associatedResource; textModel.ts
325 > }
326 this._attachedEditorCount = 0;
327
764
765 public getInitialUndoRedoSnapshot(): ResourceEditStackSnapshot | null {
766 > this._assertNotDisposed(); textModel.ts
767 > return this._initialUndoRedoSnapshot;
768 > }
769
770 public getOffsetAt(rawPosition: IPosition): number {
src/vs/editor/test/common/services/testTextResourcePropertiesService.ts 2 introduced LOC · 1 range

Open complete file

21 const eol = this.configurationService.getValue('files.eol', { overrideIdentifier: language, resource });
22 if (eol && typeof eol === 'string' && eol !== 'auto') {
24 > }
25 return (platform.isLinux || platform.isMacintosh) ? '\n' : '\r\n';
26 }