Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further refactoring of Razor tooling project system #11320

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fcfd3ce
ProjectState: Replace LanguageServerFeatureOptions with enum
DustinCampbell Dec 12, 2024
eb5d916
Improve ProjectState.Create(...) factory methods and constructors
DustinCampbell Dec 12, 2024
ea3fd03
Clean up TestProjectEngineFactoryProvider a bit
DustinCampbell Dec 12, 2024
9042ae4
Seal DocumentState and ProjectState and make effectively immutable
DustinCampbell Dec 12, 2024
ee0e239
Rework ProjectState.ImportsToRelatedDocuments map
DustinCampbell Dec 13, 2024
3ba0eda
Simplify DocumentState.Version tracking
DustinCampbell Dec 16, 2024
fdf9486
Remove unused DocumentState property
DustinCampbell Dec 16, 2024
5b0bfb6
Clean up DocumentState With* methods
DustinCampbell Dec 16, 2024
8d376cc
Move DocumentState helper methods for computing imports
DustinCampbell Dec 16, 2024
4601b2d
Clean up EmptyTextLoader (currently only used by tests)
DustinCampbell Dec 16, 2024
e3a9a86
Replace DocumentState.EmptyLoader with EmptyTextLoader.Instance
DustinCampbell Dec 16, 2024
4d18137
Replace CreateEmptyTextLoader with EmptyTextLoader.Instance
DustinCampbell Dec 16, 2024
4c9becf
Clean up TestMocks.CreateTextLoader calls
DustinCampbell Dec 16, 2024
a3b25f8
Clean up calls to ProjectState.AddDocument with empty loaders
DustinCampbell Dec 16, 2024
18ad48f
Augment Assumed class with new helpers and message parameters
DustinCampbell Dec 16, 2024
ae4e86c
Introduce AsyncLazy<T> variation from Roslyn
DustinCampbell Dec 16, 2024
813e448
Introduce ITextAndVersionSource to manage text loading in DocumentState
DustinCampbell Dec 16, 2024
b508614
Don't update ProjectState when DocumentState doesn't
DustinCampbell Dec 16, 2024
1f9144f
Move DocumentState helper methods for compilation
DustinCampbell Dec 17, 2024
df3e21c
Remove DocumentState.ComputedStateTracker
DustinCampbell Dec 17, 2024
1e045ea
Introduce legacy snapshot interfaces to support legacy editor
DustinCampbell Dec 17, 2024
0049ac0
Remove IProjectSnapshot.Version
DustinCampbell Dec 17, 2024
b5acc30
Remove ProjectState.DocumentCollectionVersion
DustinCampbell Dec 17, 2024
f26bd81
Remove remaining version logic from ProjectState
DustinCampbell Dec 17, 2024
b341603
Make IProjectSnapshot.GetProjectEngine() async
DustinCampbell Dec 17, 2024
aafea13
Remove IProjectSnapshotManager interface
DustinCampbell Dec 18, 2024
c838a75
Remove IProjectSnapshot.GetProjectEngineAsync
DustinCampbell Dec 18, 2024
49a973c
Remove IProjectSnapshot.ProjectWorkspaceState
DustinCampbell Dec 18, 2024
04bf4bf
Move IDocumentSnapshot and IProjectSnapshot to lower tooling layer
DustinCampbell Dec 18, 2024
f27d768
Remove IProjectSnapshot.Configuration
DustinCampbell Dec 18, 2024
67e3227
Don't use LINQ Count() method
DustinCampbell Dec 18, 2024
295d482
Compute test span correctly
DustinCampbell Dec 18, 2024
74167ba
Double-checked lock
DustinCampbell Dec 18, 2024
670eae2
Fix comment
DustinCampbell Dec 18, 2024
f28f239
Remove unused method
DustinCampbell Dec 18, 2024
284c7d7
Rename method to ProjectState.UpdateRelatedDocumentsIfNecessary
DustinCampbell Dec 18, 2024
f952c9b
Delete unused ExtractToComponentResolverDocumentContextFactory
DustinCampbell Dec 18, 2024
1deb4a0
Remove all but one ProjectState.Create(...) factory method
DustinCampbell Dec 18, 2024
d35e121
RazorProjectService: Use TryGetDocument rather than pattern matching
DustinCampbell Dec 18, 2024
b51fabc
RazorProjectService: Rename for consistency throughout
DustinCampbell Dec 18, 2024
f3fed12
ProjectState: Don't perform string replacements unless necessary
DustinCampbell Dec 18, 2024
80709ba
Merge branch 'main' into cleanup-project-and-documentstate
DustinCampbell Jan 6, 2025
f9096fe
Move FORMAT_FUSE constant to Directory.Build.props
DustinCampbell Jan 6, 2025
4d299ee
Merge branch 'main' into cleanup-project-and-documentstate
DustinCampbell Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;

internal partial class DocumentState
internal sealed partial class DocumentState
{
private static readonly LoadTextOptions s_loadTextOptions = new(SourceHashAlgorithm.Sha256);

Expand Down Expand Up @@ -42,14 +42,7 @@ private DocumentState(
_textLoader = textLoader ?? EmptyLoader;
}

// Internal for testing
internal DocumentState(HostDocument hostDocument, int version, SourceText text, VersionStamp textVersion)
: this(hostDocument, version, TextAndVersion.Create(text, textVersion), textLoader: null)
{
}

// Internal for testing
internal DocumentState(HostDocument hostDocument, int version, TextLoader loader)
private DocumentState(HostDocument hostDocument, int version, TextLoader loader)
: this(hostDocument, version, textAndVersion: null, loader)
{
}
Expand Down Expand Up @@ -161,16 +154,13 @@ public bool TryGetTextVersion(out VersionStamp result)
return false;
}

public virtual DocumentState WithConfigurationChange()
public DocumentState WithConfigurationChange()
{
var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader);

// Do not cache computed state

return state;
return new(HostDocument, Version + 1, _textAndVersion, _textLoader);
}

public virtual DocumentState WithImportsChange()
public DocumentState WithImportsChange()
{
var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader);
DustinCampbell marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -180,7 +170,7 @@ public virtual DocumentState WithImportsChange()
return state;
}

public virtual DocumentState WithProjectWorkspaceStateChange()
public DocumentState WithProjectWorkspaceStateChange()
{
var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader);

Expand All @@ -190,18 +180,16 @@ public virtual DocumentState WithProjectWorkspaceStateChange()
return state;
}

public virtual DocumentState WithText(SourceText text, VersionStamp textVersion)
public DocumentState WithText(SourceText text, VersionStamp textVersion)
{
// Do not cache the computed state

return new DocumentState(HostDocument, Version + 1, TextAndVersion.Create(text, textVersion), textLoader: null);
return new(HostDocument, Version + 1, TextAndVersion.Create(text, textVersion), textLoader: null);
}

public virtual DocumentState WithTextLoader(TextLoader textLoader)
public DocumentState WithTextLoader(TextLoader textLoader)
{
// Do not cache the computed state

return new DocumentState(HostDocument, Version + 1, textAndVersion: null, textLoader);
return new(HostDocument, Version + 1, textAndVersion: null, textLoader);
}

internal static async Task<RazorCodeDocument> GenerateCodeDocumentAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;

// Internal tracker for DefaultProjectSnapshot
internal class ProjectState
internal sealed class ProjectState
{
private const ProjectDifference ClearConfigurationVersionMask = ProjectDifference.ConfigurationChanged;

Expand All @@ -41,6 +40,9 @@ internal class ProjectState
public RazorCompilerOptions CompilerOptions { get; }
public ProjectWorkspaceState ProjectWorkspaceState { get; }

public ImmutableDictionary<string, DocumentState> Documents { get; }
public ImmutableDictionary<string, ImmutableArray<string>> ImportsToRelatedDocuments { get; }

private readonly IProjectEngineFactoryProvider _projectEngineFactoryProvider;
private RazorProjectEngine? _projectEngine;

Expand Down Expand Up @@ -123,26 +125,28 @@ private ProjectState(

public static ProjectState Create(
HostProject hostProject,
ProjectWorkspaceState? projectWorkspaceState = null,
RazorCompilerOptions compilerOptions = RazorCompilerOptions.None,
IProjectEngineFactoryProvider? projectEngineFactoryProvider = null)
=> new(
hostProject,
projectWorkspaceState ?? ProjectWorkspaceState.Default,
compilerOptions,
projectEngineFactoryProvider ?? ProjectEngineFactories.DefaultProvider);
ProjectWorkspaceState projectWorkspaceState,
RazorCompilerOptions compilerOptions,
IProjectEngineFactoryProvider projectEngineFactoryProvider)
=> new(hostProject, projectWorkspaceState, compilerOptions, projectEngineFactoryProvider);

public static ProjectState Create(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState)
=> new(hostProject, projectWorkspaceState, RazorCompilerOptions.None, ProjectEngineFactories.DefaultProvider);

public static ProjectState Create(
HostProject hostProject,
RazorCompilerOptions compilerOptions,
IProjectEngineFactoryProvider? projectEngineFactoryProvider = null)
=> Create(hostProject, ProjectWorkspaceState.Default, compilerOptions, projectEngineFactoryProvider);
ProjectWorkspaceState projectWorkspaceState,
IProjectEngineFactoryProvider projectEngineFactoryProvider)
=> new(hostProject, projectWorkspaceState, RazorCompilerOptions.None, projectEngineFactoryProvider);

// Internal set for testing.
public ImmutableDictionary<string, DocumentState> Documents { get; internal set; }
public static ProjectState Create(
HostProject hostProject,
RazorCompilerOptions compilerOptions,
IProjectEngineFactoryProvider projectEngineFactoryProvider)
=> new(hostProject, ProjectWorkspaceState.Default, compilerOptions, projectEngineFactoryProvider);

// Internal set for testing.
public ImmutableDictionary<string, ImmutableArray<string>> ImportsToRelatedDocuments { get; internal set; }
public static ProjectState Create(HostProject hostProject)
=> new(hostProject, ProjectWorkspaceState.Default, RazorCompilerOptions.None, ProjectEngineFactories.DefaultProvider);

public ImmutableArray<TagHelperDescriptor> TagHelpers => ProjectWorkspaceState.TagHelpers;

Expand Down Expand Up @@ -198,6 +202,9 @@ RazorProjectEngine CreateProjectEngine()

public VersionStamp ConfigurationVersion { get; }

public ProjectState AddDocument(HostDocument hostDocument)
=> AddDocument(hostDocument, DocumentState.EmptyLoader);

public ProjectState AddDocument(HostDocument hostDocument, SourceText text)
{
ArgHelper.ThrowIfNull(hostDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static TestDocumentSnapshot Create(string filePath, string text, ProjectW
var sourceText = SourceText.From(text);
var textVersion = VersionStamp.Default;

var documentState = new DocumentState(hostDocument, version, sourceText, textVersion);
var documentState = DocumentState.Create(hostDocument, version, sourceText, textVersion);

return new TestDocumentSnapshot(project, documentState);
}
Expand All @@ -54,7 +54,7 @@ public static TestDocumentSnapshot Create(string filePath, RazorCodeDocument cod
var sourceText = codeDocument.Source.Text;
var textVersion = VersionStamp.Default;

var documentState = new DocumentState(hostDocument, version, sourceText, textVersion);
var documentState = DocumentState.Create(hostDocument, version, sourceText, textVersion);

return new TestDocumentSnapshot(project, documentState, codeDocument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private TestProjectSnapshot(ProjectState state)
public static TestProjectSnapshot Create(string filePath, ProjectWorkspaceState? projectWorkspaceState = null)
{
var hostProject = TestHostProject.Create(filePath);
var state = ProjectState.Create(hostProject, projectWorkspaceState);
var state = ProjectState.Create(hostProject, projectWorkspaceState ?? ProjectWorkspaceState.Default);

return new TestProjectSnapshot(state);
}
Expand Down
Loading