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

Remove IDocumentSnapshot.Project #9854

Closed

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Jan 24, 2024

Part of #9519

In trying to reduce the suface area of IProjectSnapshot for cohosting I ran into a problem of the somewhat circular dependency between document and project snapshots. eg, I want to split IProjectSnapshot into two types: IProjectSnapshot which has the minimum needed to reason about a project and its documents, and IProjectSnapshotThatCanCompileRazorFiles for the existing Razor project system, where the project snapshot also has to be able to produce generated code. Obviously that name is not final :)

The problem comes when someone asks a IProjectSnapshotThatCanCompileRazorFiles for any documents, they get back an IDocumentSnapshot, and if they pass that around and something wants to know about the project it came from, they just get an IProjectSnapshot and have potentially lost the extra information that it original came from. This could be solved via runtime validation, and that probably would work perfectly well, but in this case because cohosting is off-by-default and still very early in development, I wanted the reassurance that the compiler gives by making this a compile time check. This could also have been solved with generics via IDocumentSnapshot<TProject> but I can't imagine that would have ended well.

It turns out that there were very few spots that needed the project from the IDocumentSnapshot, and in every case the source of the document snapshot had the project snapshot right there and available too, so removing the property seemed the most straight forward way of resolving this. Other than some minor Moq annoyance (and who doesn't get annoyed at Moq every now and again) the changes here are pretty much just all plumbing, but looking commit-at-a-time might be a little clearer as to what is going on.

@davidwengier davidwengier requested a review from a team as a code owner January 24, 2024 04:37
Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

I'll be honest, I don't love this change. I understand what you're trying to do, but it doesn't feel right to me. It's a significant change in semantics to say that a document snapshot, which is supposed to be an immutable object that is part of the data that makes up a project snapshot, another immutable object, no longer knows what project snapshot that it came from. Something about this really doesn't sit right with me and the number of changes required to support it really smells fishy to me. Could we discuss this approach further before pushing it in?

{
ClearClosedDocumentsPublishedDiagnostics(PublishedRazorDiagnostics);
ClearClosedDocumentsPublishedDiagnostics(PublishedCSharpDiagnostics);
lock (PublishedCSharpDiagnostics)
Copy link
Member

Choose a reason for hiding this comment

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

Having nested locks at the same indent level with just one set of braces is pretty standard. However, if you'd rather indent the nested lock statement, please add braces for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is 100% not intentional, I just have a habit of pressing Ctrl+E, D a fair amount. Will fix up, thanks for catching it.

@davidwengier
Copy link
Contributor Author

Could we discuss this approach further before pushing it in?

of course!

@davidwengier davidwengier deleted the RemoveIDocumentSnapshotDotProject branch January 29, 2024 00:34
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.

2 participants