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

Don't expose MS.VS.LanguageServer.Protocol types from EA.Razor #68713

Merged
merged 4 commits into from
Jun 23, 2023

Conversation

davidwengier
Copy link
Member

@davidwengier davidwengier commented Jun 21, 2023

We had a bit of a situation today, due to our EA having types from MS.VS.LanguageServer.Protocol exposed in its API. It means as soon as Roslyn inserts to VS referencing a new version, Razor functionality and local dev stops working.

To avoid a dual insertion I've just made the old API obsolete, and will follow up with removal once everything is inserted appropriately. Using strings and serializing capabilities is not ideal, but I couldn't think of another way, and the scenario is only used from our tests. In fact, I'd love to rename all of the language server wrapper classes to include "Test" in the name, but that seemed like an annoying amount of code to obsolete and duplicate.

@davidwengier davidwengier requested a review from a team as a code owner June 21, 2023 12:00
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 21, 2023
Comment on lines 118 to 119
public static SemanticTokensSchema GetSchema(ClientCapabilities capabilities)
=> capabilities.HasVisualStudioLspCapability()
=> GetSchema(capabilities.HasVisualStudioLspCapability());
Copy link
Member Author

Choose a reason for hiding this comment

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

Let me know if you want me to remove this overload completely. Every caller could just pass capabilities.HasVisualStudioLspCapability() and it would all work the same.

Copy link
Member

Choose a reason for hiding this comment

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

I think its reasonable to remove the client capabilities overload entirely

Comment on lines 118 to 119
public static SemanticTokensSchema GetSchema(ClientCapabilities capabilities)
=> capabilities.HasVisualStudioLspCapability()
=> GetSchema(capabilities.HasVisualStudioLspCapability());
Copy link
Member

Choose a reason for hiding this comment

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

I think its reasonable to remove the client capabilities overload entirely

internal interface IRazorCapabilitiesProvider
{
ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities);
}

/// <summary>
/// A capabilities provider that should only be used from Razor tests
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's anything we can use to ban the usage of any LSP protocol types in this project. Maybe ban the entire LSP protocol namespace?
https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md

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 thought about this too, but the issue is that we don't want to ban the usage, just the exposure. In fact we require the usage, because thats what the Roslyn LSP server we're interacting with needs.

{
// To avoid exposing types from MS.VS.LanguageServer.Protocol types we serialize and deserialize the capabilities
// so we can just pass string around. This is obviously not great for perf, but it is only used in Razor tests.
var clientCapabilitiesJson = JsonConvert.SerializeObject(clientCapabilities);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@davidwengier davidwengier Jun 22, 2023

Choose a reason for hiding this comment

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

For completeness, probably, but we don't actually need that, because I'm explicitly telling NewtonSoft that its a VSInternalServerCapabilities, which is the highest level type. The type converters are needed, AFAIK, for when you ask it to [de]serialize a lower level type, but don't want to lose the info from the higher types.

Also, this is only used by tests, our scenario is super simple. We only set SupportsDiagnosticsRequests, and always serialize a VSInternalServerCapabilities: https://github.com/dotnet/razor/blob/main/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.cs#L75

@davidwengier
Copy link
Member Author

Removed the extra overload. Also the Razor response is here in case you're curious, but its super unexciting: dotnet/razor#8855

@davidwengier davidwengier merged commit 832d1ac into dotnet:main Jun 23, 2023
@davidwengier davidwengier deleted the DontExposeVSLSPTypes branch June 23, 2023 00:59
@ghost ghost added this to the Next milestone Jun 23, 2023
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE 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.

4 participants