Fixes #48546: Merge editor.largeFileSize and editor.largeFileLineCount

This commit is contained in:
Alex Dima
2018-04-25 12:40:03 +02:00
parent 05bca58420
commit 811d3985ef
6 changed files with 26 additions and 41 deletions
@@ -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',
+1 -2
View File
@@ -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
};
/**
+1 -2
View File
@@ -400,8 +400,7 @@ export interface ITextModelCreationOptions {
trimAutoWhitespace: boolean;
defaultEOL: DefaultEndOfLine;
isForSimpleWidget: boolean;
largeFileSize: number;
largeFileLineCount: number;
largeFileOptimizations: boolean;
}
export interface ITextModelUpdateOptions {
+12 -6
View File
@@ -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
@@ -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
};
}
+2 -4
View File
@@ -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);
}