From c1dff076d5194ac0d49e394556fcfd9b1a7a127b Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Mon, 5 Oct 2020 15:37:52 -0700 Subject: [PATCH] When an analyzer fails to load, log an error Right now we just silently fail which isn't a good debugging experience. Ideally these would be shown in the error list but this is good enough when trying to track things down. --- src/OmniSharp.MSBuild/ProjectManager.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/OmniSharp.MSBuild/ProjectManager.cs b/src/OmniSharp.MSBuild/ProjectManager.cs index c545906e24..a58c491fb5 100644 --- a/src/OmniSharp.MSBuild/ProjectManager.cs +++ b/src/OmniSharp.MSBuild/ProjectManager.cs @@ -366,6 +366,8 @@ private void AddProject(ProjectFileInfo projectFileInfo) var newSolution = _workspace.CurrentSolution.AddProject(projectInfo); _workspace.AddDocumentInclusionRuleForProject(projectInfo.Id, (filePath) => projectFileInfo.IsFileIncluded(filePath)); + SubscribeToAnalyzerReferenceLoadFailures(projectInfo.AnalyzerReferences.Cast(), _logger); + if (!_workspace.TryApplyChanges(newSolution)) { _logger.LogError($"Failed to add project to workspace: '{projectFileInfo.FilePath}'"); @@ -478,10 +480,22 @@ private void UpdateAnalyzerReferences(Project project, ProjectFileInfo projectFi { var analyzerFileReferences = projectFileInfo.ResolveAnalyzerReferencesForProject(_analyzerAssemblyLoader); + SubscribeToAnalyzerReferenceLoadFailures(analyzerFileReferences, _logger); _workspace.SetAnalyzerReferences(project.Id, analyzerFileReferences); } + private void SubscribeToAnalyzerReferenceLoadFailures(IEnumerable analyzerFileReferences, ILogger logger) + { + foreach (var analyzerFileReference in analyzerFileReferences) + { + analyzerFileReference.AnalyzerLoadFailed += (sender, e) => + { + logger.LogError($"Failure while loading the analyzer reference '{analyzerFileReference.Display}': {e.Message}"); + }; + } + } + private void UpdateProjectProperties(Project project, ProjectFileInfo projectFileInfo) { if (projectFileInfo.DefaultNamespace != project.DefaultNamespace)