diff --git a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.DeclaredSymbolNavigableItem.cs b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.DeclaredSymbolNavigableItem.cs index 96c6b6880e03e1c2efbc3cb2b5adbf723e931eb3..fd9854da50f78ea279b00996f1d86af28202dc66 100644 --- a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.DeclaredSymbolNavigableItem.cs +++ b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.DeclaredSymbolNavigableItem.cs @@ -44,20 +44,7 @@ public DeclaredSymbolNavigableItem(Document document, DeclaredSymbolInfo declare return null; } - var symbolDisplayService = Document.GetLanguageService(); - switch (Symbol.Kind) - { - case SymbolKind.NamedType: - return symbolDisplayService.ToDisplayString(Symbol, s_shortFormatWithModifiers); - - case SymbolKind.Method: - return Symbol.IsStaticConstructor() - ? symbolDisplayService.ToDisplayString(Symbol, s_shortFormatWithModifiers) - : symbolDisplayService.ToDisplayString(Symbol, s_shortFormat); - - default: - return symbolDisplayService.ToDisplayString(Symbol, s_shortFormat); - } + return GetSymbolDisplayString(Document.Project, Symbol); } catch (Exception e) when (FatalError.Report(e)) { diff --git a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.SymbolLocationNavigableItem.cs b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.SymbolLocationNavigableItem.cs index bc674f311aba6814cfecd8e0ae06b911b909016c..14855eca8e664a931820a57d8a6cb2aca57b2b51 100644 --- a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.SymbolLocationNavigableItem.cs +++ b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.SymbolLocationNavigableItem.cs @@ -28,21 +28,7 @@ private class SymbolLocationNavigableItem : INavigableItem _lazyDisplayName = new Lazy(() => { - var symbolDisplayService = this.Document.Project.LanguageServices.GetService(); - - switch (symbol.Kind) - { - case SymbolKind.NamedType: - return symbolDisplayService.ToDisplayString(_symbol, s_shortFormatWithModifiers); - - case SymbolKind.Method: - return _symbol.IsStaticConstructor() - ? symbolDisplayService.ToDisplayString(_symbol, s_shortFormatWithModifiers) - : symbolDisplayService.ToDisplayString(_symbol, s_shortFormat); - - default: - return symbolDisplayService.ToDisplayString(_symbol, s_shortFormat); - } + return GetSymbolDisplayString(Document.Project, _symbol); }); } diff --git a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.cs b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.cs index 20f13c96c05136784215771c71e19954ac0b9b21..e73837be4b5f9ecb0a60d01031d854399de4bd55 100644 --- a/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.cs +++ b/src/EditorFeatures/Core/Extensibility/Navigation/NavigableItemFactory.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.GeneratedCodeRecognition; +using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -21,6 +23,7 @@ public static INavigableItem GetItemFromDeclaredSymbolInfo(DeclaredSymbolInfo de return new DeclaredSymbolNavigableItem(document, declaredSymbolInfo); } + public static IEnumerable GetItemsFromPreferredSourceLocations(Solution solution, ISymbol symbol) { var locations = GetPreferredSourceLocations(solution, symbol); @@ -57,6 +60,24 @@ private static IEnumerable GetPreferredSourceLocations(ISymbol symbol) : locations.Where(loc => loc.IsInSource); } + public static string GetSymbolDisplayString(Project project, ISymbol symbol) + { + var symbolDisplayService = project.LanguageServices.GetRequiredService(); + switch (symbol.Kind) + { + case SymbolKind.NamedType: + return symbolDisplayService.ToDisplayString(symbol, s_shortFormatWithModifiers); + + case SymbolKind.Method: + return symbol.IsStaticConstructor() + ? symbolDisplayService.ToDisplayString(symbol, s_shortFormatWithModifiers) + : symbolDisplayService.ToDisplayString(symbol, s_shortFormat); + + default: + return symbolDisplayService.ToDisplayString(symbol, s_shortFormat); + } + } + private static readonly SymbolDisplayFormat s_shortFormat = new SymbolDisplayFormat( globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining, diff --git a/src/EditorFeatures/Test/TestExportProvider.cs b/src/EditorFeatures/Test/TestExportProvider.cs index a6afd0524e6ba8ab24b8c3401f09f6663c1e6622..6bef7b821f948b659c610aa608c7560fe59b70ae 100644 --- a/src/EditorFeatures/Test/TestExportProvider.cs +++ b/src/EditorFeatures/Test/TestExportProvider.cs @@ -96,6 +96,8 @@ private static Type[] GetNeutralAndCSharpAndVisualBasicTypes() typeof(Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxFactsService), typeof(CodeAnalysis.CSharp.CSharpSymbolDeclarationService), typeof(CodeAnalysis.VisualBasic.VisualBasicSymbolDeclarationService), + typeof(CodeAnalysis.Editor.CSharp.LanguageServices.CSharpSymbolDisplayServiceFactory), + typeof(CodeAnalysis.Editor.VisualBasic.LanguageServices.VisualBasicSymbolDisplayServiceFactory), typeof(CodeAnalysis.CSharp.Simplification.CSharpSimplificationService), typeof(CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService), typeof(CodeAnalysis.CSharp.Rename.CSharpRenameConflictLanguageService),