Skip to content

Commit

Permalink
Merge pull request #54468 from akhera99/fix_intro_param_bug
Browse files Browse the repository at this point in the history
Introduce Parameter Highlight method return type bug
  • Loading branch information
akhera99 authored Jun 30, 2021
2 parents 51f16af + 4a03dcb commit 1b9f72f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1775,5 +1775,50 @@ void M1()
}";
await TestInRegularAndScriptAsync(code, expected, index: 0);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceParameter)]
public async Task TestHighlightReturnType()
{
var code =
@"using System;
class TestClass
{
[|int|] M(int x)
{
return x;
}
void M1()
{
M(5);
}
}";
await TestMissingInRegularAndScriptAsync(code);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceParameter)]
public async Task TestTypeOfOnString()
{
var code =
@"using System;
class TestClass
{
void M()
{
var x = [|typeof(string);|]
}
}";

var expected =
@"using System;
class TestClass
{
void M(Type x)
{
}
}";

await TestInRegularAndScriptAsync(code, expected, index: 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,18 @@ End Class"

Await TestInRegularAndScriptAsync(source, expected, index:=1)
End Function

<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceParameter)>
Public Async Function TestHighlightReturnType() As Task
Dim source =
"Class Program
Public Function M(x As Integer) As [|Integer|]
Return x
End Function
End Class"

Await TestMissingInRegularAndScriptAsync(source)
End Function
End Class
End Namespace

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
return;
}

// Need to special case for highlighting of method types because they are also "contained" within a method,
// but it does not make sense to introduce a parameter in that case.
if (syntaxFacts.IsInNamespaceOrTypeContext(expression))
{
return;
}

var generator = SyntaxGenerator.GetGenerator(document);
var containingMethod = expression.FirstAncestorOrSelf<SyntaxNode>(node => generator.GetParameterListNode(node) is not null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void M()
caretLocation,
customTags: new[] { PredefinedCodeRefactoringProviderNames.UseImplicitType }),
priority: PriorityLevel.Low,
groupName: "Roslyn4",
groupName: "Roslyn1",
applicableRange: new LSP.Range { Start = new Position { Line = 4, Character = 8 }, End = new Position { Line = 4, Character = 11 } },
diagnostics: null);

Expand Down

0 comments on commit 1b9f72f

Please sign in to comment.