diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs index b50029fcff5b63de1a72809ebc412077e0b0e190..50d7609291f63b0f8f9f98a448f725324a3b959b 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs @@ -4152,7 +4152,8 @@ class TestClass /// /// /// - /// + /// + /// looks like a proper prefix but isn't void M() { M$$(); @@ -4160,7 +4161,7 @@ void M() } } ", - Exceptions($"\r\n{WorkspacesResources.Exceptions}\r\n MyException1\r\n MyException2\r\n double\r\n int")); + Exceptions($"\r\n{WorkspacesResources.Exceptions}\r\n MyException1\r\n MyException2\r\n int\r\n double\r\n Not_A_Class_But_Still_Displayed\r\n T:")); } } } diff --git a/src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb b/src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb index e1d8b49c7291eaa490ea2b748a478524c3e7e28d..2e85ee77ecd2d95f4345cfdec545581833d88d37 100644 --- a/src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb +++ b/src/EditorFeatures/VisualBasicTest/QuickInfo/SemanticQuickInfoSourceTests.vb @@ -2049,14 +2049,15 @@ Namespace MyNs ''' ''' ''' - ''' + ''' + ''' looks like a proper prefix but isn't Sub M() M$$() End Sub End Class End Namespace ", - Exceptions($"{vbCrLf}{WorkspacesResources.Exceptions}{vbCrLf} MyException1{vbCrLf} MyException2{vbCrLf} Double{vbCrLf} Integer")) + Exceptions($"{vbCrLf}{WorkspacesResources.Exceptions}{vbCrLf} MyException1{vbCrLf} MyException2{vbCrLf} Integer{vbCrLf} Double{vbCrLf} Not_A_Class_But_Still_Displayed{vbCrLf} T:")) End Sub End Class diff --git a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs index 061b2b12cf83d03aafa26ecb1ca0c59646452862..737b33aa75de63d441bae8a3d63d7d2902cc83a1 100644 --- a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs +++ b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs @@ -156,24 +156,32 @@ private async Task AddPartsAsync(ImmutableArray symbols) private void AddExceptions(ISymbol symbol) { - // clean up the list of possible exceptions by de-duplicating and ordering them - var exceptions = - symbol.GetDocumentationComment().ExceptionTypes - .Distinct() - .OrderBy(e => e) - .Select(e => DocumentationCommentId.GetFirstSymbolForDeclarationId(e, _semanticModel.Compilation)) - .WhereNotNull() - .ToList(); - if (exceptions.Any()) + var exceptionTypes = symbol.GetDocumentationComment().ExceptionTypes; + if (exceptionTypes.Any()) { var parts = new List(); - parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, null, $"\r\n{WorkspacesResources.Exceptions}")); - - foreach (var exception in exceptions) + parts.Add(new SymbolDisplayPart(kind: SymbolDisplayPartKind.Text, symbol: null, text: $"\r\n{WorkspacesResources.Exceptions}")); + foreach (var exceptionString in exceptionTypes) { parts.AddRange(LineBreak()); parts.AddRange(Space(count: 2)); - parts.AddRange(_displayService.ToMinimalDisplayParts(_semanticModel, _position, exception)); + + // try to get the actual exception symbol + var exceptionSymbol = DocumentationCommentId.GetFirstSymbolForDeclarationId(exceptionString, _semanticModel.Compilation); + if (exceptionSymbol != null) + { + parts.AddRange(_displayService.ToMinimalDisplayParts(_semanticModel, _position, exceptionSymbol)); + } + else + { + // unable to parse exception symbol, fall back to displaying the raw text after trying to + // strip off the leading prefix of "[E|F|M|N|P|T|!]:" + var colonIndex = exceptionString.IndexOf(':'); + var displayText = colonIndex >= 0 && exceptionString.Length > colonIndex + 1 + ? exceptionString.Substring(colonIndex + 1) + : exceptionString; + parts.Add(new SymbolDisplayPart(kind: SymbolDisplayPartKind.Text, symbol: null, text: displayText)); + } } AddToGroup(SymbolDescriptionGroups.Exceptions, parts);