Path: blob/main/src/vs/workbench/contrib/codeEditor/browser/largeFileOptimizations.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as nls from '../../../../nls.js';6import * as path from '../../../../base/common/path.js';7import { Disposable } from '../../../../base/common/lifecycle.js';8import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';9import { EditorContributionInstantiation, registerEditorContribution } from '../../../../editor/browser/editorExtensions.js';10import { IEditorContribution } from '../../../../editor/common/editorCommon.js';11import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';12import { INotificationService, Severity } from '../../../../platform/notification/common/notification.js';1314/**15* Shows a message when opening a large file which has been memory optimized (and features disabled).16*/17export class LargeFileOptimizationsWarner extends Disposable implements IEditorContribution {1819public static readonly ID = 'editor.contrib.largeFileOptimizationsWarner';2021constructor(22private readonly _editor: ICodeEditor,23@INotificationService private readonly _notificationService: INotificationService,24@IConfigurationService private readonly _configurationService: IConfigurationService,25) {26super();2728this._register(this._editor.onDidChangeModel((e) => this._update()));29this._update();30}3132private _update(): void {33const model = this._editor.getModel();34if (!model) {35return;36}3738if (model.isTooLargeForTokenization()) {39const message = nls.localize(40{41key: 'largeFile',42comment: [43'Variable 0 will be a file name.'44]45},46"{0}: tokenization, wrapping, folding, codelens, word highlighting and sticky scroll have been turned off for this large file in order to reduce memory usage and avoid freezing or crashing.",47path.basename(model.uri.path)48);4950this._notificationService.prompt(Severity.Info, message, [51{52label: nls.localize('removeOptimizations', "Forcefully Enable Features"),53run: () => {54this._configurationService.updateValue(`editor.largeFileOptimizations`, false).then(() => {55this._notificationService.info(nls.localize('reopenFilePrompt', "Please reopen file in order for this setting to take effect."));56}, (err) => {57this._notificationService.error(err);58});59}60}61], { neverShowAgain: { id: 'editor.contrib.largeFileOptimizationsWarner' } });62}63}64}6566registerEditorContribution(LargeFileOptimizationsWarner.ID, LargeFileOptimizationsWarner, EditorContributionInstantiation.AfterFirstRender);676869