From 811d3985ef47c2ac49d7ac09268e5c650de7abdd Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 25 Apr 2018 12:40:03 +0200 Subject: [PATCH] Fixes #48546: Merge editor.largeFileSize and editor.largeFileLineCount --- .../common/config/commonEditorConfig.ts | 13 ++++------ src/vs/editor/common/config/editorOptions.ts | 3 +-- src/vs/editor/common/model.ts | 3 +-- src/vs/editor/common/model/textModel.ts | 18 +++++++++----- .../common/services/modelServiceImpl.ts | 24 +++++-------------- src/vs/editor/test/common/editorTestUtils.ts | 6 ++--- 6 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 75efeb0c4c3..70f7b4053ee 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -687,15 +687,10 @@ const editorConfiguration: IConfigurationNode = { 'default': true, 'description': nls.localize('ignoreTrimWhitespace', "Controls if the diff editor shows changes in leading or trailing whitespace as diffs") }, - 'editor.largeFileSize': { - 'type': 'number', - 'default': EDITOR_MODEL_DEFAULTS.largeFileSize, - 'description': nls.localize('largeFileSize', "Controls file size threshold in bytes beyond which special optimization rules are applied") - }, - 'editor.largeFileLineCount': { - 'type': 'number', - 'default': EDITOR_MODEL_DEFAULTS.largeFileLineCount, - 'description': nls.localize('largeFileLineCount', "Controls file size threshold in terms of line count beyond which special optimization rules are applied") + 'editor.largeFileOptimizations': { + 'type': 'boolean', + 'default': EDITOR_MODEL_DEFAULTS.largeFileOptimizations, + 'description': nls.localize('largeFileOptimizations', "Special handling for large files to disable certain memory intensive features.") }, 'diffEditor.renderIndicators': { 'type': 'boolean', diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 61037c9f7d0..02f732afc75 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -2230,8 +2230,7 @@ export const EDITOR_MODEL_DEFAULTS = { insertSpaces: true, detectIndentation: true, trimAutoWhitespace: true, - largeFileSize: 20 * 1024 * 1024, // 20 MB - largeFileLineCount: 300 * 1000 // 300K lines + largeFileOptimizations: true }; /** diff --git a/src/vs/editor/common/model.ts b/src/vs/editor/common/model.ts index 3f628c4136a..3dcea7a7f55 100644 --- a/src/vs/editor/common/model.ts +++ b/src/vs/editor/common/model.ts @@ -400,8 +400,7 @@ export interface ITextModelCreationOptions { trimAutoWhitespace: boolean; defaultEOL: DefaultEndOfLine; isForSimpleWidget: boolean; - largeFileSize: number; - largeFileLineCount: number; + largeFileOptimizations: boolean; } export interface ITextModelUpdateOptions { diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index 8bad048eb1b..487668fe43f 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -155,6 +155,8 @@ class TextModelSnapshot implements ITextSnapshot { export class TextModel extends Disposable implements model.ITextModel { private static readonly MODEL_SYNC_LIMIT = 50 * 1024 * 1024; // 50 MB + private static readonly LARGE_FILE_SIZE_THRESHOLD = 20 * 1024 * 1024; // 20 MB; + private static readonly LARGE_FILE_LINE_COUNT_THRESHOLD = 300 * 1000; // 300K lines public static DEFAULT_CREATION_OPTIONS: model.ITextModelCreationOptions = { isForSimpleWidget: false, @@ -163,8 +165,7 @@ export class TextModel extends Disposable implements model.ITextModel { detectIndentation: false, defaultEOL: model.DefaultEndOfLine.LF, trimAutoWhitespace: EDITOR_MODEL_DEFAULTS.trimAutoWhitespace, - largeFileSize: EDITOR_MODEL_DEFAULTS.largeFileSize, - largeFileLineCount: EDITOR_MODEL_DEFAULTS.largeFileLineCount, + largeFileOptimizations: EDITOR_MODEL_DEFAULTS.largeFileOptimizations, }; public static createFromString(text: string, options: model.ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null, uri: URI = null): TextModel { @@ -285,13 +286,18 @@ export class TextModel extends Disposable implements model.ITextModel { const bufferLineCount = this._buffer.getLineCount(); const bufferTextLength = this._buffer.getValueLengthInRange(new Range(1, 1, bufferLineCount, this._buffer.getLineLength(bufferLineCount) + 1), model.EndOfLinePreference.TextDefined); + // !!! Make a decision in the ctor and permanently respect this decision !!! // If a model is too large at construction time, it will never get tokenized, // under no circumstances. - this._isTooLargeForTokenization = ( - (bufferTextLength > creationOptions.largeFileSize) - || (bufferLineCount > creationOptions.largeFileLineCount) - ); + if (creationOptions.largeFileOptimizations) { + this._isTooLargeForTokenization = ( + (bufferTextLength > TextModel.LARGE_FILE_SIZE_THRESHOLD) + || (bufferLineCount > TextModel.LARGE_FILE_LINE_COUNT_THRESHOLD) + ); + } else { + this._isTooLargeForTokenization = false; + } this._shouldSimplifyMode = ( this._isTooLargeForTokenization diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index 6490f6d7a0e..4d5123785ab 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -205,8 +205,8 @@ interface IRawConfig { insertSpaces?: any; detectIndentation?: any; trimAutoWhitespace?: any; - largeFileSize?: any; - largeFileLineCount?: any; + creationOptions?: any; + largeFileOptimizations?: any; }; } @@ -285,20 +285,9 @@ export class ModelServiceImpl implements IModelService { detectIndentation = (config.editor.detectIndentation === 'false' ? false : Boolean(config.editor.detectIndentation)); } - let largeFileSize = EDITOR_MODEL_DEFAULTS.largeFileSize; - if (config.editor && typeof config.editor.largeFileSize !== 'undefined') { - let parsedlargeFileSize = parseInt(config.editor.largeFileSize, 10); - if (!isNaN(parsedlargeFileSize)) { - largeFileSize = parsedlargeFileSize; - } - } - - let largeFileLineCount = EDITOR_MODEL_DEFAULTS.largeFileLineCount; - if (config.editor && typeof config.editor.largeFileLineCount !== 'undefined') { - let parsedlargeFileLineCount = parseInt(config.editor.largeFileLineCount, 10); - if (!isNaN(parsedlargeFileLineCount)) { - largeFileLineCount = parsedlargeFileLineCount; - } + let largeFileOptimizations = EDITOR_MODEL_DEFAULTS.largeFileOptimizations; + if (config.editor && typeof config.editor.largeFileOptimizations !== 'undefined') { + largeFileOptimizations = (config.editor.largeFileOptimizations === 'false' ? false : Boolean(config.editor.largeFileOptimizations)); } return { @@ -308,8 +297,7 @@ export class ModelServiceImpl implements IModelService { detectIndentation: detectIndentation, defaultEOL: newDefaultEOL, trimAutoWhitespace: trimAutoWhitespace, - largeFileSize: largeFileSize, - largeFileLineCount: largeFileLineCount + largeFileOptimizations: largeFileOptimizations }; } diff --git a/src/vs/editor/test/common/editorTestUtils.ts b/src/vs/editor/test/common/editorTestUtils.ts index d2e8cb2072e..d5ba6be54b1 100644 --- a/src/vs/editor/test/common/editorTestUtils.ts +++ b/src/vs/editor/test/common/editorTestUtils.ts @@ -22,8 +22,7 @@ export interface IRelaxedTextModelCreationOptions { trimAutoWhitespace?: boolean; defaultEOL?: DefaultEndOfLine; isForSimpleWidget?: boolean; - largeFileSize?: number; - largeFileLineCount?: number; + largeFileOptimizations?: boolean; } export function createTextModel(text: string, _options: IRelaxedTextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null, uri: URI = null): TextModel { @@ -34,8 +33,7 @@ export function createTextModel(text: string, _options: IRelaxedTextModelCreatio trimAutoWhitespace: (typeof _options.trimAutoWhitespace === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.trimAutoWhitespace : _options.trimAutoWhitespace), defaultEOL: (typeof _options.defaultEOL === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.defaultEOL : _options.defaultEOL), isForSimpleWidget: (typeof _options.isForSimpleWidget === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.isForSimpleWidget : _options.isForSimpleWidget), - largeFileSize: (typeof _options.largeFileSize === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.largeFileSize : _options.largeFileSize), - largeFileLineCount: (typeof _options.largeFileLineCount === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.largeFileLineCount : _options.largeFileLineCount), + largeFileOptimizations: (typeof _options.largeFileOptimizations === 'undefined' ? TextModel.DEFAULT_CREATION_OPTIONS.largeFileOptimizations : _options.largeFileOptimizations), }; return TextModel.createFromString(text, options, languageIdentifier, uri); }