mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
Add table of contents provider abstraction (#152504)
We currently re-compute the same table of contents for markdown files multiple times. This is because multiple language features all need table of contents With this change, we introduce a new `TableOfContentsProvider` which maintains a cache of the table of contents per file. This provider is then passed into every caller that needs a toc
This commit is contained in:
@@ -9,6 +9,7 @@ import * as vscode from 'vscode';
|
||||
import { DiagnosticCollectionReporter, DiagnosticComputer, DiagnosticConfiguration, DiagnosticLevel, DiagnosticManager, DiagnosticOptions, DiagnosticReporter } from '../languageFeatures/diagnostics';
|
||||
import { MdLinkProvider } from '../languageFeatures/documentLinkProvider';
|
||||
import { MdReferencesProvider } from '../languageFeatures/references';
|
||||
import { MdTableOfContentsProvider } from '../tableOfContents';
|
||||
import { noopToken } from '../util/cancellation';
|
||||
import { disposeAll } from '../util/dispose';
|
||||
import { InMemoryDocument } from '../util/inMemoryDocument';
|
||||
@@ -30,7 +31,8 @@ const defaultDiagnosticsOptions = Object.freeze<DiagnosticOptions>({
|
||||
async function getComputedDiagnostics(doc: InMemoryDocument, workspace: MdWorkspaceContents, options: Partial<DiagnosticOptions> = {}): Promise<vscode.Diagnostic[]> {
|
||||
const engine = createNewMarkdownEngine();
|
||||
const linkProvider = new MdLinkProvider(engine, workspace);
|
||||
const computer = new DiagnosticComputer(engine, workspace, linkProvider);
|
||||
const tocProvider = new MdTableOfContentsProvider(engine, workspace);
|
||||
const computer = new DiagnosticComputer(workspace, linkProvider, tocProvider);
|
||||
return (
|
||||
await computer.getDiagnostics(doc, { ...defaultDiagnosticsOptions, ...options, }, noopToken)
|
||||
).diagnostics;
|
||||
@@ -430,11 +432,12 @@ suite('Markdown: Diagnostics manager', () => {
|
||||
) {
|
||||
const engine = createNewMarkdownEngine();
|
||||
const linkProvider = new MdLinkProvider(engine, workspace);
|
||||
const referencesProvider = new MdReferencesProvider(engine, workspace);
|
||||
const tocProvider = new MdTableOfContentsProvider(engine, workspace);
|
||||
const referencesProvider = new MdReferencesProvider(engine, workspace, tocProvider);
|
||||
const manager = new DiagnosticManager(
|
||||
engine,
|
||||
workspace,
|
||||
new DiagnosticComputer(engine, workspace, linkProvider),
|
||||
new DiagnosticComputer(workspace, linkProvider, tocProvider),
|
||||
configuration,
|
||||
reporter,
|
||||
referencesProvider,
|
||||
|
||||
Reference in New Issue
Block a user