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
Add and fix nullability annotations in Microsoft.CodeAnalysis.Razor.Workspaces #8115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MOAR PATTERNS!
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/BackgroundDocumentGenerator.cs
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs
Outdated
Show resolved
Hide resolved
...r/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultImportDocumentSnapshot.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/EphemeralProjectSnapshot.cs
Outdated
Show resolved
Hide resolved
2e01990
to
25745dd
Compare
25745dd
to
739e344
Compare
63688e8
to
a25548d
Compare
a25548d
to
d56debd
Compare
b77e326
to
78b6760
Compare
78b6760
to
e5db5d5
Compare
src/Razor/src/Microsoft.AspNetCore.Razor.Common/NullableExtensions.cs
Outdated
Show resolved
Hide resolved
private class DefaultElementCompletionResult : ElementCompletionResult | ||
{ | ||
private readonly IReadOnlyDictionary<string, IEnumerable<TagHelperDescriptor>> _completions; | ||
var readonlyCompletions = new Dictionary<string, IEnumerable<TagHelperDescriptor>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the second method I've seen that converts a dictionary from something to something very very similar. I have nothing but questions, but I don't expect you to answer them. In fact, I admire your restraint in leaving them here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I tried to remove them but then I saw that this is public and used by Web Tools. So, I left it mostly in place and just removed the gratuitous inheritance.
@@ -384,12 +393,16 @@ private void UpdateProjectDocuments(IReadOnlyList<DocumentSnapshotHandle> docume | |||
} | |||
} | |||
|
|||
private void MoveDocument(string documentFilePath, DefaultProjectSnapshot fromProject, DefaultProjectSnapshot toProject) | |||
private void MoveDocument(string documentFilePath, ProjectSnapshot fromProject, ProjectSnapshot toProject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if this makes more sense as IProjectSnapshot
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might, but understanding the impact of that is a bit beyond the scope of this PR. This change is just the result of a rename.
Task<RazorCodeDocument> GetGeneratedOutputAsync(); | ||
|
||
bool TryGetText([NotNullWhen(true)] out SourceText? result); | ||
bool TryGetTextVersion(out VersionStamp result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we fail to get the VersionStamp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's default
. This is a struct, not a reference type, and it's not necessary to lift structs to nullable value types in TryGet
methods.
Thanks very much for the reviews! |
Fixes #7945
This starts the work of updating
Microsoft.CodeAnalysis.Razor.Workspaces
with nullable annotations, making some largish refactorings, and generally cleaning up.Here are a few highlights:
AssumesNotNull()
extension methods that can be used to verify that an expression is non-null. This is similar to theAssume.NotNull(...)
methods from theMicrosoft.VisualStudio.Validation
library. The advantage to the extension method forms is that they can be used at an expression level, which makes them simpler to use thanAssume.NotNull(...)
, which often requires requiring expressions into statements in order to validate.DocumentSnapshot
to an interface:IDocumentSnapshot
. The oldDefaultDocumentSnapshot
has been renamed toDocumentSnapshot
.ProjectSnapshot
to an interface:IProjectSnapshot
. The oldDefaultProjectSnapshot
has been renamed toProjectSnapshot
.ErrorReporter
to an interface:IErrorReporter
. The oldDefaultErrorReporter
has been renamed toErrorReporter
. In addition, I've updated the test infrastructure and all tests to use a test-onlyIErrorReporter
that logs exceptions to the test output.There is more to come, but this PR is already large enough, so I'm submitting it for review.