-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OutVariableArgumentProvider for 'out' parameters #53049
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7771664
Add OutVariableArgumentProvider for 'out' parameters
sharwell f97a9ec
Support testing calls with multiple arguments
sharwell 9be420e
Share code for implementation of GetParameterSymbolInfo
sharwell 550db94
Prepare to support type style options in argument providers
sharwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...ditorFeatures/CSharpTest/Completion/ArgumentProviders/OutVariableArgumentProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CodeStyle; | ||
using Microsoft.CodeAnalysis.CSharp.CodeStyle; | ||
using Microsoft.CodeAnalysis.CSharp.Completion.Providers; | ||
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.ArgumentProviders | ||
{ | ||
[Trait(Traits.Feature, Traits.Features.Completion)] | ||
public class OutVariableArgumentProviderTests : AbstractCSharpArgumentProviderTests | ||
{ | ||
private static readonly OptionsCollection s_useExplicitTypeOptions = new(LanguageNames.CSharp) | ||
{ | ||
{ CSharpCodeStyleOptions.VarForBuiltInTypes, false }, | ||
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, false }, | ||
{ CSharpCodeStyleOptions.VarElsewhere, false }, | ||
}; | ||
|
||
private static readonly OptionsCollection s_useExplicitMetadataTypeOptions = new(LanguageNames.CSharp) | ||
{ | ||
{ CSharpCodeStyleOptions.VarForBuiltInTypes, false }, | ||
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, false }, | ||
{ CSharpCodeStyleOptions.VarElsewhere, false }, | ||
{ CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false }, | ||
}; | ||
|
||
private static readonly OptionsCollection s_useImplicitTypeOptions = new(LanguageNames.CSharp) | ||
{ | ||
{ CSharpCodeStyleOptions.VarForBuiltInTypes, true }, | ||
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, true }, | ||
{ CSharpCodeStyleOptions.VarElsewhere, true }, | ||
}; | ||
|
||
internal override Type GetArgumentProviderType() | ||
=> typeof(OutVariableArgumentProvider); | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("ref")] | ||
[InlineData("in")] | ||
public async Task TestUnsupportedModifiers(string modifier) | ||
{ | ||
var markup = $@" | ||
class C | ||
{{ | ||
void Method() | ||
{{ | ||
TryParse($$) | ||
}} | ||
|
||
bool TryParse({modifier} int value) => throw null; | ||
}} | ||
"; | ||
|
||
await VerifyDefaultValueAsync(markup, expectedDefaultValue: null); | ||
} | ||
|
||
[Fact] | ||
public async Task TestDeclareVariable() | ||
{ | ||
var markup = $@" | ||
class C | ||
{{ | ||
void Method() | ||
{{ | ||
int.TryParse(""x"", $$) | ||
}} | ||
}} | ||
"; | ||
|
||
await VerifyDefaultValueAsync(markup, "out var result"); | ||
await VerifyDefaultValueAsync(markup, expectedDefaultValue: null, previousDefaultValue: "prior"); | ||
} | ||
|
||
[Theory(Skip = "https://github.com/dotnet/roslyn/issues/53056")] | ||
[CombinatorialData] | ||
public async Task TestDeclareVariableBuiltInType(bool preferVar, bool preferBuiltInType) | ||
{ | ||
var markup = $@" | ||
using System; | ||
class C | ||
{{ | ||
void Method() | ||
{{ | ||
int.TryParse(""x"", $$) | ||
}} | ||
}} | ||
"; | ||
|
||
var expected = (preferVar, preferBuiltInType) switch | ||
{ | ||
(true, _) => "out var result", | ||
(false, true) => "out int result", | ||
(false, false) => "out Int32 result", | ||
}; | ||
|
||
var options = (preferVar, preferBuiltInType) switch | ||
{ | ||
(true, _) => s_useImplicitTypeOptions, | ||
(false, true) => s_useExplicitTypeOptions, | ||
(false, false) => s_useExplicitMetadataTypeOptions, | ||
}; | ||
|
||
await VerifyDefaultValueAsync(markup, expected, options: options); | ||
} | ||
|
||
[Theory] | ||
[InlineData("string")] | ||
[InlineData("bool")] | ||
[InlineData("int?")] | ||
public async Task TestDeclareVariableEscapedIdentifier(string type) | ||
{ | ||
var markup = $@" | ||
class C | ||
{{ | ||
void Method() | ||
{{ | ||
this.Target($$); | ||
}} | ||
|
||
void Target(out {type} @void) | ||
{{ | ||
@void = default; | ||
}} | ||
}} | ||
"; | ||
|
||
await VerifyDefaultValueAsync(markup, "out var @void"); | ||
await VerifyDefaultValueAsync(markup, expectedDefaultValue: null, previousDefaultValue: "prior"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the filtering above guaranteed to limit us to a single result? or would an exception here mean the test should be rewritten to remove ambiguity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still possible to construct a test that the framework doesn't support. We'd have to modify it at that time to support the specifics of the new test.