dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19k stars 4.03k forks source link

Document Highlights not working #70785

Open vsfeedback opened 11 months ago

vsfeedback commented 11 months ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] I don't use document outline - don't even know what it does - but I frequently see a status message at the top of VS indicating that it failed with this stack trace:

VS 17.7.5, but I've been seeing this for many versions - maybe as long as since VS 2022 first shipped.

Project is a C# class library (MSTest unit tests), .NET Framework 4.8 target.

StreamJsonRpc.RemoteInvocationException: Cannot generated a documentation comment id for symbol.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- 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 Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.InvalidOperationException: Cannot generated a documentation comment id for symbol.
      at Microsoft.CodeAnalysis.DocumentationCommentId.DeclarationGenerator.Generator.DefaultVisit(ISymbol symbol)
      at Microsoft.CodeAnalysis.SymbolVisitor`1.VisitDynamicType(IDynamicTypeSymbol symbol)
      at Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.DynamicTypeSymbol.Accept[TResult](SymbolVisitor`1 visitor)
      at Microsoft.CodeAnalysis.SymbolVisitor`1.Visit(ISymbol symbol)
      at Microsoft.CodeAnalysis.DocumentationCommentId.DeclarationGenerator.Generator.VisitMethod(IMethodSymbol symbol)
      at Microsoft.CodeAnalysis.SymbolVisitor`1.Visit(ISymbol symbol)
      at Microsoft.CodeAnalysis.DocumentationCommentId.DeclarationGenerator.VisitMethod(IMethodSymbol symbol)
      at Microsoft.CodeAnalysis.DocumentationCommentId.CreateDeclarationId(ISymbol symbol)
      at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder.ShouldFindReferencesInGlobalSuppressions(ISymbol symbol, String& documentationCommentId)
      at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder.FindReferencesInDocumentInsideGlobalSuppressionsAsync(ISymbol symbol, FindReferencesDocumentState state, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.Finders.OperatorSymbolReferenceFinder.FindReferencesInDocumentAsync(IMethodSymbol symbol, FindReferencesDocumentState state, FindReferencesSearchOptions options, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass28_0.<<FindReferencesInDocumentsAsync>g__PerformSearchInDocumentWorkerAsync|4>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass28_0.<<FindReferencesInDocumentsAsync>g__PerformSearchInDocumentAsync|3>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass28_0.<<FindReferencesInDocumentsAsync>g__PerformSearchInProjectAsync|2>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesInDocumentsAsync(ISymbol originalSymbol, IImmutableSet`1 documents, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.GetTagsForReferencedSymbolAsync(ISymbol symbol, Document document, IImmutableSet`1 documentsToSearch, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.GetDocumentHighlightsInCurrentProcessAsync(Document document, Int32 position, IImmutableSet`1 documentsToSearch, HighlightingOptions options, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DocumentHighlighting.AbstractDocumentHighlightsService.GetDocumentHighlightsAsync(Document document, Int32 position, IImmutableSet`1 documentsToSearch, HighlightingOptions options, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteDocumentHighlightsService.<>c__DisplayClass2_0.<<GetDocumentHighlightsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

Original Comments

Feedback Bot on 10/15/2023, 10:08 PM:

(private comment, text removed)

Chaojie Yang [MSFT] on 10/15/2023, 11:51 PM:

(private comment, text removed)

Feedback Bot on 10/25/2023, 01:33 AM:

(private comment, text removed)

Feedback Bot on 11/13/2023, 09:49 AM:

(private comment, text removed)

Feedback Bot on 11/13/2023, 09:52 AM:

(private comment, text removed)


Original Solutions

Nicole Hu [MSFT] solved on 11/8/2023, 11:09 PM, 0 votes:

We are unable to investigate this issue further without the additional information requested. If you are able to provide more information, you can request the issue being reactivate below. See our guidelines for further information about our process.

CyrusNajmabadi commented 11 months ago

Similar to https://github.com/dotnet/roslyn/issues/70159. Another case where creating a DocCommentId is just throwing.

CyrusNajmabadi commented 11 months ago

@dotnet/roslyn-compiler to take a look. We're just taking a method symbol, passed back from the compiler, as an argument to DocumentationCommentId.CreateDeclarationId. All that API says is:

        /// <summary>
        /// Creates an id string used by external documentation comment files to identify declarations
        /// of types, namespaces, methods, properties, etc.
        /// </summary>

I would not expect any symbol to fail, esp. not because of a dynamic type symbol. I think the issue is:

                public override bool VisitMethod(IMethodSymbol symbol)
                {
                    if (this.Visit(symbol.ContainingSymbol))
                    {

which likely needs to be:

if (this.GetReferenceGenerator(symbol).Visit(symbol.ContainingSymbol) (or somethign like that).

CyrusNajmabadi commented 11 months ago

@jcouv can you triage this?

AlekseyTs commented 11 months ago

@CyrusNajmabadi Could you create a complete standalone repro? In order to answer the question, we need to have a clear understanding of the scenario.

CyrusNajmabadi commented 11 months ago

@AlekseyTs https://github.com/dotnet/roslyn/issues/70159 has a repo for the pointer case. My guess is that it's similar here. Maybe a synthesized compiler operator dynamic methods?

sharwell commented 10 months ago

@AlekseyTs @CyrusNajmabadi we now have 3 separate reports of this. We also have at least 68K hits in telemetry (AB#1774410)

AlekseyTs commented 10 months ago

In order to speed-up the investigation, could IDE team create a stand alone repro in the form of a compiler API unit-test? Basically the repro I am looking for is something like: here is a compilation, here is the API call that behaves in an unexpected way.