-
Notifications
You must be signed in to change notification settings - Fork 215
Remove RLSP alias by limiting direct references to CLaSP types to Microsoft.AspNetCore.Razor.LanguageServer #11708
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
Conversation
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.
There was a problem hiding this 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.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SignatureHelp/SignatureHelpEndpoint.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CLaSPTypeHelpers.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspServices.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Microsoft.CodeAnalysis.Remote.Razor.csproj
Outdated
Show resolved
Hide resolved
src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageServerTest.cs
Show resolved
Hide resolved
Thanks for your thoughts! I'll go ahead and merge this one. |
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.