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

Check UI context before trying to initialize cohosting #73172

Merged
merged 6 commits into from Apr 24, 2024

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Apr 22, 2024

Fixes dotnet/razor#10279 and a 4 image load regression on the latest Razor insertion
Fixes AB#2045232

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 22, 2024
Co-authored-by: ady109 <149323961+ady109@users.noreply.github.com>
@davidwengier davidwengier requested a review from a team April 22, 2024 21:19
@davidwengier davidwengier marked this pull request as ready for review April 22, 2024 21:19
@davidwengier davidwengier requested a review from a team as a code owner April 22, 2024 21:19
var uiContext = UIContext.FromUIContextGuid(Constants.RazorCohostingUIContext);
uiContext.WhenActivated(() =>
{
// Not using the cancellation token passed in, as the context could be activated well after LSP server initialization
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, might need to expose a way for something to access a general server cancellation token for things that should be cancelled when the server shutsdown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDisposable was enough for this, and much simpler.

One thing I noticed from my testing though, as FYI, the "AlwaysActive" server initializes when Roslyn loads, and then shuts down when a solution is closed. Fine, makes sense. BUT if I then open a solution again, it doesn't get initialized again until a C# file is opened. In other words. No idea if that could/would be a problem ever.

Copy link
Member

Choose a reason for hiding this comment

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

Right, dispose should take care of it since its an LSP service - good call.

BUT if I then open a solution again, it doesn't get initialized again until a C# file is opened. In other words. No idea if that could/would be a problem ever.

Yes, theres a potential bug there - workspace level requests won't get fulfilled on the second solution open unti la file is opened. I think its because the VS workspace doesn't get recreated (so the event listener doesn't trigger).

davidwengier added a commit to dotnet/razor that referenced this pull request Apr 22, 2024
Register the UI context for Razor, so it can be used in Roslyn (see
dotnet/roslyn#73172)

Will eventual fix #10279 once the
Roslyn side is in
Part of #9519
@davidwengier davidwengier requested a review from a team as a code owner April 22, 2024 22:25

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;

[ExportCSharpVisualBasicLspServiceFactory(typeof(RazorDynamicRegistrationService), WellKnownLspServerKinds.AlwaysActiveVSLspServer), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class RazorDynamicRegistrationServiceFactory([Import(AllowDefault = true)] IRazorCohostDynamicRegistrationService? dynamicRegistrationService) : ILspServiceFactory
internal sealed class RazorDynamicRegistrationServiceFactory(
[Import(AllowDefault = true)] IUIContextActivationService? uIContextActivationService,
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to allow null here because this is used in vscode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is null because I'm paranoid, and an interface defined in one layer, and implemented in another, seems like a recipe for null to me. This doesn't ship in VS Code, at least not in the .roslyn folder, but it is present in OOP, and who knows where else. It shouldn't be imported by anything other than the always active LSP server, so maybe this is worrying about nothing?

Copy link
Member

Choose a reason for hiding this comment

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

Ah if it is in OOP it might not be present - but then editor features I don't think is in OOP, so maybe the interface definition needs to move down? Not 100% sure on that one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EditorFeatures is in OOP on my machine at least. Perhaps it shouldn't be, but in future if we split the EA into language server and editor features layers, this would stick with editors features anyway I think. Plus I can't see any obvious place to put this that makes sense in Features :P


namespace Microsoft.CodeAnalysis.Editor.Shared.Utilities;

internal interface IUIContextActivationService
Copy link
Member

Choose a reason for hiding this comment

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

Editor features is not available in vscode. If you're expecting the code in the EA layer to run in vscode, this needs to be moved down, to the protocol layer or features layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned, this doesn't ship in VS Code. We'll need a new EA assembly for that eventually.

@davidwengier davidwengier merged commit 1288876 into dotnet:main Apr 24, 2024
25 checks passed
@davidwengier davidwengier deleted the RazorUIContext branch April 24, 2024 05:59
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 24, 2024
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't load Razor when not necessary
3 participants