If your outline view is well-organized with symbols arranged hierarchically and includes range objects for each symbol's scope, you can easily track your location within the hierarchy by toggling the "Breadcrumbs" item in the view menu. This feature was exactly what I needed.
In order to achieve this functionality, I stored some essential data in a variable named currentBlock
, which included symbolInformation
generated when encountering the first line of a method using a match object from a regex:
currentBlock.symbolInformation = new vscode.SymbolInformation(
match[1],
vscode.SymbolKind.Method,
className,
new vscode.Location(document.uri,
new vscode.Position(lineNum, line.firstNonWhitespaceCharacterIndex)));
Upon reaching the end of a block, I consolidated the remaining information along with earlier stored data and added it to the result as part of an array of SymbolInformation[]
.
private popBlock(document: vscode.TextDocument, lineNum: number, currentBlock: IndentInfo): vscode.SymbolInformation | undefined {
if (currentBlock.symbolInformation !== undefined) {
currentBlock.symbolInformation = new vscode.SymbolInformation(
currentBlock.symbolInformation.name,
currentBlock.symbolInformation.kind,
currentBlock.symbolInformation.containerName,
new vscode.Location(
currentBlock.symbolInformation.location.uri,
new vscode.Range(
currentBlock.symbolInformation.location.range.start,
new vscode.Position(lineNum-1, document.lineAt(lineNum-1).text.length)
)
)
);
return currentBlock.symbolInformation;
}
}
The breadcrumbs displayed above the editor pane provide a comprehensive overview of the current context based on the same data used to construct the outline.
https://i.sstatic.net/Tu9xP.png