Skip to content

Commit

Permalink
Decouple document management in ProjectWorkspace from physical I/O.
Browse files Browse the repository at this point in the history
Closes #78.
  • Loading branch information
alexrp committed May 2, 2023
1 parent 95c04bc commit 95df8b5
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/language/tooling/Workspaces/ProjectWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ public sealed class ProjectWorkspace : Workspace

public ProjectConfiguration Configuration { get; }

private readonly DirectoryInfo _sourceDirectory;

private readonly bool _disableAnalysis;

private ProjectWorkspace(
string path, SourceTextProvider textProvider, ProjectConfiguration configuration, bool disableAnalysis)
: base(path, textProvider)
{
Configuration = configuration;
_sourceDirectory = new(System.IO.Path.Join(path, configuration.SourcePath));
_disableAnalysis = disableAnalysis;
}

Expand Down Expand Up @@ -57,26 +54,13 @@ protected internal override IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyze

protected override WorkspaceDocumentAttributes GetDocumentAttributes(string path)
{
var file = new FileInfo(System.IO.Path.Join(Path, path));
var srcAttrs = _disableAnalysis
? WorkspaceDocumentAttributes.DisableAnalyzers | WorkspaceDocumentAttributes.SuppressDiagnostics
var attrs = path == WorkspaceDocument.EntryPointPath
? WorkspaceDocumentAttributes.EntryPoint
: WorkspaceDocumentAttributes.None;

if ((file.DirectoryName, file.Name) == (_sourceDirectory.FullName, WorkspaceDocument.EntryPointPath))
return WorkspaceDocumentAttributes.EntryPoint | srcAttrs;

var current = file.Directory;

while (current != null)
{
// Is the document within the configured source directory?
if (current.FullName == _sourceDirectory.FullName)
return srcAttrs;

current = current.Parent;
}
if (_disableAnalysis || System.IO.Path.GetDirectoryName(path) != Configuration.SourcePath)
attrs |= WorkspaceDocumentAttributes.DisableAnalyzers | WorkspaceDocumentAttributes.SuppressDiagnostics;

// It must be a loose document or a dependency document, so no analyzers and diagnostics.
return WorkspaceDocumentAttributes.DisableAnalyzers | WorkspaceDocumentAttributes.SuppressDiagnostics;
return attrs;
}
}

0 comments on commit 95df8b5

Please sign in to comment.