Introduce the concept of a SkinnyTextDocument that provides minimal interface to generate toc

This commit is contained in:
Matt Bierner
2018-06-04 10:41:03 -07:00
parent 8ea7f77c44
commit 7b69194f91
3 changed files with 14 additions and 7 deletions

View File

@@ -15,12 +15,18 @@ export interface TocEntry {
readonly location: vscode.Location;
}
export interface SkinnyTextDocument {
readonly uri: vscode.Uri;
getText(): string;
lineAt(line: number): vscode.TextLine;
}
export class TableOfContentsProvider {
private toc?: TocEntry[];
public constructor(
private engine: MarkdownEngine,
private document: vscode.TextDocument
private document: SkinnyTextDocument
) { }
public async getToc(): Promise<TocEntry[]> {
@@ -40,7 +46,7 @@ export class TableOfContentsProvider {
return toc.find(entry => entry.slug.equals(slug));
}
private async buildToc(document: vscode.TextDocument): Promise<TocEntry[]> {
private async buildToc(document: SkinnyTextDocument): Promise<TocEntry[]> {
const toc: TocEntry[] = [];
const tokens = await this.engine.parse(document.uri, document.getText());