Skip to content

Commit

Permalink
Ensure execution diagnostics are logged as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Oct 21, 2023
1 parent a44f928 commit 70b64e2
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
return binaryLogPath;
}

private async Task<(LSP.MessageType? failureType, BuildHostProcessKind? preferredKind)> LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken)
private async Task<(LSP.MessageType? FailureType, BuildHostProcessKind? PreferredKind)> LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken)
{
BuildHostProcessKind? preferredBuildHostKind = null;

Expand All @@ -207,11 +207,10 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
{
var loadedFile = await buildHost.LoadProjectFileAsync(projectPath, cancellationToken);
var diagnosticLogItems = await loadedFile.GetDiagnosticLogItemsAsync(cancellationToken);
LogDiagnostics(projectPath, diagnosticLogItems);

if (diagnosticLogItems.Any(item => item.Kind is WorkspaceDiagnosticKind.Failure))
{
// If there were any total failures, no point in continuing.
_ = LogDiagnostics(projectPath, diagnosticLogItems);
// We have total failures in evaluation, no point in continuing.
return (LSP.MessageType.Error, preferredBuildHostKind);
}

Expand Down Expand Up @@ -257,7 +256,14 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
}

await _projectLoadTelemetryReporter.ReportProjectLoadTelemetryAsync(projectFileInfos, projectToLoad, cancellationToken);
_logger.LogInformation($"Successfully completed load of {projectPath}");
diagnosticLogItems = await loadedFile.GetDiagnosticLogItemsAsync(cancellationToken);
var errorLevel = LogDiagnostics(projectPath, diagnosticLogItems);
if (errorLevel == null)
{
_logger.LogInformation($"Successfully completed load of {projectToLoad}");
}

return (errorLevel, preferredBuildHostKind);
}

return (null, null);
Expand All @@ -268,13 +274,20 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
return (LSP.MessageType.Error, preferredBuildHostKind);
}

void LogDiagnostics(string projectPath, ImmutableArray<DiagnosticLogItem> diagnosticLogItems)
LSP.MessageType? LogDiagnostics(string projectPath, ImmutableArray<DiagnosticLogItem> diagnosticLogItems)
{
if (diagnosticLogItems.IsEmpty)
{
return null;
}

foreach (var logItem in diagnosticLogItems)
{
var projectName = Path.GetFileName(projectPath);
_logger.Log(logItem.Kind is WorkspaceDiagnosticKind.Failure ? LogLevel.Error : LogLevel.Warning, $"{logItem.Kind} while loading {logItem.ProjectFilePath}: {logItem.Message}");
}

return diagnosticLogItems.Any(logItem => logItem.Kind is WorkspaceDiagnosticKind.Failure) ? LSP.MessageType.Error : LSP.MessageType.Warning;
}
}
}

0 comments on commit 70b64e2

Please sign in to comment.