diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index b1938677456..3c463fe6c46 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -668,6 +668,16 @@ 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") + }, 'diffEditor.renderIndicators': { 'type': 'boolean', 'default': true, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index ebbd7a52cb2..48d76961005 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -2204,7 +2204,9 @@ export const EDITOR_MODEL_DEFAULTS = { tabSize: 4, insertSpaces: true, detectIndentation: true, - trimAutoWhitespace: true + trimAutoWhitespace: true, + largeFileSize: 20 * 1024 * 1024, // 20 MB + largeFileLineCount: 300 * 1000 // 300K lines }; /** diff --git a/src/vs/editor/common/model.ts b/src/vs/editor/common/model.ts index ff909869d8e..b8c7a186cae 100644 --- a/src/vs/editor/common/model.ts +++ b/src/vs/editor/common/model.ts @@ -396,6 +396,8 @@ export interface ITextModelCreationOptions { trimAutoWhitespace: boolean; defaultEOL: DefaultEndOfLine; isForSimpleWidget: boolean; + largeFileSize: number; + largeFileLineCount: number; } export interface ITextModelUpdateOptions { diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index 3975b563698..53d6bc2df0e 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -155,8 +155,6 @@ 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 MODEL_TOKENIZATION_LIMIT = 20 * 1024 * 1024; // 20 MB - private static readonly MANY_MANY_LINES = 300 * 1000; // 300K lines public static DEFAULT_CREATION_OPTIONS: model.ITextModelCreationOptions = { isForSimpleWidget: false, @@ -165,6 +163,8 @@ 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, }; public static createFromString(text: string, options: model.ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null, uri: URI = null): TextModel { @@ -289,8 +289,8 @@ export class TextModel extends Disposable implements model.ITextModel { // If a model is too large at construction time, it will never get tokenized, // under no circumstances. this._isTooLargeForTokenization = ( - (bufferTextLength > TextModel.MODEL_TOKENIZATION_LIMIT) - || (bufferLineCount > TextModel.MANY_MANY_LINES) + (bufferTextLength > creationOptions.largeFileSize) + || (bufferLineCount > creationOptions.largeFileLineCount) ); this._shouldSimplifyMode = ( diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index fa395f924f0..b189ac8390c 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -197,6 +197,8 @@ interface IRawConfig { insertSpaces?: any; detectIndentation?: any; trimAutoWhitespace?: any; + largeFileSize?: any; + largeFileLineCount?: any; }; } @@ -275,13 +277,31 @@ 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; + } + } + return { isForSimpleWidget: isForSimpleWidget, tabSize: tabSize, insertSpaces: insertSpaces, detectIndentation: detectIndentation, defaultEOL: newDefaultEOL, - trimAutoWhitespace: trimAutoWhitespace + trimAutoWhitespace: trimAutoWhitespace, + largeFileSize: largeFileSize, + largeFileLineCount: largeFileLineCount }; } diff --git a/src/vs/editor/test/common/editorTestUtils.ts b/src/vs/editor/test/common/editorTestUtils.ts index 9c7ed1e9826..d2e8cb2072e 100644 --- a/src/vs/editor/test/common/editorTestUtils.ts +++ b/src/vs/editor/test/common/editorTestUtils.ts @@ -22,6 +22,8 @@ export interface IRelaxedTextModelCreationOptions { trimAutoWhitespace?: boolean; defaultEOL?: DefaultEndOfLine; isForSimpleWidget?: boolean; + largeFileSize?: number; + largeFileLineCount?: number; } export function createTextModel(text: string, _options: IRelaxedTextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null, uri: URI = null): TextModel { @@ -32,6 +34,8 @@ 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), }; return TextModel.createFromString(text, options, languageIdentifier, uri); }