Skip to content

Commit

Permalink
Unify the creation of AnalyzerFileReferences into a single place
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmalinowski committed Oct 6, 2020
1 parent 8c35bd9 commit 8222ac9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static ImmutableDictionary<string, ReportDiagnostic> GetDiagnosticOptions

public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
{
var analyzerReferences = ResolveAnalyzerReferencesForProject(projectFileInfo, analyzerAssemblyLoader);
var analyzerReferences = projectFileInfo.ResolveAnalyzerReferencesForProject(analyzerAssemblyLoader);

return ProjectInfo.Create(
id: projectFileInfo.Id,
Expand All @@ -95,19 +95,19 @@ public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo
analyzerReferences: analyzerReferences).WithDefaultNamespace(projectFileInfo.DefaultNamespace);
}

private static IEnumerable<AnalyzerReference> ResolveAnalyzerReferencesForProject(ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
public static ImmutableArray<AnalyzerFileReference> ResolveAnalyzerReferencesForProject(this ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
{
if (!projectFileInfo.RunAnalyzers || !projectFileInfo.RunAnalyzersDuringLiveAnalysis)
{
return Enumerable.Empty<AnalyzerReference>();
return ImmutableArray<AnalyzerFileReference>.Empty;
}

foreach(var analyzerAssemblyPath in projectFileInfo.Analyzers.Distinct())
{
analyzerAssemblyLoader.AddDependencyLocation(analyzerAssemblyPath);
}

return projectFileInfo.Analyzers.Select(analyzerCandicatePath => new AnalyzerFileReference(analyzerCandicatePath, analyzerAssemblyLoader));
return projectFileInfo.Analyzers.Select(analyzerCandicatePath => new AnalyzerFileReference(analyzerCandicatePath, analyzerAssemblyLoader)).ToImmutableArray();
}
}
}
9 changes: 1 addition & 8 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,8 @@ private void UpdateProject(string projectFilePath)

private void UpdateAnalyzerReferences(Project project, ProjectFileInfo projectFileInfo)
{
if (!projectFileInfo.RunAnalyzers || !projectFileInfo.RunAnalyzersDuringLiveAnalysis)
{
_workspace.SetAnalyzerReferences(project.Id, ImmutableArray<AnalyzerFileReference>.Empty);
return;
}
var analyzerFileReferences = projectFileInfo.ResolveAnalyzerReferencesForProject(_analyzerAssemblyLoader);

var analyzerFileReferences = projectFileInfo.Analyzers
.Select(analyzerReferencePath => new AnalyzerFileReference(analyzerReferencePath, _analyzerAssemblyLoader))
.ToImmutableArray();

_workspace.SetAnalyzerReferences(project.Id, analyzerFileReferences);
}
Expand Down

0 comments on commit 8222ac9

Please sign in to comment.