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:
Matt Bierner
2022-06-21 16:25:10 -07:00
committed by GitHub
parent f9d332c692
commit c84655d123
9 changed files with 64 additions and 31 deletions

View File

@@ -6,13 +6,14 @@
import type MarkdownIt = require('markdown-it');
import type Token = require('markdown-it/lib/token');
import * as vscode from 'vscode';
import { MdDocumentInfoCache } from './util/workspaceCache';
import { ILogger } from './logging';
import { MarkdownContributionProvider } from './markdownExtensions';
import { Slugifier } from './slugify';
import { Disposable } from './util/dispose';
import { stringHash } from './util/hash';
import { WebviewResourceProvider } from './util/resources';
import { isOfScheme, Schemes } from './util/schemes';
import { MdDocumentInfoCache } from './util/workspaceCache';
import { MdWorkspaceContents, SkinnyTextDocument } from './workspaceContents';
const UNICODE_NEWLINE_REGEX = /\u2028|\u2029/g;
@@ -95,6 +96,7 @@ interface RenderEnv {
export interface IMdParser {
readonly slugifier: Slugifier;
tokenize(document: SkinnyTextDocument): Promise<Token[]>;
}
@@ -110,6 +112,7 @@ export class MarkdownItEngine implements IMdParser {
public constructor(
private readonly contributionProvider: MarkdownContributionProvider,
slugifier: Slugifier,
private readonly logger: ILogger,
) {
this.slugifier = slugifier;
@@ -180,6 +183,7 @@ export class MarkdownItEngine implements IMdParser {
return cached;
}
this.logger.verbose('MarkdownItEngine', `tokenizeDocument - ${document.uri}`);
const tokens = this.tokenizeString(document.getText(), engine);
this._tokenCache.update(document, config, tokens);
return tokens;