提交 8a04f8fe 编写于 作者: M Max Sysoev 提交者: Alex Dima

Add maxTokenizationLineLength configuration option

上级 98953dd9
...@@ -832,6 +832,11 @@ const editorConfiguration: IConfigurationNode = { ...@@ -832,6 +832,11 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.contribInfo.lightbulbEnabled, 'default': EDITOR_DEFAULTS.contribInfo.lightbulbEnabled,
'description': nls.localize('codeActions', "Enables the code action lightbulb in the editor.") 'description': nls.localize('codeActions', "Enables the code action lightbulb in the editor.")
}, },
'editor.maxTokenizationLineLength': {
'type': 'integer',
'default': 20_000,
'description': nls.localize('maxTokenizationLineLength', "Configures length of lines, for which tokenization process will be skipped for performance reasons")
},
'editor.codeActionsOnSave': { 'editor.codeActionsOnSave': {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom'; import * as dom from 'vs/base/browser/dom';
import { Color } from 'vs/base/common/color'; import { Color } from 'vs/base/common/color';
import { onUnexpectedError } from 'vs/base/common/errors'; import { onUnexpectedError } from 'vs/base/common/errors';
...@@ -12,18 +11,21 @@ import * as resources from 'vs/base/common/resources'; ...@@ -12,18 +11,21 @@ import * as resources from 'vs/base/common/resources';
import * as types from 'vs/base/common/types'; import * as types from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token'; import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
import { IState, ITokenizationSupport, LanguageId, TokenMetadata, TokenizationRegistry } from 'vs/editor/common/modes'; import { IState, ITokenizationSupport, LanguageId, TokenizationRegistry, TokenMetadata } from 'vs/editor/common/modes';
import { nullTokenize2 } from 'vs/editor/common/modes/nullMode'; import { nullTokenize2 } from 'vs/editor/common/modes/nullMode';
import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization'; import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import * as nls from 'vs/nls';
import { IFileService } from 'vs/platform/files/common/files'; import { IFileService } from 'vs/platform/files/common/files';
import { ILogService } from 'vs/platform/log/common/log'; import { ILogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { IEmbeddedLanguagesMap, ITMSyntaxExtensionPoint, TokenTypesContribution, grammarsExtPoint } from 'vs/workbench/services/textMate/electron-browser/TMGrammars';
import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService'; import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService';
import { grammarsExtPoint, IEmbeddedLanguagesMap, ITMSyntaxExtensionPoint, TokenTypesContribution } from 'vs/workbench/services/textMate/electron-browser/TMGrammars';
import { ITokenColorizationRule, IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { ITokenColorizationRule, IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2, IGrammar, ITokenTypeMap, Registry, StackElement, StandardTokenType } from 'vscode-textmate'; import { IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2, IGrammar, ITokenTypeMap, Registry, StackElement, StandardTokenType } from 'vscode-textmate';
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
export class TMScopeRegistry { export class TMScopeRegistry {
...@@ -158,7 +160,8 @@ export class TextMateService extends Disposable implements ITextMateService { ...@@ -158,7 +160,8 @@ export class TextMateService extends Disposable implements ITextMateService {
@IWorkbenchThemeService private readonly _themeService: IWorkbenchThemeService, @IWorkbenchThemeService private readonly _themeService: IWorkbenchThemeService,
@IFileService private readonly _fileService: IFileService, @IFileService private readonly _fileService: IFileService,
@INotificationService private readonly _notificationService: INotificationService, @INotificationService private readonly _notificationService: INotificationService,
@ILogService private readonly _logService: ILogService @ILogService private readonly _logService: ILogService,
@IConfigurationService private readonly _configurationService: ConfigurationService
) { ) {
super(); super();
this._styleElement = dom.createStyleSheet(); this._styleElement = dom.createStyleSheet();
...@@ -226,7 +229,7 @@ export class TextMateService extends Disposable implements ITextMateService { ...@@ -226,7 +229,7 @@ export class TextMateService extends Disposable implements ITextMateService {
private _registerDefinitionIfAvailable(modeId: string): void { private _registerDefinitionIfAvailable(modeId: string): void {
if (this._languageToScope.has(modeId)) { if (this._languageToScope.has(modeId)) {
const promise = this._createGrammar(modeId).then((r) => { const promise = this._createGrammar(modeId).then((r) => {
return new TMTokenization(this._scopeRegistry, r.languageId, r.grammar, r.initialState, r.containsEmbeddedLanguages, this._notificationService); return new TMTokenization(this._scopeRegistry, r.languageId, r.grammar, r.initialState, r.containsEmbeddedLanguages, this._notificationService, this._configurationService);
}, e => { }, e => {
onUnexpectedError(e); onUnexpectedError(e);
return null; return null;
...@@ -442,15 +445,17 @@ class TMTokenization implements ITokenizationSupport { ...@@ -442,15 +445,17 @@ class TMTokenization implements ITokenizationSupport {
private readonly _containsEmbeddedLanguages: boolean; private readonly _containsEmbeddedLanguages: boolean;
private readonly _seenLanguages: boolean[]; private readonly _seenLanguages: boolean[];
private readonly _initialState: StackElement; private readonly _initialState: StackElement;
private _maxTokenizationLineLength: number;
private _tokenizationWarningAlreadyShown: boolean; private _tokenizationWarningAlreadyShown: boolean;
constructor(scopeRegistry: TMScopeRegistry, languageId: LanguageId, grammar: IGrammar, initialState: StackElement, containsEmbeddedLanguages: boolean, @INotificationService private readonly notificationService: INotificationService) { constructor(scopeRegistry: TMScopeRegistry, languageId: LanguageId, grammar: IGrammar, initialState: StackElement, containsEmbeddedLanguages: boolean, @INotificationService private readonly notificationService: INotificationService, @IConfigurationService readonly configurationService: IConfigurationService) {
this._scopeRegistry = scopeRegistry; this._scopeRegistry = scopeRegistry;
this._languageId = languageId; this._languageId = languageId;
this._grammar = grammar; this._grammar = grammar;
this._initialState = initialState; this._initialState = initialState;
this._containsEmbeddedLanguages = containsEmbeddedLanguages; this._containsEmbeddedLanguages = containsEmbeddedLanguages;
this._seenLanguages = []; this._seenLanguages = [];
this._maxTokenizationLineLength = configurationService.getValue<number>('editor.maxTokenizationLineLength');
} }
public getInitialState(): IState { public getInitialState(): IState {
...@@ -466,13 +471,13 @@ class TMTokenization implements ITokenizationSupport { ...@@ -466,13 +471,13 @@ class TMTokenization implements ITokenizationSupport {
throw new Error('Unexpected: offsetDelta should be 0.'); throw new Error('Unexpected: offsetDelta should be 0.');
} }
// Do not attempt to tokenize if a line has over 20k // Do not attempt to tokenize if a line is too long
if (line.length >= 20000) { if (line.length >= this._maxTokenizationLineLength) {
if (!this._tokenizationWarningAlreadyShown) { if (!this._tokenizationWarningAlreadyShown) {
this._tokenizationWarningAlreadyShown = true; this._tokenizationWarningAlreadyShown = true;
this.notificationService.warn(nls.localize('too many characters', "Tokenization is skipped for lines longer than 20k characters for performance reasons.")); this.notificationService.warn(nls.localize('too many characters', 'Tokenization is skipped for long lines for performance reasons. The length of a long line can be set by configuring editor.maxTokenizationLineLength in settings'));
} }
console.log(`Line (${line.substr(0, 15)}...): longer than 20k characters, tokenization skipped.`); console.log(`Line (${line.substr(0, 15)}...): longer than ${this._maxTokenizationLineLength} characters, tokenization skipped.`);
return nullTokenize2(this._languageId, line, state, offsetDelta); return nullTokenize2(this._languageId, line, state, offsetDelta);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册