This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stub out basic markdown headings document symbol provider (#33)
to restore default markdown Outline for remapped standard .md documents, and build a custom Evidence markdown Outline for markdown documents navigation in VS Code
- Loading branch information
1 parent
03a798a
commit 64c01d8
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
CancellationToken, | ||
DocumentSymbolProvider, | ||
Location, | ||
ProviderResult, | ||
SymbolInformation, | ||
SymbolKind, | ||
TextDocument, | ||
} from 'vscode'; | ||
|
||
/** | ||
* Implements custom Evidence markdown document symbol provider. | ||
*/ | ||
export class MarkdownSymbolProvider implements DocumentSymbolProvider { | ||
|
||
provideDocumentSymbols(document: TextDocument, token: CancellationToken): | ||
ProviderResult<SymbolInformation[]> { | ||
|
||
// parse text document symbols per line | ||
const symbols: SymbolInformation[] = []; | ||
for (let i = 0; i < document.lineCount; i++) { | ||
const line = document.lineAt(i); | ||
|
||
// match heading lines | ||
const match = line.text.match(/^#+\s+(.*)$/); | ||
if (match) { | ||
const symbol = new SymbolInformation(match[1], SymbolKind.String, | ||
'', // container name | ||
new Location(document.uri, line.range) | ||
); | ||
|
||
symbols.push(symbol); | ||
} | ||
} | ||
|
||
return symbols; | ||
} | ||
} |