diff --git a/src/EditorFeatures/Test2/InlineHints/CSharpInlineParameterNameHintsTests.vb b/src/EditorFeatures/Test2/InlineHints/CSharpInlineParameterNameHintsTests.vb index c310a6050f48b..0bcf0d758f3bd 100644 --- a/src/EditorFeatures/Test2/InlineHints/CSharpInlineParameterNameHintsTests.vb +++ b/src/EditorFeatures/Test2/InlineHints/CSharpInlineParameterNameHintsTests.vb @@ -1298,5 +1298,95 @@ class A Await VerifyParamHints(input, output) End Function + + + Public Async Function TestExistingNamedParameter1() As Task + Dim input = + + + +class C +{ + static void Main(string[] args) + { + Goo({|a:|}1, 2, b: 0); + } + + static void Goo(int a, int b) + { + + } +} + + + + + Dim output = + + + +class C +{ + static void Main(string[] args) + { + Goo(a: 1, 2, b: 0); + } + + static void Goo(int a, int b) + { + + } +} + + + + + Await VerifyParamHints(input, output) + End Function + + + Public Async Function TestExistingNamedParameter2() As Task + Dim input = + + + +class C +{ + static void Main(string[] args) + { + Goo({|a:|}1, {|b:|}2, c: 0); + } + + static void Goo(int a, int b) + { + + } +} + + + + + Dim output = + + + +class C +{ + static void Main(string[] args) + { + Goo(a: 1, b: 2, c: 0); + } + + static void Goo(int a, int b) + { + + } +} + + + + + Await VerifyParamHints(input, output) + End Function End Class End Namespace diff --git a/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs b/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs index 945156338c0f1..c7a3b95d37be7 100644 --- a/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs +++ b/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs @@ -19,14 +19,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InlineHints; /// as well as associate the adornments back to the parameter name /// [ExportLanguageService(typeof(IInlineParameterNameHintsService), LanguageNames.CSharp), Shared] -internal class CSharpInlineParameterNameHintsService : AbstractInlineParameterNameHintsService +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpInlineParameterNameHintsService() : AbstractInlineParameterNameHintsService { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpInlineParameterNameHintsService() - { - } - protected override void AddAllParameterNameHintLocations( SemanticModel semanticModel, ISyntaxFactsService syntaxFacts, @@ -66,12 +62,23 @@ private static void AddArguments( BaseArgumentListSyntax argumentList, CancellationToken cancellationToken) { + // Ensure we don't add an inline parameter name hint using the same name already present on another argument. + using var _ = PooledHashSet.GetInstance(out var presentNames); + foreach (var argument in argumentList.Arguments) + { + if (argument is { NameColon.Name.Identifier.ValueText: string nameText }) + presentNames.Add(nameText); + } + foreach (var argument in argumentList.Arguments) { if (argument.NameColon != null) continue; var parameter = argument.DetermineParameter(semanticModel, cancellationToken: cancellationToken); + if (presentNames.Contains(parameter?.Name)) + continue; + buffer.Add((argument.Span.Start, argument, parameter, GetKind(argument.Expression))); } } diff --git a/src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs b/src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs index 11c2242b4be0b..8141e11a01244 100644 --- a/src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs @@ -2008,7 +2008,7 @@ public async Task TestWorkspaceDiagnosticsWaitsForLspSolutionChanges(bool useVSD Assert.NotEmpty(results); } - [Theory, CombinatorialData] + [Theory(Skip = "https://github.com/dotnet/roslyn/issues/76503"), CombinatorialData] public async Task TestWorkspaceDiagnosticsWaitsForLspTextChangesWithMultipleSources(bool useVSDiagnostics, bool mutatingLspWorkspace) { var markup1 =