mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Make MdWorkspaceCache always store promises
Makes working with the class easier
This commit is contained in:
@@ -20,7 +20,7 @@ function isLinkToHeader(target: LinkTarget, header: TocEntry, headerDocument: vs
|
||||
|
||||
export class MdReferencesProvider extends Disposable implements vscode.ReferenceProvider {
|
||||
|
||||
private readonly _linkCache: MdWorkspaceCache<Promise<LinkData[]>>;
|
||||
private readonly _linkCache: MdWorkspaceCache<LinkData[]>;
|
||||
|
||||
public constructor(
|
||||
private readonly linkProvider: MdLinkProvider,
|
||||
@@ -47,7 +47,7 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
|
||||
}
|
||||
|
||||
private async getReferencesToHeader(document: SkinnyTextDocument, header: TocEntry, context: vscode.ReferenceContext,): Promise<vscode.Location[] | undefined> {
|
||||
const links = (await Promise.all(await this._linkCache.getAll())).flat();
|
||||
const links = (await this._linkCache.getAll()).flat();
|
||||
|
||||
const references: vscode.Location[] = [];
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ import { MdWorkspaceContents, SkinnyTextDocument } from '../workspaceContents';
|
||||
*/
|
||||
export class MdWorkspaceCache<T> extends Disposable {
|
||||
|
||||
private readonly _cache = new Map<string, Lazy<T>>();
|
||||
private readonly _cache = new Map<string, Lazy<Promise<T>>>();
|
||||
private _hasPopulatedCache = false;
|
||||
|
||||
public constructor(
|
||||
private readonly workspaceContents: MdWorkspaceContents,
|
||||
private readonly getValue: (document: SkinnyTextDocument) => T,
|
||||
private readonly getValue: (document: SkinnyTextDocument) => Promise<T>,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ export class MdWorkspaceCache<T> extends Disposable {
|
||||
this.workspaceContents.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this, this._disposables);
|
||||
}
|
||||
|
||||
return Array.from(this._cache.values(), x => x.value);
|
||||
return Promise.all(Array.from(this._cache.values(), x => x.value));
|
||||
}
|
||||
|
||||
private async populateSymbolCache(): Promise<void> {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { MdWorkspaceCache } from './workspaceCache';
|
||||
|
||||
export class MdWorkspaceSymbolProvider extends Disposable implements vscode.WorkspaceSymbolProvider {
|
||||
|
||||
private readonly _cache: MdWorkspaceCache<Promise<vscode.SymbolInformation[]>>;
|
||||
private readonly _cache: MdWorkspaceCache<vscode.SymbolInformation[]>;
|
||||
|
||||
public constructor(
|
||||
symbolProvider: MdDocumentSymbolProvider,
|
||||
@@ -23,8 +23,7 @@ export class MdWorkspaceSymbolProvider extends Disposable implements vscode.Work
|
||||
}
|
||||
|
||||
public async provideWorkspaceSymbols(query: string): Promise<vscode.SymbolInformation[]> {
|
||||
const allSymbolSets = await this._cache.getAll();
|
||||
const allSymbols = (await Promise.all(allSymbolSets)).flat();
|
||||
const allSymbols = (await this._cache.getAll()).flat();
|
||||
return allSymbols.filter(symbolInformation => symbolInformation.name.toLowerCase().indexOf(query.toLowerCase()) !== -1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user