-
Notifications
You must be signed in to change notification settings - Fork 27.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #44206: Inform when a large file is opened and features are tur…
…ned off
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/vs/workbench/parts/codeEditor/electron-browser/largeFileOptimizations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import * as nls from 'vs/nls'; | ||
import * as path from 'path'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { IEditorContribution } from 'vs/editor/common/editorCommon'; | ||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; | ||
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; | ||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; | ||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
|
||
/** | ||
* Shows a message when opening a large file which has been memory optimized (and features disabled). | ||
*/ | ||
export class LargeFileOptimizationsWarner extends Disposable implements IEditorContribution { | ||
|
||
private static readonly ID = 'editor.contrib.largeFileOptimizationsWarner'; | ||
|
||
private _isDisabled: boolean; | ||
|
||
constructor( | ||
private readonly _editor: ICodeEditor, | ||
@INotificationService private readonly _notificationService: INotificationService, | ||
@IConfigurationService private readonly _configurationService: IConfigurationService, | ||
@IStorageService private readonly _storageService: IStorageService, | ||
) { | ||
super(); | ||
|
||
this._isDisabled = this._storageService.getBoolean('editor.neverPromptForLargeFiles', StorageScope.GLOBAL, false); | ||
|
||
this._register(this._editor.onDidChangeModel((e) => { | ||
const model = this._editor.getModel(); | ||
if (!model) { | ||
return; | ||
} | ||
if (this._isDisabled) { | ||
return; | ||
} | ||
|
||
if (model.isTooLargeForTokenization()) { | ||
const message = nls.localize( | ||
{ | ||
key: 'largeFile', | ||
comment: [ | ||
'Variable 0 will be a file name.' | ||
] | ||
}, | ||
"{0}: tokenization, wrapping and folding have been turned off for this large file in order to reduce memory usage and avoid freezing or crashing.", | ||
path.basename(model.uri.path) | ||
); | ||
|
||
this._notificationService.prompt(Severity.Info, message, [ | ||
{ | ||
label: nls.localize('neverShowAgain', "OK. Never show again"), | ||
run: () => { | ||
this._isDisabled = true; | ||
this._storageService.store('editor.neverPromptForLargeFiles', true, StorageScope.GLOBAL); | ||
} | ||
}, | ||
{ | ||
label: nls.localize('removeOptimizations', "Forcefully enable features"), | ||
run: () => { | ||
this._configurationService.updateValue(`editor.largeFileOptimizations`, false).then(() => { | ||
this._notificationService.info(nls.localize('reopenFilePrompt', "Please reopen file in order for this setting to take effect.")); | ||
}, (err) => { | ||
this._notificationService.error(err); | ||
}); | ||
} | ||
} | ||
]); | ||
} | ||
})); | ||
} | ||
|
||
public getId(): string { | ||
return LargeFileOptimizationsWarner.ID; | ||
} | ||
} | ||
|
||
registerEditorContribution(LargeFileOptimizationsWarner); |