Skip to content

Commit

Permalink
When an analyzer fails to load, log an error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasonmalinowski committed Oct 6, 2020
1 parent 8222ac9 commit c1dff07
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnalyzerFileReference>(), _logger);

if (!_workspace.TryApplyChanges(newSolution))
{
_logger.LogError($"Failed to add project to workspace: '{projectFileInfo.FilePath}'");
Expand Down Expand Up @@ -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<AnalyzerFileReference> 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)
Expand Down

0 comments on commit c1dff07

Please sign in to comment.