Skip to content

Conversation

DustinCampbell
Copy link
Member

Razor now uses the Roslyn.LanguageServer.Protocol types directly, which is awesome! However, it comes at the cost of type ambiguities because Razor compiles CLaSP into Microsoft.AspNetCore.Razor.LanguageServer as a source package, but CLaSP is also compiled into Microsoft.CodeAnalysis.LanguageServer.Protocol, which includes the Roslyn LSP types. Initially, we've avoided the type ambiguities by using RLSP as an extern alias everywhere, which is a bit awkward. This pull request avoids needing an extern alias by restricting direct references to CLaSP types to code within Microsoft.AspNetCore.Razor.LanguageServer. I've left this as a draft PR to see if this approach seems reasonable. Do we like being able to use Roslyn LSP types directly without awkwardness or would we prefer to allow direct access to CLaSP types? To me, the Roslyn LSP types seems like the future direction, and we should lean into that, but I'm curious to know if others feel differently.

The GetRegisteredServices and SupportsGetRegisteredServices methods are not defined on ILspServices and are unused by Razor.
Lock to avoid double-disposal and don't expose IsDisiposed as a public, mutable field.
Add LspServices.Empty, which can be used in place of ILspServices mocks used in tests.
LspServices already adds itself to the service collection as ILspServices. By also adding itself with it's class type, LspServices, external code can retrieve it without going through ILspServices.
RazorRequestContextFactory was using LspServices to request services that are available from DI whenever CreateREquestContextAsync(...) was called.
Only one IOnInitialized implementation actually used the ILspServices passed into OnInitializedAsync, and it can easily just impoirt LspServices from DI.
This is a bit of a hack, but allows the RazorLanguageServerTest.AllHandlersRegisteredAsync() test to function without directly referencing types defined by CLaSP.
Now that direct references to CLaSP types are isolated within Microsoft.AspNetCore.Razor.LanguageServer, the RLSP extern alias is no longer needed.
Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

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

Very happy with this as the path forward. Small questions but nothing blocking.

If a developer accidentally uses a CLaSP type what is the experience? Would they know it was wrong and how to correctly do what they were trying to? It seems unlikely but I could see it happening in rzls for example.

Copy link
Member

@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.

LGTM

@DustinCampbell DustinCampbell marked this pull request as ready for review April 5, 2025 00:42
@DustinCampbell DustinCampbell requested a review from a team as a code owner April 5, 2025 00:42
@DustinCampbell DustinCampbell merged commit 573e014 into dotnet:main Apr 5, 2025
16 checks passed
@DustinCampbell DustinCampbell deleted the remove-rlsp-alias branch April 5, 2025 17:12
@DustinCampbell
Copy link
Member Author

Thanks for your thoughts! I'll go ahead and merge this one.

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