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

Cohosting Support for Go to Definition #10750

Merged
merged 8 commits into from
Aug 19, 2024

Conversation

DustinCampbell
Copy link
Member

Fixes #10631

Here's support for Go to Definition under co-hosting. Tests are still incoming (and I'll add them before merging), but I wanted to get this out for review to see if there's anything I missed or should implement differently.

@DustinCampbell DustinCampbell requested a review from a team as a code owner August 15, 2024 22:06
Copy link
Contributor

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

I suspect you might have had to jump through slightly less hoops by using VS protocol types instead of Roslyn types, but it wouldn't be 0 hoops, and all of the hoops will go away eventually anyway.

Unfortunately, there are two well-hidden features in the old SingleServerDelegatingEndpoint and you've fallen into both traps. Feel free not to rearchitect the world to make these traps harder to fall into in this PR, but at the same time, I know what you're like 😛

Overall though, definitely looks good. I'd probably be happy to approve with skipped tests for those two features, and have them done in a follow up, if you were in a "re-architect the world" mood. I could see some better APIs on IDocumentMappingService to make that behaviour easier to access potentially.

Comment on lines +150 to +152
var csharpText = codeDocument.GetCSharpSourceText();
var syntaxTree = CSharpSyntaxTree.ParseText(csharpText, cancellationToken: cancellationToken);
var root = await syntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
Copy link
Contributor

@davidwengier davidwengier Aug 15, 2024

Choose a reason for hiding this comment

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

Totally fine to log as a follow up, but this is a great example of where we can make things much better for cohosting. eg, if we had an abstract method on the service to get the SyntaxRoot from the code document, and then have this method take the syntax root and RazorCSharpDocument as parameters, means we can avoid having to realize the file as a string and re-parse in cohosting.

Copy link
Member Author

Choose a reason for hiding this comment

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

I definitely agree that we should do better. In this case, I was simply copying your original code from here. 😛

The approach that you described wasn't clear to me. I might be conflating terminology, but I think you're suggesting that we would use a RazorCodeDocument to retrieve the root for a C# SyntaxTree? That feels an odd mixture of currency to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for chatting with me offline. I understand your suggestion now, but I'll hold off until we get things ported over. As you said in our chat, parity first.

@DustinCampbell
Copy link
Member Author

All right @davidwengier. Take two!

Copy link
Contributor

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

Love TestCode <3

Wasn't expecting the GetPositionInfo bits to be on the base document service, but no complaints about it either.

@DustinCampbell
Copy link
Member Author

Love TestCode <3

Enjoy!

@DustinCampbell
Copy link
Member Author

Wasn't expecting the GetPositionInfo bits to be on the base document service, but no complaints about it either.

That's totally fair. I think there's a likely future where this gets cleaned up further. After all, the IDocumentPositionInfoStrategy implementations are essentially just extensions methods on IDocumentMappingService.

@DustinCampbell DustinCampbell merged commit 0777649 into dotnet:main Aug 19, 2024
12 checks passed
@DustinCampbell DustinCampbell deleted the cohost-go-to-definition branch August 19, 2024 23:53
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Aug 19, 2024
davidwengier added a commit that referenced this pull request Aug 21, 2024
…x tree (#10765)

This PR is a classic self-nerd-snipe, and resolves this comment:
#10750 (comment)

Also inadvertently found a slight "bug" with the existing go to def code
in cohosting. Bug is in quotes because the actual user behaviour
probably was identical in 99% of cases.
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GoToDefinition for Cohosting
3 participants