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

Expose document symbols to Razor cohosting #74730

Merged
merged 4 commits into from
Aug 15, 2024

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Aug 13, 2024

Roslyn side of dotnet/razor#10689
Razor side: dotnet/razor#10728

Slightly annoying having to work around the VS dependency for images, but seems to look good in VS regardless:
image

@@ -25,7 +25,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
/// </summary>
[ExportCSharpVisualBasicStatelessLspService(typeof(DocumentSymbolsHandler)), Shared]
[Method(Methods.TextDocumentDocumentSymbolName)]
internal sealed class DocumentSymbolsHandler : ILspServiceDocumentRequestHandler<RoslynDocumentSymbolParams, object[]>
internal sealed class DocumentSymbolsHandler : ILspServiceDocumentRequestHandler<RoslynDocumentSymbolParams, SumType<RoslynDocumentSymbol[], SymbolInformation[]>>
Copy link
Member

Choose a reason for hiding this comment

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

could this be SumType<DocumentSymbol[], SymbolInformation[]> (and return RoslynDocumentSymbol) or does that not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I had at first, but the Document Outline tests failed. Guessing it is missing a converter, but it wasn't clear to me why that uses LSP at all, so didn't want to poke the bear :)

Copy link
Member

Choose a reason for hiding this comment

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

I would guess the document outline tests just need to request the base type, and then cast the result it gets back here https://github.com/dotnet/roslyn/blob/main/src/VisualStudio/CSharp/Test/DocumentOutline/DocumentOutlineTestsBase.cs#L89

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an actual serialization issue, the Glyph property is just lost. I could probably add a call to AddOrReplaceConverter<DocumentSymbol, RoslynDocumentSymbol>(); here though if you like?

Copy link
Member

Choose a reason for hiding this comment

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

if that works, fine with me. otherwise OK with this too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the converter, seems to work fine. It's cleaner on the Razor side too, which is nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol, that caused a different set of test failures 🤦‍♂️

public static async Task<SumType<DocumentSymbol[], SymbolInformation[]>> GetDocumentSymbolsAsync(Document document, bool useHierarchicalSymbols, CancellationToken cancellationToken)
{
// The symbol information service in Roslyn lives in EditorFeatures and has VS dependencies. for glyph images,
// so isn't available in OOP. The default implementation is available in OOP, but not in the Roslyn MEF composition,
Copy link
Member

Choose a reason for hiding this comment

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

but not in the Roslyn MEF composition

Hmm - not sure why this isn't the case. I think its regular workspace service. Not 100% sure but I would have thought it should be available.

Copy link
Member

Choose a reason for hiding this comment

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

oh is the protocol project not in the OOP mef composition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, precisely. That might come up again in other endpoints so could be something we need to talk about in future, but document symbol didn't seem important enough to block on it

{
var document = context.GetRequiredDocument();
var clientCapabilities = context.GetRequiredClientCapabilities();
var useHierarchicalSymbols = clientCapabilities.TextDocument?.DocumentSymbol?.HierarchicalDocumentSymbolSupport == true || request.UseHierarchicalSymbols;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems weird that even if the client doesn't support HierarchicalSymbols we'd still use it if the request said to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Document Outline window in Roslyn calls the document symbols LSP endpoint, and wants hierarchical results all the time, but the VS LSP client doesn't support them. In the LSP spec the non-hierarchical result is deprecated and I should probably log an issue on the platform to move off it, and then a lot of this nonsense can go away.

Copy link
Member

Choose a reason for hiding this comment

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

this is for document outline. base vs client doesn't have hierarchical support IIRC, but we need it for our custom doc outline support.

@davidwengier davidwengier merged commit 24c3928 into dotnet:main Aug 15, 2024
25 checks passed
@davidwengier davidwengier deleted the CohostDocumentSymbol branch August 15, 2024 05:00
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Aug 15, 2024
davidwengier added a commit to dotnet/razor that referenced this pull request Aug 21, 2024
Fixes #10689
Roslyn side: dotnet/roslyn#74730

Looks good, despite the Roslyn side having VS deps for images:

![image](https://github.com/user-attachments/assets/44d2ac8d-f7c1-46ec-9572-15bfd91bed28)
@dibarbet dibarbet modified the milestones: Next, 17.12 P2 Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants