Skip to content
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 IDE tests for "file-scoped namespaces" #54374

Merged

Conversation

RikkiGibson
Copy link
Contributor

Test plan: #49000

  • 93959af fixes a crash I noticed in the IDE in ad-hoc testing. Not sure how to add an automated test for it.
  • cb3bffe adds a few tests for completion, indentation, formatting and classification.

@RikkiGibson RikkiGibson requested a review from a team as a code owner June 24, 2021 23:38
@RikkiGibson
Copy link
Contributor Author

@jcouv @chsienki Please take a look when you get the chance.

@ryzngard
Copy link
Contributor

  • 93959af fixes a crash I noticed in the IDE in ad-hoc testing. Not sure how to add an automated test for it.

Do you have the stack trace available? Could help find a good test for this with more information

@davidwengier
Copy link
Contributor

  • 93959af fixes a crash I noticed in the IDE in ad-hoc testing. Not sure how to add an automated test for it.

Just a hunch, but a test here for file scoped namespaces might repro it:
https://github.com/dotnet/roslyn/blob/main/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs#L57

@RikkiGibson
Copy link
Contributor Author

  • 93959af fixes a crash I noticed in the IDE in ad-hoc testing. Not sure how to add an automated test for it.

Do you have the stack trace available? Could help find a good test for this with more information

Stack trace
StreamJsonRpc.RemoteInvocationException: Assertion failed
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__139`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__17`1.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Remote\Core\BrokeredServiceConnection.cs:line 200
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
RPC server exception:
System.InvalidOperationException: Assertion failed
      at Microsoft.CodeAnalysis.Remote.ThrowingTraceListener.Fail(String message, String detailMessage) in C:\Users\rikki\src\roslyn\src\Workspaces\Remote\ServiceHub\Services\Host\ThrowingTraceListener.cs:line 27
      at System.Diagnostics.TraceInternal.Fail(String message)
      at System.Diagnostics.Debug.Assert(Boolean condition)
      at Microsoft.CodeAnalysis.CSharp.LanguageServices.CSharpSyntaxFacts.GetName(SyntaxNode node, DisplayNameOptions options) in C:\Users\rikki\src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs:line 894
      at Microsoft.CodeAnalysis.CSharp.LanguageServices.CSharpSyntaxFacts.GetDisplayName(SyntaxNode node, DisplayNameOptions options, String rootNamespace) in C:\Users\rikki\src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs:line 835
      at Microsoft.CodeAnalysis.CSharp.FindSymbols.CSharpDeclaredSymbolInfoFactoryService.GetContainerDisplayName(SyntaxNode node) in C:\Users\rikki\src\roslyn\src\Workspaces\CSharp\Portable\FindSymbols\CSharpDeclaredSymbolInfoFactoryService.cs:line 436
      at Microsoft.CodeAnalysis.CSharp.FindSymbols.CSharpDeclaredSymbolInfoFactoryService.TryGetDeclaredSymbolInfo(StringTable stringTable, SyntaxNode node, String rootNamespace, DeclaredSymbolInfo& declaredSymbolInfo) in C:\Users\rikki\src\roslyn\src\Workspaces\CSharp\Portable\FindSymbols\CSharpDeclaredSymbolInfoFactoryService.cs:line 173
      at Microsoft.CodeAnalysis.FindSymbols.SyntaxTreeIndex.<CreateIndexAsync>d__23.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\SyntaxTree\SyntaxTreeIndex_Create.cs:line 164
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.SyntaxTreeIndex.<GetIndexWorkerAsync>d__14.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\SyntaxTree\SyntaxTreeIndex.cs:line 131
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.SyntaxTreeIndex.<GetIndexAsync>d__13.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\SyntaxTree\SyntaxTreeIndex.cs:line 89
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.FindSymbols.SyntaxTreeIndex.<GetRequiredIndexAsync>d__11.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\SyntaxTree\SyntaxTreeIndex.cs:line 71
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder.<GetIdentifierOrGlobalNamespaceTokensWithTextAsync>d__16.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\Finders\AbstractReferenceFinder.cs:line 227
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder.<FindReferencesInDocumentUsingIdentifierAsync>d__15.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\Finders\AbstractReferenceFinder.cs:line 202
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.Finders.OrdinaryMethodReferenceFinder.<FindReferencesInDocumentAsync>d__7.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\Finders\OrdinaryMethodReferenceFinder.cs:line 123
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessDocumentAsync>d__15.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine_DocumentProcessing.cs:line 60
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessDocumentAsync>d__15.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine_DocumentProcessing.cs:line 70
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessDocumentQueueAsync>d__13.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine_DocumentProcessing.cs:line 33
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessDocumentQueueAsync>d__13.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine_DocumentProcessing.cs:line 40
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessProjectAsync>d__26.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine_ProjectProcessing.cs:line 38
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<ProcessAsync>d__10.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine.cs:line 103
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<FindReferencesAsync>d__9.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine.cs:line 74
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<FindReferencesAsync>d__9.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine.cs:line 74
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<FindReferencesAsync>d__9.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\FindReferences\FindReferencesSearchEngine.cs:line 79
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.<FindReferencesAsync>d__34.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Core\Portable\FindSymbols\SymbolFinder_FindReferences_Current.cs:line 54
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.<GetTagsForReferencedSymbolAsync>d__3.MoveNext() in C:\Users\rikki\src\roslyn\src\Features\Core\Portable\DocumentHighlighting\AbstractDocumentHighlightsService.cs:line 118
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.<GetDocumentHighlightsInCurrentProcessAsync>d__1.MoveNext() in C:\Users\rikki\src\roslyn\src\Features\Core\Portable\DocumentHighlighting\AbstractDocumentHighlightsService.cs:line 68
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.<GetDocumentHighlightsAsync>d__0.MoveNext() in C:\Users\rikki\src\roslyn\src\Features\Core\Portable\DocumentHighlighting\AbstractDocumentHighlightsService.cs:line 47
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.Remote.RemoteDocumentHighlightsService.<>c__DisplayClass2_0.<<GetDocumentHighlightsAsync>b__0>d.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Remote\ServiceHub\Services\DocumentHighlights\RemoteDocumentHighlightsService.cs:line 46
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunServiceImplAsync>d__12`1.MoveNext() in C:\Users\rikki\src\roslyn\src\Workspaces\Remote\ServiceHub\Services\BrokeredServiceBase.cs:line 73
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)


class C { }",
testHost,
Namespace("NS"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to put this (or a copy) in the TotalClassifierTests. Then we can validate that the rest of hte tokens classify properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

AssertSmartIndent(
code,
indentationLine: 4,
expectedIndentation: 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add an assert for the lines Above the namespace? and can we have a test that just tests teh behavior of indentation if the semicolon is missing (i'm fine with any behavior, i just want it tested).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public async Task TestAfterFileScopedNamespace()
{
await VerifyKeywordAsync(
@"namespace NS; $$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally a test of namespace keywords that shows it does not appear here. Note: if it does, that's not a big deal, just would be something nice to clean up later.

We should also have tests for using appearing after and before single-line ns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -857,7 +857,8 @@ public string GetDisplayName(SyntaxNode? node, DisplayNameOptions options, strin
case SyntaxKind.IncompleteMember:
return missingTokenPlaceholder;
case SyntaxKind.NamespaceDeclaration:
return GetName(((NamespaceDeclarationSyntax)node).Name, options);
case SyntaxKind.FileScopedNamespaceDeclaration:
return GetName(((BaseNamespaceDeclarationSyntax)node).Name, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. but see comment about the broken formatting. it's likely a very simple fix somewhere, but it can be annoying to track down where tehse rules get inserted. LMK if you'd like help on that.

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Jun 25, 2021

  • 93959af fixes a crash I noticed in the IDE in ad-hoc testing. Not sure how to add an automated test for it.

Just a hunch, but a test here for file scoped namespaces might repro it:
https://github.com/dotnet/roslyn/blob/main/src/EditorFeatures/CSharpTest/Debugging/LocationInfoGetterTests.cs#L57

I tried reverting the implementation change and adding the test. It doesn't look like it ended up revealing the bad behavior. @davidwengier

@RikkiGibson RikkiGibson merged commit df58f94 into dotnet:features/FileScopedNamespaces Jun 25, 2021
@RikkiGibson RikkiGibson deleted the fsn-testing branch June 25, 2021 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants