22using CodeNav . OutOfProc . ViewModels ;
33using Microsoft . CodeAnalysis ;
44using Microsoft . CodeAnalysis . CSharp ;
5+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
56using Microsoft . CodeAnalysis . Text ;
67
78namespace CodeNav . OutOfProc . Languages . CSharp . Mappers ;
@@ -15,7 +16,8 @@ public static class BaseMapper
1516 /// <param name="source">Syntax node of the code member</param>
1617 /// <param name="semanticModel">Semantic model used during compilation</param>
1718 /// <param name="codeDocumentViewModel">Code document view model used in the CodeNav tool window</param>
18- /// <param name="identifier">Syntax token of the code identifier</param>
19+ /// <param name="identifier">Syntax token of the code member identifier</param>
20+ /// <param name="nameSyntax">Syntax token of the code member name</param>
1921 /// <param name="name">Name of the code member</param>
2022 /// <param name="modifiers">Accessibility modifiers of the code member</param>
2123 /// <returns>Code item class or othe code class derived from code item</returns>
@@ -24,12 +26,13 @@ public static T MapBase<T>(
2426 SemanticModel semanticModel ,
2527 CodeDocumentViewModel codeDocumentViewModel ,
2628 SyntaxToken ? identifier = null ,
29+ NameSyntax ? nameSyntax = null ,
2730 string name = "" ,
2831 SyntaxTokenList ? modifiers = null ) where T : CodeItem
2932 {
3033 var codeItem = Activator . CreateInstance < T > ( ) ;
3134
32- var codeItemName = MapName ( identifier , name ) ;
35+ var codeItemName = MapName ( identifier , nameSyntax , name ) ;
3336
3437 codeItem . Name = codeItemName ;
3538 codeItem . FullName = MapFullName ( source , codeItemName , semanticModel ) ;
@@ -43,20 +46,43 @@ public static T MapBase<T>(
4346
4447 codeItem . Span = source . Span ;
4548 codeItem . IdentifierSpan = identifier ? . Span ;
46- codeItem . OutlineSpan = MapOutlineSpan ( codeItem . Span , codeItem . IdentifierSpan , name ) ;
49+ codeItem . OutlineSpan = MapOutlineSpan ( codeItem . Span , codeItem . IdentifierSpan , nameSyntax ? . Span ) ;
4750
4851 return codeItem ;
4952 }
5053
51- private static TextSpan MapOutlineSpan ( TextSpan span , TextSpan ? identifierSpan , string name )
54+ /// <summary>
55+ /// Map the span that is used for expanding/collapsing outline regions
56+ /// </summary>
57+ /// <param name="span">Normal span of the syntax node</param>
58+ /// <param name="identifierSpan">Identifier span of the syntax node</param>
59+ /// <param name="name">Name of the syntax node</param>
60+ /// <returns>TextSpan usable for outlining</returns>
61+ private static TextSpan MapOutlineSpan ( TextSpan span , TextSpan ? identifierSpan , TextSpan ? nameSpan )
5262 {
53- var outlineSpanStart = identifierSpan != null
54- ? identifierSpan . Value . End
55- : span . Start + name . Length ;
63+ var outlineSpanStart = 0 ;
64+
65+ if ( nameSpan != null )
66+ {
67+ outlineSpanStart = nameSpan . Value . End ;
68+ }
69+
70+ if ( identifierSpan != null )
71+ {
72+ outlineSpanStart = identifierSpan . Value . End ;
73+ }
5674
5775 return new TextSpan ( outlineSpanStart , span . End - outlineSpanStart ) ;
5876 }
5977
78+ /// <summary>
79+ /// Map the full name of a code item
80+ /// </summary>
81+ /// <remarks>Used to create a unique id for the code item</remarks>
82+ /// <param name="source">Syntax node of the code item</param>
83+ /// <param name="name">Display name of the code item</param>
84+ /// <param name="semanticModel">Semantic model used during compilation</param>
85+ /// <returns>String full name</returns>
6086 private static string MapFullName ( SyntaxNode source , string name , SemanticModel semanticModel )
6187 {
6288 try
@@ -70,8 +96,26 @@ private static string MapFullName(SyntaxNode source, string name, SemanticModel
7096 }
7197 }
7298
73- private static string MapName ( SyntaxToken ? identifier , string name )
74- => identifier != null ? identifier . Value . Text : name ;
99+ /// <summary>
100+ /// Map the display name of a code item
101+ /// </summary>
102+ /// <param name="identifier">Identifier syntax token of the code item</param>
103+ /// <param name="nameSyntax">Name syntax token of the code item</param>
104+ /// <returns>String display name</returns>
105+ private static string MapName ( SyntaxToken ? identifier , NameSyntax ? nameSyntax , string name = "" )
106+ {
107+ if ( identifier != null )
108+ {
109+ return identifier . Value . Text ;
110+ }
111+
112+ if ( nameSyntax != null )
113+ {
114+ return nameSyntax . ToString ( ) ;
115+ }
116+
117+ return name ;
118+ }
75119
76120 private static CodeItemAccessEnum MapAccess ( SyntaxTokenList ? modifiers , SyntaxNode source )
77121 {
0 commit comments