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

Pre co-hosting Hover tweaks #11131

Merged
merged 2 commits into from
Nov 1, 2024
Merged

Conversation

DustinCampbell
Copy link
Member

This pull request makes a couple of changes to HoverFactory.GetHoverAsync(...) to prepare for co-hosting:

  1. HoverFactory.GetHoverAsync(...) returns an LSP Hover rather than VSInternalHover.
  2. HoverFactory.GetHoverAsync(...) no longer takes a document file path. It already takes a RazorCodeDocument, and the file path can be retrieved from that.

@DustinCampbell DustinCampbell requested a review from a team as a code owner October 31, 2024 18:05
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.

In case it's not clear, I am 100% happy with this PR as is :)

documentFilePath, binding.Descriptors, span, options, solutionQueryOperations, cancellationToken);
codeDocument.Source.FilePath, binding.Descriptors, span, options, solutionQueryOperations, cancellationToken);
Copy link
Contributor

@davidwengier davidwengier Oct 31, 2024

Choose a reason for hiding this comment

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

Warning: Thoughts ahead!

I don't think I realised that a file path was attainable from a RazorCodeDocument, and now I'm wondering if there are other places where I've pass in an IDocumentSnapshot that could actually have taken a RazorCodeDocument.

But I'm also wondering the opposite. Presumably this codeDocument came from an IDocumentSnapshot in the caller, so would it make sense to pass an IDocumentSnapshot all the way through to the GetProjectAvailability methods? In LSP it wouldn't change much, but perhaps it would allow for smarter code in Cohosting, is there if an existing Roslyn API to go from a TextDocument to all of the projects it is contained in. Though I don't think that fits with the current solution query API, so probably unnecessarily overcomplicated for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

There comes a point where it bumps into completion needing tooltips as well. So, at most we would have only been able to push the RazorCodeDocument one method call further. Once everything's happily in co-hosting, I think that's a good change to make.

{
descriptionBuilder.AppendLine();
descriptionBuilder.Append(availability);
var availability = await solutionQueryOperations
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ reading this I would have expected ISolutionQueryOperations.GetProjectAvailabilityTextAsync to handle a null file path and return null. Is there a design decision why it doesn't?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question! The reason is primarily because there's a cost associated with calling GetProjectAvailabilityTextAsync(...). If the null check happens in GetProjectAvailabilityTextAsync(...) we have to make an async call and continue on the thread pool just to perform a null check. That seemed unnecessarily wasteful to me.

Another more opinionated meta reason is that the contract of GetProjectAvailabilityTextAsync(...) is to take a document file path and do something with it. By using a non-nullable string the API states its intent and makes it clear that it needs a document file path to function. By making it nullable, I think the contract is weaker. That might just be my opinion, but non-nullable reference types are all about stating intent, and I don't think GetProjectAvailabilityTextAsync(...) ever wants to be passed a null document file path, so it probably should be clear about that. At least, that was my thought process.

@DustinCampbell DustinCampbell merged commit 3adf6fe into dotnet:main Nov 1, 2024
12 checks passed
@DustinCampbell DustinCampbell deleted the hover-tweaks branch November 1, 2024 17:19
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 1, 2024
@jjonescz jjonescz modified the milestones: Next, 17.13 P2 Nov 25, 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.

4 participants