Skip to content

Commit

Permalink
Remove ProjectDiagnostics from GetDiagnostics to focus on user errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ocalles committed Jun 12, 2024
1 parent 0f28830 commit b3186fd
Showing 1 changed file with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,14 @@ private async Task<Workspace> AppendCodeToWorkspaceAsync(string code, int positi
private static IEnumerable<Diagnostic> GetDiagnostics(string code, CompileResult result)
{
var diagnostics = Enumerable.Empty<SerializableDiagnostic>();
var projectDiagnostics = Enumerable.Empty<SerializableDiagnostic>();

if (result.Features.TryGetValue(nameof(Diagnostics), out var candidateDiagnostics) &&
candidateDiagnostics is Diagnostics diags)
{
diagnostics = diags;
}

if (result.Features.TryGetValue(nameof(ProjectDiagnostics), out var candidateProjectDiagnostics) &&
candidateProjectDiagnostics is ProjectDiagnostics projectDiags)
{
projectDiagnostics = projectDiags;
}

var uniqueDiagnostics = diagnostics.ToDictionary(d => d.Id, d => d);

foreach (var projDiag in projectDiagnostics)
{
if (!uniqueDiagnostics.ContainsKey(projDiag.Id))
{
uniqueDiagnostics.Add(projDiag.Id, projDiag);
}
}

var finalDiagnostics = uniqueDiagnostics.Values.Select(d => new Diagnostic(new LinePositionSpan(GetLinePositionFromPosition(code, d.Start), GetLinePositionFromPosition(code, d.End)), d.Severity, d.Id, d.Message));
var finalDiagnostics = diagnostics.Select(d => new Diagnostic(new LinePositionSpan(GetLinePositionFromPosition(code, d.Start), GetLinePositionFromPosition(code, d.End)), d.Severity, d.Id, d.Message));

return finalDiagnostics;
}
Expand Down

0 comments on commit b3186fd

Please sign in to comment.