提交 66575b23 编写于 作者: P Peng Lyu

Fix #56773.

上级 36e08fed
...@@ -18,7 +18,8 @@ import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/to ...@@ -18,7 +18,8 @@ import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/to
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
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, Severity } from 'vs/platform/notification/common/notification';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { ITMSyntaxExtensionPoint, grammarsExtPoint } from 'vs/workbench/services/textMate/common/TMGrammars'; import { ITMSyntaxExtensionPoint, grammarsExtPoint } from 'vs/workbench/services/textMate/common/TMGrammars';
import { ITextMateService } from 'vs/workbench/services/textMate/common/textMateService'; import { ITextMateService } from 'vs/workbench/services/textMate/common/textMateService';
...@@ -50,7 +51,8 @@ export abstract class AbstractTextMateService extends Disposable implements ITex ...@@ -50,7 +51,8 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
@IFileService protected readonly _fileService: IFileService, @IFileService protected 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: IConfigurationService @IConfigurationService private readonly _configurationService: IConfigurationService,
@IStorageService private readonly _storageService: IStorageService
) { ) {
super(); super();
this._styleElement = dom.createStyleSheet(); this._styleElement = dom.createStyleSheet();
...@@ -219,7 +221,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex ...@@ -219,7 +221,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
this._onDidEncounterLanguage.fire(languageId); this._onDidEncounterLanguage.fire(languageId);
} }
}); });
return new TMTokenizationSupport(r.languageId, tokenization, this._notificationService, this._configurationService); return new TMTokenizationSupport(r.languageId, tokenization, this._notificationService, this._configurationService, this._storageService);
}, e => { }, e => {
onUnexpectedError(e); onUnexpectedError(e);
return null; return null;
...@@ -328,6 +330,8 @@ export abstract class AbstractTextMateService extends Disposable implements ITex ...@@ -328,6 +330,8 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
protected abstract _loadOnigLib(): Promise<IOnigLib> | undefined; protected abstract _loadOnigLib(): Promise<IOnigLib> | undefined;
} }
const donotAskUpdateKey = 'editor.maxTokenizationLineLength.donotask';
class TMTokenizationSupport implements ITokenizationSupport { class TMTokenizationSupport implements ITokenizationSupport {
private readonly _languageId: LanguageId; private readonly _languageId: LanguageId;
private readonly _actual: TMTokenization; private readonly _actual: TMTokenization;
...@@ -338,11 +342,12 @@ class TMTokenizationSupport implements ITokenizationSupport { ...@@ -338,11 +342,12 @@ class TMTokenizationSupport implements ITokenizationSupport {
languageId: LanguageId, languageId: LanguageId,
actual: TMTokenization, actual: TMTokenization,
@INotificationService private readonly _notificationService: INotificationService, @INotificationService private readonly _notificationService: INotificationService,
@IConfigurationService private readonly _configurationService: IConfigurationService @IConfigurationService private readonly _configurationService: IConfigurationService,
@IStorageService private readonly _storageService: IStorageService
) { ) {
this._languageId = languageId; this._languageId = languageId;
this._actual = actual; this._actual = actual;
this._tokenizationWarningAlreadyShown = false; this._tokenizationWarningAlreadyShown = !!(this._storageService.getBoolean(donotAskUpdateKey, StorageScope.GLOBAL));
this._maxTokenizationLineLength = this._configurationService.getValue<number>('editor.maxTokenizationLineLength'); this._maxTokenizationLineLength = this._configurationService.getValue<number>('editor.maxTokenizationLineLength');
this._configurationService.onDidChangeConfiguration(e => { this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('editor.maxTokenizationLineLength')) { if (e.affectsConfiguration('editor.maxTokenizationLineLength')) {
...@@ -368,7 +373,15 @@ class TMTokenizationSupport implements ITokenizationSupport { ...@@ -368,7 +373,15 @@ class TMTokenizationSupport implements ITokenizationSupport {
if (line.length >= this._maxTokenizationLineLength) { 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 long lines for performance reasons. The length of a long line can be configured via `editor.maxTokenizationLineLength`.")); this._notificationService.prompt(
Severity.Warning,
nls.localize('too many characters', "Tokenization is skipped for long lines for performance reasons. The length of a long line can be configured via `editor.maxTokenizationLineLength`."),
[{
label: nls.localize('neverAgain', "Don't Show Again"),
isSecondary: true,
run: () => this._storageService.store(donotAskUpdateKey, true, StorageScope.GLOBAL)
}]
);
} }
console.log(`Line (${line.substr(0, 15)}...): longer than ${this._maxTokenizationLineLength} 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);
......
...@@ -14,6 +14,7 @@ import { ILogService } from 'vs/platform/log/common/log'; ...@@ -14,6 +14,7 @@ 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 { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IStorageService } from 'vs/platform/storage/common/storage';
export class TextMateService extends AbstractTextMateService { export class TextMateService extends AbstractTextMateService {
...@@ -23,9 +24,10 @@ export class TextMateService extends AbstractTextMateService { ...@@ -23,9 +24,10 @@ export class TextMateService extends AbstractTextMateService {
@IFileService fileService: IFileService, @IFileService fileService: IFileService,
@INotificationService notificationService: INotificationService, @INotificationService notificationService: INotificationService,
@ILogService logService: ILogService, @ILogService logService: ILogService,
@IConfigurationService configurationService: IConfigurationService @IConfigurationService configurationService: IConfigurationService,
@IStorageService storageService: IStorageService
) { ) {
super(modeService, themeService, fileService, notificationService, logService, configurationService); super(modeService, themeService, fileService, notificationService, logService, configurationService, storageService);
} }
protected _loadVSCodeTextmate(): Promise<typeof import('vscode-textmate')> { protected _loadVSCodeTextmate(): Promise<typeof import('vscode-textmate')> {
......
...@@ -20,6 +20,7 @@ import { TextMateWorker } from 'vs/workbench/services/textMate/electron-browser/ ...@@ -20,6 +20,7 @@ import { TextMateWorker } from 'vs/workbench/services/textMate/electron-browser/
import { ITextModel } from 'vs/editor/common/model'; import { ITextModel } from 'vs/editor/common/model';
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { UriComponents, URI } from 'vs/base/common/uri'; import { UriComponents, URI } from 'vs/base/common/uri';
import { IStorageService } from 'vs/platform/storage/common/storage';
const RUN_TEXTMATE_IN_WORKER = false; const RUN_TEXTMATE_IN_WORKER = false;
...@@ -110,9 +111,10 @@ export class TextMateService extends AbstractTextMateService { ...@@ -110,9 +111,10 @@ export class TextMateService extends AbstractTextMateService {
@INotificationService notificationService: INotificationService, @INotificationService notificationService: INotificationService,
@ILogService logService: ILogService, @ILogService logService: ILogService,
@IConfigurationService configurationService: IConfigurationService, @IConfigurationService configurationService: IConfigurationService,
@IStorageService storageService: IStorageService,
@IModelService private readonly _modelService: IModelService, @IModelService private readonly _modelService: IModelService,
) { ) {
super(modeService, themeService, fileService, notificationService, logService, configurationService); super(modeService, themeService, fileService, notificationService, logService, configurationService, storageService);
this._worker = null; this._worker = null;
this._workerProxy = null; this._workerProxy = null;
this._tokenizers = Object.create(null); this._tokenizers = Object.create(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册