-
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
Completion: Suggest types after keywords indicating a local function #54493
Completion: Suggest types after keywords indicating a local function #54493
Conversation
SyntaxKind.ExternKeyword, | ||
SyntaxKind.StaticKeyword, | ||
SyntaxKind.AsyncKeyword, | ||
SyntaxKind.UnsafeKeyword, |
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.
This list is derived from all calls to IsLocalFunctionDeclarationContext (ExternKeywordRecommender
, StaticKeywordRecommender
, AsyncKeywordRecommender
and UnsafeKeywordRecommender
). The spec only mentions async
and unsafe
, but dates back to C# 7.0.
@@ -78,7 +78,7 @@ private ImmutableArray<ISymbol> GetSymbolsForCurrentContext() | |||
// is a type-only context, we'll show all symbols anyway. | |||
return GetSymbolsForExpressionOrStatementContext(); | |||
} | |||
else if (_context.IsTypeContext || _context.IsNamespaceContext) | |||
else if (_context.IsTypeContext || _context.IsNamespaceContext || _context.IsLocalFunctionDeclarationContext) |
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.
@CyrusNajmabadi This is probably naive or just plain wrong. Do you have any objections? If not, I will add some more tests.
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.
I'm not sure if IsTypeContext
should be true here instead of introducing the new property. Also consider revisiting other callers to IsTypeContext
and check what the desired behavior is for these callers.
For example, generate type codefix is (most likely) also affected by IsTypeContext
returning false.
roslyn/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs
Line 135 in acf3e27
if (!semanticFacts.IsTypeContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) && |
class C
{
Test NotLocal() { return null; } // Generate class 'Test' is offered here
void M()
{
static Test Local(){ return null; } // But not offered here.
}
}
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.
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.
I tracked down every reference of IsTypeContext
(at least I tried) and added tests for each occurrence.
} | ||
} | ||
"; | ||
await VerifyItemExistsAsync(markup, "String"); |
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 string
offered too? It has a separate keyword recommender IIRC (there are other keywords too).
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 wasn't offered. I fixed this and added tests.
@CyrusNajmabadi This simple approach expands roslyn/src/EditorFeatures/CSharpTest2/Recommendations/DelegateKeywordRecommenderTests.cs Lines 289 to 291 in 6453b4f
The root cause is here in roslyn/src/Features/CSharp/Portable/Completion/KeywordRecommenders/DelegateKeywordRecommender.cs Lines 31 to 47 in 6453b4f
I'm not too confident about the @CyrusNajmabadi What do you think about the approach of expanding |
|
…SyntaxContext" This reverts commit eb1b5be.
@CyrusNajmabadi Ready for review |
@@ -288,7 +288,7 @@ public async Task TestNotAfterSealed() | |||
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | |||
public async Task TestAfterStatic() | |||
{ | |||
await VerifyAbsenceAsync(SourceCodeKind.Regular, @"static $$"); | |||
await VerifyKeywordAsync(SourceCodeKind.Regular, @"static $$"); | |||
await VerifyKeywordAsync(SourceCodeKind.Script, @"static $$"); |
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.
can we have a test for this after static inside a method as well?
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.
public async Task TestAfterStaticLocalFunction() | ||
{ | ||
await VerifyKeywordAsync(AddInsideMethod(@" | ||
static $$")); |
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.
so, you had all the tests after 'static' in a method, can you do the same for after 'async'? as well? or make all the tests theories and test static
async
async static
and static async
. Thanks!
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.
src/Features/CSharp/Portable/Completion/KeywordRecommenders/IntKeywordRecommender.cs
Show resolved
Hide resolved
...haredUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
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.
LGTM with requested test additions.
…xtensions/ContextQuery/SyntaxTreeExtensions.cs Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
…legate recommender tests
@CyrusNajmabadi Feedback is addressed and tests are green (except one unrelated integration test failure). I added the new file roslyn/src/EditorFeatures/CSharpTest2/Recommendations/TheoryDataKeywordsIndicatingLocalFunction.cs Lines 11 to 16 in 8439d03
|
...haredUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
…xtensions/ContextQuery/SyntaxTreeExtensions.cs
Thanks! |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Fixes #53585
cc @Youssef1313