Skip to content

Commit df548d6

Browse files
Remove ImportDocumentSnapshot and (finally) fix nullability annotations on IDocumentSnapshot (#11184)
Commit-by-commit is the way. 😄
2 parents 121b129 + b31ace0 commit df548d6

File tree

29 files changed

+130
-214
lines changed

29 files changed

+130
-214
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeDocumentReferenceHolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void DocumentProcessed(RazorCodeDocument codeDocument, IDocumentSnapshot
3030
// multiple parses/regenerations across LSP requests that are all for the same document version.
3131
lock (_codeDocumentCache)
3232
{
33-
var key = new DocumentKey(documentSnapshot.Project.Key, documentSnapshot.FilePath.AssumeNotNull());
33+
var key = new DocumentKey(documentSnapshot.Project.Key, documentSnapshot.FilePath);
3434
_codeDocumentCache[key] = codeDocument;
3535
}
3636
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.Comparer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public bool Equals(IDocumentSnapshot? x, IDocumentSnapshot? y)
2626
}
2727

2828
public int GetHashCode(IDocumentSnapshot obj)
29-
{
30-
var filePath = obj.FilePath.AssumeNotNull();
31-
return FilePathComparer.Instance.GetHashCode(filePath);
32-
}
29+
=> FilePathComparer.Instance.GetHashCode(obj.FilePath);
3330
}
3431
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private async Task PublishDiagnosticsAsync(IDocumentSnapshot document, Cancellat
121121

122122
lock (_publishedDiagnostics)
123123
{
124-
var filePath = document.FilePath.AssumeNotNull();
124+
var filePath = document.FilePath;
125125

126126
// See if these are the same diagnostics as last time. If so, we don't need to publish.
127127
if (_publishedDiagnostics.TryGetValue(filePath, out var previousDiagnostics))

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentSynchronizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ internal class GeneratedDocumentSynchronizer(
1919
public void DocumentProcessed(RazorCodeDocument codeDocument, IDocumentSnapshot document)
2020
{
2121
var hostDocumentVersion = document.Version;
22-
var filePath = document.FilePath.AssumeNotNull();
22+
var filePath = document.FilePath;
2323

2424
// If the document isn't open, and we're not updating buffers for closed documents, then we don't need to do anything.
25-
if (!_projectManager.IsDocumentOpen(document.FilePath) &&
25+
if (!_projectManager.IsDocumentOpen(filePath) &&
2626
!_languageServerFeatureOptions.UpdateBuffersForClosedDocuments)
2727
{
2828
return;
2929
}
3030

3131
// If the document has been removed from the project, then don't do anything, or version numbers will be thrown off
3232
if (!_projectManager.TryGetLoadedProject(document.Project.Key, out var project) ||
33-
!project.ContainsDocument(document.FilePath))
33+
!project.ContainsDocument(filePath))
3434
{
3535
return;
3636
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.Comparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public int GetHashCode(IDocumentSnapshot obj)
3737
{
3838
var hash = HashCodeCombiner.Start();
3939
hash.Add(obj.Project.Key.Id, FilePathComparer.Instance);
40-
hash.Add(obj.FileKind.AssumeNotNull(), FilePathComparer.Instance);
40+
hash.Add(obj.FileKind, FilePathComparer.Instance);
4141
return hash.CombinedHash;
4242
}
4343
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private void ProjectManager_Changed(object? sender, ProjectChangeEventArgs args)
148148
{
149149
foreach (var relatedDocument in oldProject.GetRelatedDocuments(document))
150150
{
151-
var relatedDocumentFilePath = relatedDocument.FilePath.AssumeNotNull();
151+
var relatedDocumentFilePath = relatedDocument.FilePath;
152152

153153
if (newProject.TryGetDocument(relatedDocumentFilePath, out var newRelatedDocument))
154154
{
@@ -169,7 +169,7 @@ private void ProjectManager_Changed(object? sender, ProjectChangeEventArgs args)
169169

170170
void EnqueueIfNecessary(IDocumentSnapshot document)
171171
{
172-
if (!_projectManager.IsDocumentOpen(document.FilePath.AssumeNotNull()) &&
172+
if (!_projectManager.IsDocumentOpen(document.FilePath) &&
173173
!_options.UpdateBuffersForClosedDocuments)
174174
{
175175
return;

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/GoToDefinition/AbstractRazorComponentDefinitionService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Threading;
55
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Razor;
76
using Microsoft.AspNetCore.Razor.Language;
87
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
98
using Microsoft.CodeAnalysis.Razor.Logging;
@@ -62,7 +61,7 @@ internal abstract class AbstractRazorComponentDefinitionService(
6261
return null;
6362
}
6463

65-
var componentFilePath = componentDocument.FilePath.AssumeNotNull();
64+
var componentFilePath = componentDocument.FilePath;
6665

6766
_logger.LogInformation($"Definition found at file path: {componentFilePath}");
6867

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal class DocumentContext(Uri uri, IDocumentSnapshot snapshot, VSProjectCon
2323

2424
public Uri Uri { get; } = uri;
2525
public IDocumentSnapshot Snapshot { get; } = snapshot;
26-
public string FilePath => Snapshot.FilePath.AssumeNotNull();
27-
public string FileKind => Snapshot.FileKind.AssumeNotNull();
26+
public string FilePath => Snapshot.FilePath;
27+
public string FileKind => Snapshot.FileKind;
2828
public IProjectSnapshot Project => Snapshot.Project;
2929

3030
public TextDocumentIdentifier GetTextDocumentIdentifier()

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentSnapshot.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,8 @@ public async ValueTask<RazorCodeDocument> GetGeneratedOutputAsync(bool forceDesi
8282
return output;
8383
}
8484

85-
private async Task<RazorCodeDocument> GetDesignTimeGeneratedOutputAsync(CancellationToken cancellationToken)
86-
{
87-
var tagHelpers = await Project.GetTagHelpersAsync(cancellationToken).ConfigureAwait(false);
88-
var projectEngine = Project.GetProjectEngine();
89-
var imports = await DocumentState.GetImportsAsync(this, projectEngine, cancellationToken).ConfigureAwait(false);
90-
return await DocumentState
91-
.GenerateCodeDocumentAsync(this, projectEngine, imports, tagHelpers, forceRuntimeCodeGeneration: false, cancellationToken)
92-
.ConfigureAwait(false);
93-
}
85+
private Task<RazorCodeDocument> GetDesignTimeGeneratedOutputAsync(CancellationToken cancellationToken)
86+
=> DocumentState.GenerateCodeDocumentAsync(this, Project.GetProjectEngine(), forceRuntimeCodeGeneration: false, cancellationToken);
9487

9588
/// <summary>
9689
/// Retrieves a cached Roslyn <see cref="SyntaxTree"/> from the generated C# document.

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.ComputedStateTracker.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static void PropagateToTaskCompletionSource(
186186
var configurationVersion = project.ConfigurationVersion;
187187
var projectWorkspaceStateVersion = project.ProjectWorkspaceStateVersion;
188188
var documentCollectionVersion = project.DocumentCollectionVersion;
189-
var imports = await GetImportsAsync(document, project.GetProjectEngine(), cancellationToken).ConfigureAwait(false);
189+
var importItems = await GetImportItemsAsync(document, project.GetProjectEngine(), cancellationToken).ConfigureAwait(false);
190190
var documentVersion = await document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
191191

192192
// OK now that have the previous output and all of the versions, we can see if anything
@@ -207,7 +207,7 @@ static void PropagateToTaskCompletionSource(
207207
inputVersion = documentCollectionVersion;
208208
}
209209

210-
foreach (var import in imports)
210+
foreach (var import in importItems)
211211
{
212212
var importVersion = import.Version;
213213
if (inputVersion.GetNewerVersion(importVersion) == importVersion)
@@ -232,9 +232,8 @@ static void PropagateToTaskCompletionSource(
232232
}
233233
}
234234

235-
var tagHelpers = await project.GetTagHelpersAsync(cancellationToken).ConfigureAwait(false);
236235
var forceRuntimeCodeGeneration = project.LanguageServerFeatureOptions.ForceRuntimeCodeGeneration;
237-
var codeDocument = await GenerateCodeDocumentAsync(document, project.GetProjectEngine(), imports, tagHelpers, forceRuntimeCodeGeneration, cancellationToken).ConfigureAwait(false);
236+
var codeDocument = await GenerateCodeDocumentAsync(document, project.GetProjectEngine(), importItems, forceRuntimeCodeGeneration, cancellationToken).ConfigureAwait(false);
238237
return (codeDocument, inputVersion);
239238
}
240239

0 commit comments

Comments
 (0)