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

Remap and translate diagnostics on the server #9151

Merged
merged 4 commits into from
Aug 23, 2023

Conversation

davidwengier
Copy link
Contributor

Server side of dotnet/vscode-csharp#6209

Found an issue in the logs where 2 seconds after a .razor document close, we try to update diagnostics for the document, which then tries to remap the ranges for those diagnostics, but we've just closed the file, the so it fails. This was actually quite wasteful, as the remapping has to happen on the server anyway, so its better to just do it after the results have come back. Additionally, it meant that VS Code diagnostics weren't going through our translation service, which excludes some diagnostics and fixes ranges on others, so the experience would have been generally worse than in VS.

Also renamed a couple of things to make a bit more sense, so the changes are slightly bigger than they first seem.

@@ -191,6 +192,7 @@ public static void AddDocumentManagementServices(this IServiceCollection service
services.AddSingleton<GeneratedDocumentPublisher, DefaultGeneratedDocumentPublisher>();
services.AddSingleton<IProjectSnapshotChangeTrigger>((services) => services.GetRequiredService<GeneratedDocumentPublisher>());
services.AddSingleton<DocumentContextFactory, DefaultDocumentContextFactory>();
services.AddSingleton(sp => new Lazy<DocumentContextFactory>(sp.GetRequiredService<DocumentContextFactory>));
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 the annoying way to do lazy DI in this system, and its annoying, but I didn't think it was worth extracting new services and things, because ideally we can move to pull diagnostics in VS Code soon, and then the entire diagnostic publisher can be deleted.

@@ -29,7 +30,6 @@ internal static class CustomMessageNames
public const string RazorResolveCodeActionsEndpoint = "razor/resolveCodeActions";
public const string RazorProvideHtmlColorPresentationEndpoint = "razor/provideHtmlColorPresentation";
public const string RazorProvideHtmlDocumentColorEndpoint = "razor/provideHtmlDocumentColor";
public const string RazorPullDiagnosticEndpointName = "razor/pullDiagnostics";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously VS and VS Code both used this method name, but to my surprise, with different response types. Not strictly an issue since the two systems never exist together, but I thought it would be easier to audit things in future if it wasn't confusing.

@@ -193,8 +209,8 @@ internal async Task PublishDiagnosticsAsync(IDocumentSnapshot document)
{
var result = await document.GetGeneratedOutputAsync().ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Move this below the if next to where it's used

@davidwengier davidwengier merged commit a3213d6 into dotnet:main Aug 23, 2023
@davidwengier davidwengier deleted the MapDiagnosticsOnServer branch August 23, 2023 21:56
@ghost ghost added this to the Next milestone Aug 23, 2023
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
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.

3 participants