Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ internal static partial class EditAndContinueDiagnosticSource
{
private sealed class OpenDocumentSource(Document document) : AbstractDocumentDiagnosticSource<Document>(document)
{
public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken)
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken)
=> GetDiagnosticsAsync(Document, cancellationToken);

public static async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Document document, CancellationToken cancellationToken)
{
var solution = Document.Project.Solution;
var solution = document.Project.Solution;
var services = solution.Services;

// Do not report EnC diagnostics for a non-host workspace, or if Hot Reload/EnC session is not active.
Expand All @@ -27,7 +30,7 @@ public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(R
return [];
}

var applyDiagnostics = sessionStateTracker.ApplyChangesDiagnostics.WhereAsArray(static (data, id) => data.DocumentId == id, Document.Id);
var applyDiagnostics = sessionStateTracker.ApplyChangesDiagnostics.WhereAsArray(static (data, id) => data.DocumentId == id, document.Id);

var proxy = new RemoteEditAndContinueServiceProxy(services);
var spanLocator = services.GetService<IActiveStatementSpanLocator>();
Expand All @@ -36,12 +39,15 @@ public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(R
? new ActiveStatementSpanProvider((documentId, filePath, cancellationToken) => spanLocator.GetSpansAsync(solution, documentId, filePath, cancellationToken))
: static async (_, _, _) => ImmutableArray<ActiveStatementSpan>.Empty;

var rudeEditDiagnostics = await proxy.GetDocumentDiagnosticsAsync(Document, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false);
var rudeEditDiagnostics = await proxy.GetDocumentDiagnosticsAsync(document, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false);

return applyDiagnostics.AddRange(rudeEditDiagnostics);
}
}

public static IDiagnosticSource CreateOpenDocumentSource(Document document)
=> new OpenDocumentSource(document);

internal static Task<ImmutableArray<DiagnosticData>> GetDocumentDiagnosticsAsync(Document document, CancellationToken cancellationToken)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why have this helper if you alread hve exposed GetDiagnosticsAsync(doc, ct) publicly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh. i see. there are two classes here. one nested in the other. ok.

=> OpenDocumentSource.GetDiagnosticsAsync(document, cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics;
using Microsoft.CodeAnalysis.Options;
Expand All @@ -31,7 +33,9 @@ public static LSP.VSDiagnosticProjectInformation GetProjectInformation(Project p
var diagnostics = await diagnosticAnalyzerService.GetDiagnosticsForSpanAsync(
document, range: null, DiagnosticKind.All, cancellationToken).ConfigureAwait(false);

return GetLspDiagnostics(document, supportsVisualStudioExtensions, globalOptionsService, diagnostics);
var encDiagnostics = await EditAndContinueDiagnosticSource.GetDocumentDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false);

return GetLspDiagnostics(document, supportsVisualStudioExtensions, globalOptionsService, diagnostics.Concat(encDiagnostics));
}

public static async Task<ImmutableArray<LSP.Diagnostic>> GetTaskListAsync(Document document, bool supportsVisualStudioExtensions, CancellationToken cancellationToken)
Expand Down
Loading