From a44f9285ec441fce912cc96b846549d0de0abd37 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 19 Oct 2023 15:24:27 -0700 Subject: [PATCH 1/2] Ensure diagnostics are logged before proceeding with further project loading --- .../LanguageServerProjectSystem.cs | 37 ++++++++++--------- 1 file changed, 20 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..c849f47d63a5f 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; @@ -205,6 +206,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 +257,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 +267,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}"); + } + } } } From 70b64e24382eb3f649298a0c217741b5207097a8 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Fri, 20 Oct 2023 18:38:04 -0700 Subject: [PATCH 2/2] Ensure execution diagnostics are logged as well --- .../LanguageServerProjectSystem.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs index c849f47d63a5f..9311bc3c886f5 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs @@ -193,7 +193,7 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList 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; @@ -207,11 +207,10 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList 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); } @@ -257,7 +256,14 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList diagnosticLogItems) + LSP.MessageType? LogDiagnostics(string projectPath, ImmutableArray 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; } } }