Skip to content

Commit

Permalink
Merge pull request #5536 from trolleyman/improve-outline-breadcrumbs
Browse files Browse the repository at this point in the history
Improve outline
  • Loading branch information
dibarbet authored Feb 3, 2023
2 parents 4d31e93 + a3d8056 commit 8c4a7ab
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/features/documentSymbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export default class OmnisharpDocumentSymbolProvider extends AbstractSupport imp
}
}

function createSymbols(elements: Structure.CodeElement[]): vscode.DocumentSymbol[] {
function createSymbols(elements: Structure.CodeElement[], parentElement?: Structure.CodeElement): vscode.DocumentSymbol[] {
let results: vscode.DocumentSymbol[] = [];

elements.forEach(element => {
let symbol = createSymbolForElement(element);
let symbol = createSymbolForElement(element, parentElement);
if (element.Children) {
symbol.children = createSymbols(element.Children);
symbol.children = createSymbols(element.Children, element);
}

results.push(symbol);
Expand All @@ -46,11 +46,43 @@ function createSymbols(elements: Structure.CodeElement[]): vscode.DocumentSymbol
return results;
}

function createSymbolForElement(element: Structure.CodeElement): vscode.DocumentSymbol {
function getNameForElement(element: Structure.CodeElement, parentElement?: Structure.CodeElement): string {
switch (element.Kind) {
case SymbolKinds.Class:
case SymbolKinds.Delegate:
case SymbolKinds.Enum:
case SymbolKinds.Interface:
case SymbolKinds.Struct:
return element.Name;

case SymbolKinds.Namespace:
return typeof parentElement !== 'undefined' && element.DisplayName.startsWith(`${parentElement.DisplayName}.`)
? element.DisplayName.slice(parentElement.DisplayName.length + 1)
: element.DisplayName;

case SymbolKinds.Constant:
case SymbolKinds.Constructor:
case SymbolKinds.Destructor:
case SymbolKinds.EnumMember:
case SymbolKinds.Event:
case SymbolKinds.Field:
case SymbolKinds.Indexer:
case SymbolKinds.Method:
case SymbolKinds.Operator:
case SymbolKinds.Property:
case SymbolKinds.Unknown:
default:
return element.DisplayName;
}
}

function createSymbolForElement(element: Structure.CodeElement, parentElement?: Structure.CodeElement): vscode.DocumentSymbol {
const fullRange = element.Ranges[SymbolRangeNames.Full];
const nameRange = element.Ranges[SymbolRangeNames.Name];
const name = getNameForElement(element, parentElement);
const details = name === element.DisplayName ? '' : element.DisplayName;

return new vscode.DocumentSymbol(element.DisplayName, /*detail*/ "", toSymbolKind(element.Kind), toRange3(fullRange), toRange3(nameRange));
return new vscode.DocumentSymbol(name, details, toSymbolKind(element.Kind), toRange3(fullRange), toRange3(nameRange));
}

const kinds: { [kind: string]: vscode.SymbolKind; } = {};
Expand Down

0 comments on commit 8c4a7ab

Please sign in to comment.