Skip to content

Commit

Permalink
Remove ProjectFileInfo.Log
Browse files Browse the repository at this point in the history
The shape of this type was a bit deceiving: a ProjectFile has a Log
property, and this also having a Log property makes it appear like
there's one log for the basic loading of the project, and then a second
log for the actual loading for a specific TFM. This is however not the
case: ProjectFileInfo.Log would always be the same instance as the
ProjectFile it came from. Removing this is easy, as the only place
it was ever used was where we already had the ProjectFile in hand,
and it makes ProjectFileInfo a simple data type.
  • Loading branch information
jasonmalinowski committed Aug 22, 2023
1 parent 784b438 commit b7f609f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<ImmutableArray<ProjectFileInfo>> GetProjectFileInfosAsync(Canc
{
if (_loadedProject is null)
{
return ImmutableArray.Create(ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath, Log));
return ImmutableArray.Create(ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath));
}

var targetFrameworkValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFramework);
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task<ImmutableArray<ProjectFileInfo>> GetProjectFileInfosAsync(Canc
else
{
var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false);
projectFileInfo ??= ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath, Log);
projectFileInfo ??= ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath);
return ImmutableArray.Create(projectFileInfo);
}
}
Expand All @@ -101,14 +101,14 @@ private async Task<ProjectFileInfo> BuildProjectFileInfoAsync(CancellationToken
{
if (_loadedProject is null)
{
return ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath, Log);
return ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath);
}

var project = await _buildManager.BuildProjectAsync(_loadedProject, Log, cancellationToken).ConfigureAwait(false);

return project != null
? CreateProjectFileInfo(project)
: ProjectFileInfo.CreateEmpty(Language, _loadedProject.FullPath, Log);
: ProjectFileInfo.CreateEmpty(Language, _loadedProject.FullPath);
}

private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance project)
Expand Down Expand Up @@ -174,8 +174,7 @@ private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance proj
docs,
additionalDocs,
analyzerConfigDocs,
project.GetProjectReferences().ToImmutableArray(),
Log);
project.GetProjectReferences().ToImmutableArray());
}

private ImmutableArray<string> GetCommandLineArgs(MSB.Execution.ProjectInstance project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ internal sealed class ProjectFileInfo
/// </summary>
public ImmutableArray<ProjectFileReference> ProjectReferences { get; }

/// <summary>
/// The error message produced when a failure occurred attempting to get the info.
/// If a failure occurred some or all of the information may be inaccurate or incomplete.
/// </summary>
public DiagnosticLog Log { get; }

public override string ToString()
=> RoslynString.IsNullOrWhiteSpace(TargetFramework)
? FilePath ?? string.Empty
Expand All @@ -118,8 +112,7 @@ public override string ToString()
ImmutableArray<DocumentFileInfo> documents,
ImmutableArray<DocumentFileInfo> additionalDocuments,
ImmutableArray<DocumentFileInfo> analyzerConfigDocuments,
ImmutableArray<ProjectFileReference> projectReferences,
DiagnosticLog log)
ImmutableArray<ProjectFileReference> projectReferences)
{
RoslynDebug.Assert(filePath != null);

Expand All @@ -137,7 +130,6 @@ public override string ToString()
this.AdditionalDocuments = additionalDocuments;
this.AnalyzerConfigDocuments = analyzerConfigDocuments;
this.ProjectReferences = projectReferences;
this.Log = log;
}

public static ProjectFileInfo Create(
Expand All @@ -153,8 +145,7 @@ public override string ToString()
ImmutableArray<DocumentFileInfo> documents,
ImmutableArray<DocumentFileInfo> additionalDocuments,
ImmutableArray<DocumentFileInfo> analyzerConfigDocuments,
ImmutableArray<ProjectFileReference> projectReferences,
DiagnosticLog log)
ImmutableArray<ProjectFileReference> projectReferences)
=> new(
isEmpty: false,
language,
Expand All @@ -169,10 +160,9 @@ public override string ToString()
documents,
additionalDocuments,
analyzerConfigDocuments,
projectReferences,
log);
projectReferences);

public static ProjectFileInfo CreateEmpty(string language, string? filePath, DiagnosticLog log)
public static ProjectFileInfo CreateEmpty(string language, string? filePath)
=> new(
isEmpty: true,
language,
Expand All @@ -187,7 +177,6 @@ public static ProjectFileInfo CreateEmpty(string language, string? filePath, Dia
documents: ImmutableArray<DocumentFileInfo>.Empty,
additionalDocuments: ImmutableArray<DocumentFileInfo>.Empty,
analyzerConfigDocuments: ImmutableArray<DocumentFileInfo>.Empty,
projectReferences: ImmutableArray<ProjectFileReference>.Empty,
log);
projectReferences: ImmutableArray<ProjectFileReference>.Empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private async Task<ImmutableArray<ProjectFileInfo>> LoadProjectFileInfosAsync(st
_diagnosticReporter.Report(projectFile.Log);

return ImmutableArray.Create(
ProjectFileInfo.CreateEmpty(loader.Language, projectPath, projectFile.Log));
ProjectFileInfo.CreateEmpty(loader.Language, projectPath));
}

var projectFileInfos = await DoOperationAndReportProgressAsync(
Expand All @@ -212,10 +212,8 @@ private async Task<ImmutableArray<ProjectFileInfo>> LoadProjectFileInfosAsync(st
foreach (var projectFileInfo in projectFileInfos)
{
// If any diagnostics were logged during build, we'll carry on and try to produce a meaningful project.
if (!projectFileInfo.Log.IsEmpty)
{
_diagnosticReporter.Report(projectFileInfo.Log);
}
// Note: any diagnostics would have been logged to the original project file's log.
_diagnosticReporter.Report(projectFile.Log);

results.Add(projectFileInfo);
}
Expand Down

0 comments on commit b7f609f

Please sign in to comment.