Skip to content

Commit 1e21020

Browse files
Do not offer inline hints for parameters that already named
1 parent 4234893 commit 1e21020

File tree

3 files changed

+105
-8
lines changed

3 files changed

+105
-8
lines changed

src/EditorFeatures/Test2/InlineHints/CSharpInlineParameterNameHintsTests.vb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,5 +1298,95 @@ class A
12981298

12991299
Await VerifyParamHints(input, output)
13001300
End Function
1301+
1302+
<WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59317")>
1303+
Public Async Function TestExistingNamedParameter1() As Task
1304+
Dim input =
1305+
<Workspace>
1306+
<Project Language="C#" CommonReferences="true">
1307+
<Document>
1308+
class C
1309+
{
1310+
static void Main(string[] args)
1311+
{
1312+
Goo({|a:|}1, 2, b: 0);
1313+
}
1314+
1315+
static void Goo(int a, int b)
1316+
{
1317+
1318+
}
1319+
}
1320+
</Document>
1321+
</Project>
1322+
</Workspace>
1323+
1324+
Dim output =
1325+
<Workspace>
1326+
<Project Language="C#" CommonReferences="true">
1327+
<Document>
1328+
class C
1329+
{
1330+
static void Main(string[] args)
1331+
{
1332+
Goo(a: 1, 2, b: 0);
1333+
}
1334+
1335+
static void Goo(int a, int b)
1336+
{
1337+
1338+
}
1339+
}
1340+
</Document>
1341+
</Project>
1342+
</Workspace>
1343+
1344+
Await VerifyParamHints(input, output)
1345+
End Function
1346+
1347+
<WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/59317")>
1348+
Public Async Function TestExistingNamedParameter2() As Task
1349+
Dim input =
1350+
<Workspace>
1351+
<Project Language="C#" CommonReferences="true">
1352+
<Document>
1353+
class C
1354+
{
1355+
static void Main(string[] args)
1356+
{
1357+
Goo({|a:|}1, {|b:|}2, c: 0);
1358+
}
1359+
1360+
static void Goo(int a, int b)
1361+
{
1362+
1363+
}
1364+
}
1365+
</Document>
1366+
</Project>
1367+
</Workspace>
1368+
1369+
Dim output =
1370+
<Workspace>
1371+
<Project Language="C#" CommonReferences="true">
1372+
<Document>
1373+
class C
1374+
{
1375+
static void Main(string[] args)
1376+
{
1377+
Goo(a: 1, b: 2, c: 0);
1378+
}
1379+
1380+
static void Goo(int a, int b)
1381+
{
1382+
1383+
}
1384+
}
1385+
</Document>
1386+
</Project>
1387+
</Workspace>
1388+
1389+
Await VerifyParamHints(input, output)
1390+
End Function
13011391
End Class
13021392
End Namespace

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InlineHints;
1919
/// as well as associate the adornments back to the parameter name
2020
/// </summary>
2121
[ExportLanguageService(typeof(IInlineParameterNameHintsService), LanguageNames.CSharp), Shared]
22-
internal class CSharpInlineParameterNameHintsService : AbstractInlineParameterNameHintsService
22+
[method: ImportingConstructor]
23+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
24+
internal sealed class CSharpInlineParameterNameHintsService() : AbstractInlineParameterNameHintsService
2325
{
24-
[ImportingConstructor]
25-
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
26-
public CSharpInlineParameterNameHintsService()
27-
{
28-
}
29-
3026
protected override void AddAllParameterNameHintLocations(
3127
SemanticModel semanticModel,
3228
ISyntaxFactsService syntaxFacts,
@@ -66,12 +62,23 @@ private static void AddArguments(
6662
BaseArgumentListSyntax argumentList,
6763
CancellationToken cancellationToken)
6864
{
65+
// Ensure we don't add an inline parameter name hint using the same name already present on another argument.
66+
using var _ = PooledHashSet<string?>.GetInstance(out var presentNames);
67+
foreach (var argument in argumentList.Arguments)
68+
{
69+
if (argument is { NameColon.Name.Identifier.ValueText: string nameText })
70+
presentNames.Add(nameText);
71+
}
72+
6973
foreach (var argument in argumentList.Arguments)
7074
{
7175
if (argument.NameColon != null)
7276
continue;
7377

7478
var parameter = argument.DetermineParameter(semanticModel, cancellationToken: cancellationToken);
79+
if (presentNames.Contains(parameter?.Name))
80+
continue;
81+
7582
buffer.Add((argument.Span.Start, argument, parameter, GetKind(argument.Expression)));
7683
}
7784
}

src/LanguageServer/ProtocolUnitTests/Diagnostics/PullDiagnosticTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ public async Task TestWorkspaceDiagnosticsWaitsForLspSolutionChanges(bool useVSD
20082008
Assert.NotEmpty(results);
20092009
}
20102010

2011-
[Theory, CombinatorialData]
2011+
[Theory(Skip = "https://github.com/dotnet/roslyn/issues/76503"), CombinatorialData]
20122012
public async Task TestWorkspaceDiagnosticsWaitsForLspTextChangesWithMultipleSources(bool useVSDiagnostics, bool mutatingLspWorkspace)
20132013
{
20142014
var markup1 =

0 commit comments

Comments
 (0)