mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 08:38:56 +01:00
Reduce recomputation of state in markdown extension (#152804)
* Reduce recomputation of state in markdown extension - Use `getForDocument` more often to avoid refetching documents - Debounce `MdTableOfContentsWatcher`. We don't want this to trigger on every keystroke :) * Cache LinkDefinitionSet * Add test file change * Fix toc watcher for tests
This commit is contained in:
@@ -427,12 +427,17 @@ export class MdLinkComputer {
|
||||
}
|
||||
}
|
||||
|
||||
interface MdDocumentLinks {
|
||||
readonly links: readonly MdLink[];
|
||||
readonly definitions: LinkDefinitionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stateful object which provides links for markdown files the workspace.
|
||||
*/
|
||||
export class MdLinkProvider extends Disposable {
|
||||
|
||||
private readonly _linkCache: MdDocumentInfoCache<readonly MdLink[]>;
|
||||
private readonly _linkCache: MdDocumentInfoCache<MdDocumentLinks>;
|
||||
|
||||
private readonly linkComputer: MdLinkComputer;
|
||||
|
||||
@@ -443,21 +448,19 @@ export class MdLinkProvider extends Disposable {
|
||||
) {
|
||||
super();
|
||||
this.linkComputer = new MdLinkComputer(tokenizer);
|
||||
this._linkCache = this._register(new MdDocumentInfoCache(workspaceContents, doc => {
|
||||
this._linkCache = this._register(new MdDocumentInfoCache(workspaceContents, async doc => {
|
||||
logger.verbose('LinkProvider', `compute - ${doc.uri}`);
|
||||
return this.linkComputer.getAllLinks(doc, noopToken);
|
||||
|
||||
const links = await this.linkComputer.getAllLinks(doc, noopToken);
|
||||
return {
|
||||
links,
|
||||
definitions: new LinkDefinitionSet(links),
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
public async getLinks(document: SkinnyTextDocument): Promise<{
|
||||
readonly links: readonly MdLink[];
|
||||
readonly definitions: LinkDefinitionSet;
|
||||
}> {
|
||||
const links = (await this._linkCache.get(document.uri)) ?? [];
|
||||
return {
|
||||
links,
|
||||
definitions: new LinkDefinitionSet(links),
|
||||
};
|
||||
public async getLinks(document: SkinnyTextDocument): Promise<MdDocumentLinks> {
|
||||
return this._linkCache.getForDocument(document);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user