'How to display/control breadcrumbs of a VSCode virtual document?
I'm working on an extension that registers a TextDocumentContentProvider to provide a read-only viewer for certain Azure resources in JSON format. When I display the JSON for these resources, I'd like the editor to show the JSON breadcrumbs. For some reason, when displaying the content via my virtual document URL, the breadcrumbs don't get displayed. The editor displays breadcrumbs fine when the same document content is pulled using file:// scheme.
Does anyone know how to set up breadcrumb support for a virtual document?
Solution 1:[1]
Breadcrumbs use the info returned from the DocumentSymbolProvider. Implement an own symbol provider that returns the info you wish and register it as described on the VS Code API page.
The document provider itself is pretty simple.
export class MySymbolProvider implements DocumentSymbolProvider {
constructor() {}
provideDocumentSymbols(document: TextDocument, token: CancellationToken): ProviderResult<SymbolInformation[]> {
var symbols = ... // get your symbols from somewhere
var symbolsList = [];
for (let symbol of symbols) {
// Construct location information here (for go-to feature).
let startRow = ...;
let endRow = ...;
let startColumn = ...;
let endColumn = ...;
let range = new Range(startRow, startColumn, endRow, endColumn);
let location = new Location(Uri.file(symbol.source), range);
var description = ...;
const kind = translateSymbolKind(symbol.kind);
let info = new SymbolInformation(symbol.name, kind, description, location);
symbolsList.push(info);
}
return symbolsList;
};
};
Solution 2:[2]
Seems like this is currently not possible as the only file schemes that support breadcrumbs are file and untitled according to this comment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mike Lischke |
| Solution 2 | MartinT |
