Skip to content

Commit a1d33d1

Browse files
Inline Hints - do not allow double click for collection expression type hint (#78900)
* do not allow double click for collection expression hint * Update src/EditorFeatures/Test2/InlineHints/CSharpInlineTypeHintsTests.vb Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com> * comment --------- Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
1 parent 5936530 commit a1d33d1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/EditorFeatures/Test2/InlineHints/CSharpInlineTypeHintsTests.vb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,5 +934,34 @@ class C
934934

935935
Await VerifyTypeHints(input, output)
936936
End Function
937+
938+
<WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/48941")>
939+
Public Async Function TestNoDoubleClickWithCollectionExpression() As Task
940+
Dim input =
941+
<Workspace>
942+
<Project Language="C#" CommonReferences="true">
943+
<Document>
944+
class A
945+
{
946+
private static readonly ImmutableHashSet&lt;string?&gt; Hashes = {| ImmutableHashSet&lt;string?&gt;:|}[];
947+
}
948+
</Document>
949+
</Project>
950+
</Workspace>
951+
952+
Dim output =
953+
<Workspace>
954+
<Project Language="C#" CommonReferences="true">
955+
<Document>
956+
class A
957+
{
958+
private static readonly ImmutableHashSet&lt;string?&gt; Hashes = [];
959+
}
960+
</Document>
961+
</Project>
962+
</Workspace>
963+
964+
Await VerifyTypeHints(input, output)
965+
End Function
937966
End Class
938967
End Namespace

src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ internal sealed class CSharpInlineTypeHintsService() : AbstractInlineTypeHintsSe
105105
if (IsValidType(type))
106106
{
107107
var span = new TextSpan(collectionExpression.OpenBracketToken.SpanStart, 0);
108-
return new(type, span, new TextChange(span, GetTypeDisplayString(type)), leadingSpace: true);
108+
109+
// We pass null for the TextChange in collection expressions because
110+
// inserting with the type is incorrect and will make the code uncompilable.
111+
return new(type, span, textChange: null, leadingSpace: true);
109112
}
110113
}
111114
}

0 commit comments

Comments
 (0)