Skip to content

Commit

Permalink
Add additional files to output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel authored and daveaglick committed Sep 1, 2023
1 parent 95558c5 commit cb00c8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions src/Buildalyzer.Workspaces/AnalyzerResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private static ProjectInfo GetProjectInfo(IAnalyzerResult analyzerResult, Worksp
projectReferences: GetExistingProjectReferences(analyzerResult, workspace),
metadataReferences: GetMetadataReferences(analyzerResult),
analyzerReferences: GetAnalyzerReferences(analyzerResult, workspace),
additionalDocuments: GetAdditionalDocuments(analyzerResult, projectId),
parseOptions: CreateParseOptions(analyzerResult, languageName),
compilationOptions: CreateCompilationOptions(analyzerResult, languageName));
}
Expand Down Expand Up @@ -267,17 +268,28 @@ private static IEnumerable<IProjectAnalyzer> GetReferencedAnalyzerProjects(IAnal
?? Array.Empty<ProjectAnalyzer>();

private static IEnumerable<DocumentInfo> GetDocuments(IAnalyzerResult analyzerResult, ProjectId projectId) =>
analyzerResult
.SourceFiles?.Where(File.Exists)
.Select(x => DocumentInfo.Create(
DocumentId.CreateNewId(projectId),
Path.GetFileName(x),
loader: TextLoader.From(
TextAndVersion.Create(
SourceText.From(File.ReadAllText(x), Encoding.Unicode), VersionStamp.Create())),
filePath: x))
GetDocuments(analyzerResult.SourceFiles, projectId);

private static IEnumerable<DocumentInfo> GetDocuments(IEnumerable<string> files, ProjectId projectId) =>
files?.Where(File.Exists)
.Select(x => DocumentInfo.Create(
DocumentId.CreateNewId(projectId),
Path.GetFileName(x),
loader: TextLoader.From(
TextAndVersion.Create(
SourceText.From(File.ReadAllText(x), Encoding.Unicode), VersionStamp.Create())),
filePath: x))
?? Array.Empty<DocumentInfo>();

private static IEnumerable<DocumentInfo> GetAdditionalDocuments(IAnalyzerResult analyzerResult, ProjectId projectId)
{
string projectDirectory = Path.GetDirectoryName(analyzerResult.ProjectFilePath);

return GetDocuments(
analyzerResult.AdditionalFiles?.Select(x => Path.Combine(projectDirectory, x)),
projectId);
}

private static IEnumerable<MetadataReference> GetMetadataReferences(IAnalyzerResult analyzerResult) =>
analyzerResult
.References?.Where(File.Exists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void SupportsAdditionalFiles()
// Then
string logged = log.ToString();
logged.ShouldNotContain("Workspace failed", logged);
project.AdditionalDocuments.ShouldContain(doc => Path.GetFileName(doc.FilePath) == "message.txt");
project.AdditionalDocuments.Select(d => d.Name).ShouldBe(new[] { "message.txt" });
}

#if Is_Windows
Expand Down

0 comments on commit cb00c8c

Please sign in to comment.