提交 54c3db12 编写于 作者: I isidor

fileEditorInput: do more caching and drop cache when new formatter registered

fixes #79742
上级 f144b5d5
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { memoize } from 'vs/base/common/decorators';
import { createMemoizer } from 'vs/base/common/decorators';
import { dirname } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { EncodingMode, ConfirmResult, EditorInput, IFileEditorInput, ITextEditorModel, Verbosity, IRevertOptions } from 'vs/workbench/common/editor';
......@@ -23,6 +23,7 @@ const enum ForceOpenAs {
Text,
Binary
}
const memoizer = createMemoizer();
/**
* A file editor input is the input type for the file editor of file system resources.
......@@ -34,7 +35,6 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
private forceOpenAs: ForceOpenAs = ForceOpenAs.None;
private textModelReference: Promise<IReference<ITextEditorModel>> | null = null;
private name: string;
/**
* An editor input who's contents are retrieved from file services.
......@@ -69,6 +69,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
this._register(this.textFileService.models.onModelSaved(e => this.onDirtyStateChange(e)));
this._register(this.textFileService.models.onModelReverted(e => this.onDirtyStateChange(e)));
this._register(this.textFileService.models.onModelOrphanedChanged(e => this.onModelOrphanedChanged(e)));
this._register(this.labelService.onDidChangeFormatters(() => memoizer.clear()));
}
private onDirtyStateChange(e: TextFileModelChangeEvent): void {
......@@ -144,22 +145,22 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
return FILE_EDITOR_INPUT_ID;
}
@memoizer
getName(): string {
if (!this.name) {
this.name = this.labelService.getUriBasenameLabel(this.resource);
}
return this.decorateLabel(this.name);
return this.decorateLabel(this.labelService.getUriBasenameLabel(this.resource));
}
@memoizer
private get shortDescription(): string {
return this.labelService.getUriBasenameLabel(dirname(this.resource));
}
@memoizer
private get mediumDescription(): string {
return this.labelService.getUriLabel(dirname(this.resource), { relative: true });
}
@memoizer
private get longDescription(): string {
return this.labelService.getUriLabel(dirname(this.resource));
}
......@@ -176,17 +177,17 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
}
}
@memoize
@memoizer
private get shortTitle(): string {
return this.getName();
}
@memoize
@memoizer
private get mediumTitle(): string {
return this.labelService.getUriLabel(this.resource, { relative: true });
}
@memoize
@memoizer
private get longTitle(): string {
return this.labelService.getUriLabel(this.resource);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册