exclude emitted source gen files from workspace

This commit is contained in:
Matt Parker
2025-11-24 18:10:35 +10:00
parent 3c84754c1f
commit 529784f606
2 changed files with 11 additions and 3 deletions

View File

@@ -965,7 +965,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
return true; return true;
} }
public async Task AddDocument(SharpIdeFile fileModel, string content) public async Task<bool> AddDocument(SharpIdeFile fileModel, string content)
{ {
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(AddDocument)}"); using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(AddDocument)}");
await _solutionLoadedTcs.Task; await _solutionLoadedTcs.Task;
@@ -977,6 +977,12 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
// This file probably belongs to this project, but we need to check its path against the globs for the project to make sure // This file probably belongs to this project, but we need to check its path against the globs for the project to make sure
var projectFileInfo = _projectFileInfoMap.GetValueOrDefault(probableProject.Id); var projectFileInfo = _projectFileInfoMap.GetValueOrDefault(probableProject.Id);
Guard.Against.Null(projectFileInfo); Guard.Against.Null(projectFileInfo);
var generatedFilesOutputDirectory = projectFileInfo.GeneratedFilesOutputDirectory;
if (generatedFilesOutputDirectory is not null && fileModel.Path.StartsWith(generatedFilesOutputDirectory, StringComparison.OrdinalIgnoreCase))
{
return false;
}
var matchers = projectFileInfo.FileGlobs.Select(glob => var matchers = projectFileInfo.FileGlobs.Select(glob =>
{ {
var matcher = new Matcher(); var matcher = new Matcher();
@@ -1005,7 +1011,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
if (belongsToProject is false) if (belongsToProject is false)
{ {
return; return false;
} }
var existingDocumentIdsWithFilePath = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path); var existingDocumentIdsWithFilePath = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path);
@@ -1026,6 +1032,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
}; };
return newSolution; return newSolution;
}, WorkspaceChangeKind.DocumentAdded, documentId: documentId); }, WorkspaceChangeKind.DocumentAdded, documentId: documentId);
return true;
} }
public async Task<bool> RemoveDocument(SharpIdeFile fileModel) public async Task<bool> RemoveDocument(SharpIdeFile fileModel)

View File

@@ -140,7 +140,8 @@ public class FileChangedService
private async Task HandleWorkspaceFileAdded(SharpIdeFile file, string contents) private async Task HandleWorkspaceFileAdded(SharpIdeFile file, string contents)
{ {
await _roslynAnalysis.AddDocument(file, contents); var success = await _roslynAnalysis.AddDocument(file, contents);
if (success is false) return;
GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget(); GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget();
_updateSolutionDiagnosticsQueue.AddWork(); _updateSolutionDiagnosticsQueue.AddWork();
} }