1515namespace Microsoft . CodeAnalysis . CSharp . InlineHints ;
1616
1717[ ExportLanguageService ( typeof ( IInlineTypeHintsService ) , LanguageNames . CSharp ) , Shared ]
18- internal sealed class CSharpInlineTypeHintsService : AbstractInlineTypeHintsService
18+ [ method: ImportingConstructor ]
19+ [ method: Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
20+ internal sealed class CSharpInlineTypeHintsService ( ) : AbstractInlineTypeHintsService
1921{
20- [ ImportingConstructor ]
21- [ Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
22- public CSharpInlineTypeHintsService ( )
23- {
24- }
25-
2622 protected override TypeHint ? TryGetTypeHint (
2723 SemanticModel semanticModel ,
2824 SyntaxNode node ,
@@ -41,7 +37,7 @@ public CSharpInlineTypeHintsService()
4137 {
4238 var type = semanticModel . GetTypeInfo ( variableDeclaration . Type , cancellationToken ) . Type ;
4339 if ( IsValidType ( type ) )
44- return CreateTypeHint ( type , displayAllOverride , forImplicitVariableTypes , variableDeclaration . Type , variableDeclaration . Variables [ 0 ] . Identifier ) ;
40+ return CreateTypeHint ( type , variableDeclaration . Type , variableDeclaration . Variables [ 0 ] . Identifier ) ;
4541 }
4642
4743 // We handle individual variables of ParenthesizedVariableDesignationSyntax separately.
@@ -51,7 +47,7 @@ public CSharpInlineTypeHintsService()
5147 {
5248 var type = semanticModel . GetTypeInfo ( declarationExpression . Type , cancellationToken ) . Type ;
5349 if ( IsValidType ( type ) )
54- return CreateTypeHint ( type , displayAllOverride , forImplicitVariableTypes , declarationExpression . Type , declarationExpression . Designation ) ;
50+ return CreateTypeHint ( type , declarationExpression . Type , declarationExpression . Designation ) ;
5551 }
5652 else if ( node is SingleVariableDesignationSyntax { Parent : not DeclarationPatternSyntax and not DeclarationExpressionSyntax } variableDesignation )
5753 {
@@ -60,7 +56,7 @@ public CSharpInlineTypeHintsService()
6056 if ( IsValidType ( type ) )
6157 {
6258 return node . Parent is VarPatternSyntax varPattern
63- ? CreateTypeHint ( type , displayAllOverride , forImplicitVariableTypes , varPattern . VarKeyword , variableDesignation . Identifier )
59+ ? CreateTypeHint ( type , varPattern . VarKeyword , variableDesignation . Identifier )
6460 : new ( type , new TextSpan ( variableDesignation . Identifier . SpanStart , 0 ) , textChange : null , trailingSpace : true ) ;
6561 }
6662 }
@@ -69,7 +65,7 @@ public CSharpInlineTypeHintsService()
6965 var info = semanticModel . GetForEachStatementInfo ( forEachStatement ) ;
7066 var type = info . ElementType ;
7167 if ( IsValidType ( type ) )
72- return CreateTypeHint ( type , displayAllOverride , forImplicitVariableTypes , forEachStatement . Type , forEachStatement . Identifier ) ;
68+ return CreateTypeHint ( type , forEachStatement . Type , forEachStatement . Identifier ) ;
7369 }
7470 }
7571
@@ -83,7 +79,7 @@ public CSharpInlineTypeHintsService()
8379 IsValidType ( parameter ? . Type ) )
8480 {
8581 return parameterNode . Parent ? . Parent ? . Kind ( ) is SyntaxKind . ParenthesizedLambdaExpression
86- ? new TypeHint ( parameter . Type , span , textChange : new TextChange ( span , parameter . Type . ToDisplayString ( s_minimalTypeStyle ) + " " ) , trailingSpace : true )
82+ ? new TypeHint ( parameter . Type , span , textChange : new TextChange ( span , GetTypeDisplayString ( parameter . Type ) + " " ) , trailingSpace : true )
8783 : new TypeHint ( parameter . Type , span , textChange : null , trailingSpace : true ) ;
8884 }
8985 }
@@ -97,7 +93,7 @@ public CSharpInlineTypeHintsService()
9793 if ( IsValidType ( type ) )
9894 {
9995 var span = new TextSpan ( implicitNew . NewKeyword . Span . End , 0 ) ;
100- return new ( type , span , new TextChange ( span , " " + type . ToDisplayString ( s_minimalTypeStyle ) ) , leadingSpace : true ) ;
96+ return new ( type , span , new TextChange ( span , " " + GetTypeDisplayString ( type ) ) , leadingSpace : true ) ;
10197 }
10298 }
10399 }
@@ -110,26 +106,27 @@ public CSharpInlineTypeHintsService()
110106 if ( IsValidType ( type ) )
111107 {
112108 var span = new TextSpan ( collectionExpression . OpenBracketToken . SpanStart , 0 ) ;
113- return new ( type , span , new TextChange ( span , type . ToDisplayString ( s_minimalTypeStyle ) ) , leadingSpace : true ) ;
109+ return new ( type , span , new TextChange ( span , GetTypeDisplayString ( type ) ) , leadingSpace : true ) ;
114110 }
115111 }
116112 }
117113
118114 return null ;
119- }
120115
121- private static TypeHint CreateTypeHint (
122- ITypeSymbol type ,
123- bool displayAllOverride ,
124- bool normalOption ,
125- SyntaxNodeOrToken displayAllSpan ,
126- SyntaxNodeOrToken normalSpan )
127- {
128- var span = GetSpan ( displayAllOverride , normalOption , displayAllSpan , normalSpan ) ;
129- // if this is a hint that is placed in-situ (i.e. it's not overwriting text like 'var'), then place
130- // a space after it to make things feel less cramped.
131- var trailingSpace = span . Length == 0 ;
132- return new TypeHint ( type , span , new TextChange ( displayAllSpan . Span , type . ToDisplayString ( s_minimalTypeStyle ) ) , trailingSpace : trailingSpace ) ;
116+ string GetTypeDisplayString ( ITypeSymbol type )
117+ => type . ToMinimalDisplayString ( semanticModel , node . SpanStart , s_minimalTypeStyle ) ;
118+
119+ TypeHint CreateTypeHint (
120+ ITypeSymbol type ,
121+ SyntaxNodeOrToken displayAllSpan ,
122+ SyntaxNodeOrToken normalSpan )
123+ {
124+ var span = GetSpan ( displayAllOverride , forImplicitVariableTypes , displayAllSpan , normalSpan ) ;
125+ // if this is a hint that is placed in-situ (i.e. it's not overwriting text like 'var'), then place
126+ // a space after it to make things feel less cramped.
127+ var trailingSpace = span . Length == 0 ;
128+ return new TypeHint ( type , span , new TextChange ( displayAllSpan . Span , GetTypeDisplayString ( type ) ) , trailingSpace : trailingSpace ) ;
129+ }
133130 }
134131
135132 private static TextSpan GetSpan (
0 commit comments