Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/codeEditor/browser/largeFileOptimizations.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as nls from '../../../../nls.js';
7
import * as path from '../../../../base/common/path.js';
8
import { Disposable } from '../../../../base/common/lifecycle.js';
9
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
10
import { EditorContributionInstantiation, registerEditorContribution } from '../../../../editor/browser/editorExtensions.js';
11
import { IEditorContribution } from '../../../../editor/common/editorCommon.js';
12
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
13
import { INotificationService, Severity } from '../../../../platform/notification/common/notification.js';
14
15
/**
16
* Shows a message when opening a large file which has been memory optimized (and features disabled).
17
*/
18
export class LargeFileOptimizationsWarner extends Disposable implements IEditorContribution {
19
20
public static readonly ID = 'editor.contrib.largeFileOptimizationsWarner';
21
22
constructor(
23
private readonly _editor: ICodeEditor,
24
@INotificationService private readonly _notificationService: INotificationService,
25
@IConfigurationService private readonly _configurationService: IConfigurationService,
26
) {
27
super();
28
29
this._register(this._editor.onDidChangeModel((e) => this._update()));
30
this._update();
31
}
32
33
private _update(): void {
34
const model = this._editor.getModel();
35
if (!model) {
36
return;
37
}
38
39
if (model.isTooLargeForTokenization()) {
40
const message = nls.localize(
41
{
42
key: 'largeFile',
43
comment: [
44
'Variable 0 will be a file name.'
45
]
46
},
47
"{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.",
48
path.basename(model.uri.path)
49
);
50
51
this._notificationService.prompt(Severity.Info, message, [
52
{
53
label: nls.localize('removeOptimizations', "Forcefully Enable Features"),
54
run: () => {
55
this._configurationService.updateValue(`editor.largeFileOptimizations`, false).then(() => {
56
this._notificationService.info(nls.localize('reopenFilePrompt', "Please reopen file in order for this setting to take effect."));
57
}, (err) => {
58
this._notificationService.error(err);
59
});
60
}
61
}
62
], { neverShowAgain: { id: 'editor.contrib.largeFileOptimizationsWarner' } });
63
}
64
}
65
}
66
67
registerEditorContribution(LargeFileOptimizationsWarner.ID, LargeFileOptimizationsWarner, EditorContributionInstantiation.AfterFirstRender);
68
69