-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fileEditorInput: do more caching and drop cache when new formatter re…
…gistered fixes #79742
- Loading branch information
Showing
1 changed file
with
11 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
isidorn
Author
Contributor
|
||
|
||
/** | ||
* 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); | ||
} | ||
|
@isidorn why not
static
onFileEditorInput
?