Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve outline #5536

Merged
merged 10 commits into from
Feb 3, 2023
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