From 53b5f4aafc0d19996d323c80850a5b3a4558e4fa Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 19 Oct 2023 15:24:27 -0700 Subject: [PATCH] Ensure diagnostics are logged before proceeding with further project loading --- .../LanguageServerProjectSystem.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs index 0e187df5c44c4..908c4ff9b0f1e 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.ProjectTelemetry; using Microsoft.CodeAnalysis.MSBuild; +using Microsoft.CodeAnalysis.MSBuild.Logging; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.ProjectSystem; using Microsoft.CodeAnalysis.Shared.TestHooks; @@ -196,6 +197,7 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList? projectLoadDiagnostics = null; try { var projectPath = projectToLoad.Path; @@ -205,6 +207,15 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList item.Kind is WorkspaceDiagnosticKind.Failure)) + { + // If there were any total failures, no point in continuing. + return (LSP.MessageType.Error, preferredBuildHostKind); + } + var loadedProjectInfos = await loadedFile.GetProjectFileInfosAsync(cancellationToken); // The out-of-proc build host supports more languages than we may actually have Workspace binaries for, so ensure we can actually process that @@ -247,23 +258,7 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList logItem.Kind is WorkspaceDiagnosticKind.Failure) ? LSP.MessageType.Error : LSP.MessageType.Warning, preferredBuildHostKind); - } - else - { - _logger.LogInformation($"Successfully completed load of {projectPath}"); - return (null, null); - } + _logger.LogInformation($"Successfully completed load of {projectPath}"); } return (null, null); @@ -273,5 +268,14 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList diagnosticLogItems) + { + 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}"); + } + } } }