Refactor markdown language features (#152402)

(sorry for the size of this PR)

This change cleans up the markdown language features by making the following changes:

- Use `registerXSupport` public functions to register these
- Expose the slugifier the `MarkdownEngine` uses. You never want to use a different one if you already have a markdown engine
- Sort of clean up names. I'd introduced a bunch of confusing names while iterating in this space. What I'm working towards:

    - `Computer` — Stateless thing that computer data
    - `Provider` — Potentially stateful thing that provides data (which may be cached)
    - `VsCodeProvider` — The actual implementation of the various vscode language features (which should only be used by VS Code and in tests, not shared with other features)
- Introduce `MdLinkProvider` to avoid recomputing links for a given document. Also use this to hide more internals of link computation
This commit is contained in:
Matt Bierner
2022-06-17 01:25:52 -07:00
committed by GitHub
parent 54f5758f81
commit 623f55f437
24 changed files with 333 additions and 181 deletions

View File

@@ -6,19 +6,21 @@
import * as assert from 'assert';
import 'mocha';
import * as vscode from 'vscode';
import { MdLinkComputer, MdLinkProvider } from '../languageFeatures/documentLinkProvider';
import { MdLinkProvider, MdVsCodeLinkProvider } from '../languageFeatures/documentLinkProvider';
import { noopToken } from '../util/cancellation';
import { InMemoryDocument } from '../util/inMemoryDocument';
import { createNewMarkdownEngine } from './engine';
import { assertRangeEqual, joinLines } from './util';
import { InMemoryWorkspaceMarkdownDocuments } from './inMemoryWorkspace';
import { assertRangeEqual, joinLines, workspacePath } from './util';
const testFile = vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, 'x.md');
function getLinksForFile(fileContents: string) {
const doc = new InMemoryDocument(testFile, fileContents);
const linkComputer = new MdLinkComputer(createNewMarkdownEngine());
const provider = new MdLinkProvider(linkComputer);
const doc = new InMemoryDocument(workspacePath('x.md'), fileContents);
const workspace = new InMemoryWorkspaceMarkdownDocuments([doc]);
const engine = createNewMarkdownEngine();
const linkProvider = new MdLinkProvider(engine, workspace);
const provider = new MdVsCodeLinkProvider(linkProvider);
return provider.provideDocumentLinks(doc, noopToken);
}