未验证 提交 81fb0cfc 编写于 作者: A Alex Dima

Fixes #96694: Use `files.restoreUndoStack` instead of `files.maxMemoryForClosedFilesUndoStackMB`

上级 d62c642e
...@@ -148,6 +148,8 @@ class DisposedModelInfo { ...@@ -148,6 +148,8 @@ class DisposedModelInfo {
export class ModelServiceImpl extends Disposable implements IModelService { export class ModelServiceImpl extends Disposable implements IModelService {
public static MAX_MEMORY_FOR_CLOSED_FILES_UNDO_STACK = 20 * 1024 * 1024;
public _serviceBrand: undefined; public _serviceBrand: undefined;
private readonly _onModelAdded: Emitter<ITextModel> = this._register(new Emitter<ITextModel>()); private readonly _onModelAdded: Emitter<ITextModel> = this._register(new Emitter<ITextModel>());
...@@ -263,12 +265,12 @@ export class ModelServiceImpl extends Disposable implements IModelService { ...@@ -263,12 +265,12 @@ export class ModelServiceImpl extends Disposable implements IModelService {
return platform.OS === platform.OperatingSystem.Linux || platform.OS === platform.OperatingSystem.Macintosh ? '\n' : '\r\n'; return platform.OS === platform.OperatingSystem.Linux || platform.OS === platform.OperatingSystem.Macintosh ? '\n' : '\r\n';
} }
private _getMaxMemoryForClosedFilesUndoStack(): number { private _shouldRestoreUndoStack(): boolean {
const result = this._configurationService.getValue<number>('files.maxMemoryForClosedFilesUndoStackMB'); const result = this._configurationService.getValue<boolean>('files.restoreUndoStack');
if (typeof result === 'number') { if (typeof result === 'boolean') {
return result * 1024 * 1024; return result;
} }
return 20 * 1024 * 1024; return true;
} }
public getCreationOptions(language: string, resource: URI | undefined, isForSimpleWidget: boolean): ITextModelCreationOptions { public getCreationOptions(language: string, resource: URI | undefined, isForSimpleWidget: boolean): ITextModelCreationOptions {
...@@ -504,7 +506,7 @@ export class ModelServiceImpl extends Disposable implements IModelService { ...@@ -504,7 +506,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
const model = modelData.model; const model = modelData.model;
let maintainUndoRedoStack = false; let maintainUndoRedoStack = false;
let heapSize = 0; let heapSize = 0;
if (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote || resource.scheme === Schemas.userData) { if (this._shouldRestoreUndoStack() && (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote || resource.scheme === Schemas.userData)) {
const elements = this._undoRedoService.getElements(resource); const elements = this._undoRedoService.getElements(resource);
if ((elements.past.length > 0 || elements.future.length > 0) && isEditStackPastFutureElements(elements)) { if ((elements.past.length > 0 || elements.future.length > 0) && isEditStackPastFutureElements(elements)) {
maintainUndoRedoStack = true; maintainUndoRedoStack = true;
...@@ -516,8 +518,6 @@ export class ModelServiceImpl extends Disposable implements IModelService { ...@@ -516,8 +518,6 @@ export class ModelServiceImpl extends Disposable implements IModelService {
heapSize += element.heapSize(resource); heapSize += element.heapSize(resource);
element.setModel(resource); // remove reference from text buffer instance element.setModel(resource); // remove reference from text buffer instance
} }
} else {
maintainUndoRedoStack = false;
} }
} }
...@@ -527,7 +527,7 @@ export class ModelServiceImpl extends Disposable implements IModelService { ...@@ -527,7 +527,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
return; return;
} }
const maxMemory = this._getMaxMemoryForClosedFilesUndoStack(); const maxMemory = ModelServiceImpl.MAX_MEMORY_FOR_CLOSED_FILES_UNDO_STACK;
if (heapSize > maxMemory) { if (heapSize > maxMemory) {
// the undo stack for this file would never fit in the configured memory, so don't bother with it. // the undo stack for this file would never fit in the configured memory, so don't bother with it.
this._undoRedoService.removeElements(resource); this._undoRedoService.removeElements(resource);
......
...@@ -320,10 +320,10 @@ configurationRegistry.registerConfiguration({ ...@@ -320,10 +320,10 @@ configurationRegistry.registerConfiguration({
'markdownDescription': nls.localize('maxMemoryForLargeFilesMB', "Controls the memory available to VS Code after restart when trying to open large files. Same effect as specifying `--max-memory=NEWSIZE` on the command line."), 'markdownDescription': nls.localize('maxMemoryForLargeFilesMB', "Controls the memory available to VS Code after restart when trying to open large files. Same effect as specifying `--max-memory=NEWSIZE` on the command line."),
included: platform.isNative included: platform.isNative
}, },
'files.maxMemoryForClosedFilesUndoStackMB': { 'files.restoreUndoStack': {
'type': 'number', 'type': 'boolean',
'default': 20, 'description': nls.localize('files.restoreUndoStack', "Restore the undo stack when a file is reopened."),
'markdownDescription': nls.localize('maxMemoryForClosedFilesUndoStackMB', "Controls the maximum ammount of memory the undo stack should hold for files that have been closed.") 'default': true
}, },
'files.saveConflictResolution': { 'files.saveConflictResolution': {
'type': 'string', 'type': 'string',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册