mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 10:19:02 +00: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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user