mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Expand js/ts document symbols to have entries for each span
Fixes #54855
This commit is contained in:
parent
bd1e8d40fd
commit
5e40bd7df9
|
@ -40,7 +40,6 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider
|
|||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
let tree: Proto.NavigationTree;
|
||||
try {
|
||||
const args: Proto.FileRequestArgs = { file };
|
||||
|
@ -64,26 +63,33 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider
|
|||
}
|
||||
|
||||
private static convertNavTree(resource: vscode.Uri, bucket: vscode.DocumentSymbol[], item: Proto.NavigationTree): boolean {
|
||||
const symbolInfo = new vscode.DocumentSymbol(
|
||||
item.text,
|
||||
'',
|
||||
getSymbolKind(item.kind),
|
||||
typeConverters.Range.fromTextSpan(item.spans[0]),
|
||||
typeConverters.Range.fromTextSpan(item.spans[0]),
|
||||
);
|
||||
|
||||
let shouldInclude = TypeScriptDocumentSymbolProvider.shouldInclueEntry(item);
|
||||
|
||||
if (item.childItems) {
|
||||
for (const child of item.childItems) {
|
||||
const includedChild = TypeScriptDocumentSymbolProvider.convertNavTree(resource, symbolInfo.children, child);
|
||||
shouldInclude = shouldInclude || includedChild;
|
||||
const children = new Set(item.childItems || []);
|
||||
for (const span of item.spans) {
|
||||
const range = typeConverters.Range.fromTextSpan(span);
|
||||
const symbolInfo = new vscode.DocumentSymbol(
|
||||
item.text,
|
||||
'',
|
||||
getSymbolKind(item.kind),
|
||||
range,
|
||||
range);
|
||||
|
||||
if (item.childItems) {
|
||||
for (const child of children) {
|
||||
if (child.spans.some(span => !!range.intersection(typeConverters.Range.fromTextSpan(span)))) {
|
||||
const includedChild = TypeScriptDocumentSymbolProvider.convertNavTree(resource, symbolInfo.children, child);
|
||||
shouldInclude = shouldInclude || includedChild;
|
||||
children.delete(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldInclude) {
|
||||
bucket.push(symbolInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldInclude) {
|
||||
bucket.push(symbolInfo);
|
||||
}
|
||||
return shouldInclude;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue