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

Conversation

DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Dec 18, 2024

There's a lot of code changes here

  • Remove IProjectSnapshotManger interface completely
  • Push IDocumentSnapshot and IProjectSnapshot down to MS.ANC.Razor.ProjectEngineHost
  • Split out ILegacyDocumentSnapshot and ILegacyProjectSnapshot to serve the needs of the legacy editor.
  • Prune IDocumentSnapshot and IProjectSnapshot and hide implementation details, such as Configuration, ProjectWorkspaceState and GetProjectEngine().
  • Remove ComputedStateTracker and stop weakly caching RazorCodeDocument on DocumentState.
  • Introduce a variation of AsyncLazy from Roslyn. (A key difference between this and the VS AsyncLazy is that it doesn't have a JTF dependency.)
  • Remove tricky version logic from ProjectState.
  • Clean up ProjectState and DocumentState API.

VS Insertion PR: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/599715

The Razor project/document state model only need two compiler options: ForceRuntimeCodeGeneration and UseRoslynTokenizer. So, using LanguageServerFeatureOptions directly within ProjectState is a bit overkill. This change introduces a new enum, RazorCompilerOptions, to track the two options that the project model needs to control Razor compilation.
This change cleans up the TestProjectEngineFactoryProvider to be a bit more usable.
There were a number of test hooks in DocumentState and ProjectState, such as settable properties and virtual methods. This change removes those test hooks by cleaning up and refactoring ProjectStateTest.
This change attempts to be a bit more efficient what updating the ImportsToRelatedDocuments map. In addition, related documents are now stored in ImmutableHashSets.
This change brings Roslyn's AsyncLazy<T> implementation to Razor, but removes the synchronous computation path, since Razor doesn't need it.
This change removes the DocumentState.ComputedTracker, and DocumentState no longer weakly caches it's generated RazorCodeDocument. In addition, IDocumentSnapshot.GetGeneratedOutputAsync(...) has been modified to remove the forceDesignTimeGeneratedOutput parameter and the remove project/document snapshot implementations now use Razor's Roslyn-based AsyncLazy.
This change adds ILegacyDocumentSnapshot and ILegacyProjectSnapshot to be used exclusively by the legacy editor. These provide synchronous methods that should *only* be used by the legacy editor.
This property isn't actually used outside of ProjectState.
This change fully removes the IProjectSnapshotManager interface. Components in the language server and VS client layers can import a ProjectSnapshotManager. ProjectSnapshotManager provides direct access to DocumentSnapshot and ProjectSnapshot, which implement IDocumentSnapshot and IProjectSnapshot.
Retrieving a RazorProjectEngine for a project snapshot is an implementation detail and doesn't need to be exposed on IProjectSnapshot.
ProjectWorkspaceState is an implementation detail and does not need to be exposed on IProjectSnapshot.
IDocumentSnapshot and IProjectSnapshot and now more fundamental and below in a lower layer of Razor tooling.
The RazorConfiguration of a project snapshot is an implementation detail and doesn't need to be exposed.
@DustinCampbell DustinCampbell marked this pull request as ready for review December 18, 2024 02:59
@DustinCampbell DustinCampbell requested review from a team as code owners December 18, 2024 02:59
Copy link
Contributor

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so awesome. I did have a few questions though, that are probably just me missing something or misunderstanding something.

@davidwengier
Copy link
Contributor

In my professional opinion, we can consider the integration tests to have passed. The one failing test, HtmlCodeActionsTests_RemoveTag_WithCSharpContent, is known to be flaky at times.

Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Most of this may seem scattered. I reviewed commit by commit since the UI for over 200 files wasn't working too well. Thanks for the detailed commit messages

ValueTask<RazorCodeDocument> GetGeneratedOutputAsync(
bool forceDesignTimeGeneratedOutput,
CancellationToken cancellationToken);
ValueTask<RazorCodeDocument> GetGeneratedOutputAsync(CancellationToken cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 should we take the time to change this to GetGeneratedDocumentAsync? 👀

Copy link
Member Author

@DustinCampbell DustinCampbell Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I have a whole series of renames coming soon. IDocumentSnapshot will become IRazorDocument, IProjectSnapshot will become IRazorProject.

To account for recent formatting changes in main, `IDesignTimeCodeGenerator` does not compile
if `FORMAT_FUSE` is defined.
Changes in this PR caused the number of projects needing to compile with FORMAT_FUSE from two to four. So, this change pushes FORMAT_FUSE into Directory.Build.props to avoid needing to update four project files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants