Skip to content

Commit e027f2e

Browse files
Make ISnapshotResolver.ResolveDocumentInAnyProject synchronous
1 parent 8b6e05b commit e027f2e

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ internal sealed class DocumentContextFactory(
9292
{
9393
if (projectContext is null)
9494
{
95-
return await _snapshotResolver
96-
.ResolveDocumentInAnyProjectAsync(filePath, cancellationToken)
97-
.ConfigureAwait(false);
95+
return _snapshotResolver.ResolveDocumentInAnyProject(filePath);
9896
}
9997

10098
if (_projectManager.TryGetLoadedProject(projectContext.ToProjectKey(), out var project) &&

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/ISnapshotResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ internal interface ISnapshotResolver
2323
/// Finds a <see cref="IDocumentSnapshot"/> for the given document path that is contained within any project, and returns the first
2424
/// one found if it does. This method should be avoided where possible, and the overload that takes a <see cref="ProjectKey"/> should be used instead
2525
/// </summary>
26-
Task<IDocumentSnapshot?> ResolveDocumentInAnyProjectAsync(string documentFilePath, CancellationToken cancellationToken);
26+
IDocumentSnapshot? ResolveDocumentInAnyProject(string documentFilePath);
2727
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ public async Task OpenDocumentAsync(string filePath, SourceText sourceText, int
123123
// We are okay to use the non-project-key overload of TryResolveDocument here because we really are just checking if the document
124124
// has been added to _any_ project. AddDocument will take care of adding to all of the necessary ones, and then below we ensure
125125
// we process them all too
126-
var document = await _snapshotResolver
127-
.ResolveDocumentInAnyProjectAsync(textDocumentPath, cancellationToken)
128-
.ConfigureAwait(false);
126+
var document = _snapshotResolver.ResolveDocumentInAnyProject(textDocumentPath);
129127

130128
if (document is null)
131129
{

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public IProjectSnapshot GetMiscellaneousProject()
7878
return _projectManager.GetLoadedProject(MiscellaneousHostProject.Key);
7979
}
8080

81-
public async Task<IDocumentSnapshot?> ResolveDocumentInAnyProjectAsync(string documentFilePath, CancellationToken cancellationToken)
81+
public IDocumentSnapshot? ResolveDocumentInAnyProject(string documentFilePath)
8282
{
8383
_logger.LogTrace($"Looking for {documentFilePath}.");
8484

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentContextFactoryTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ public ImmutableArray<IProjectSnapshot> FindPotentialProjects(string documentFil
217217
public IProjectSnapshot GetMiscellaneousProject()
218218
=> throw new NotImplementedException();
219219

220-
public Task<IDocumentSnapshot?> ResolveDocumentInAnyProjectAsync(string documentFilePath, CancellationToken cancellationToken)
220+
public IDocumentSnapshot? ResolveDocumentInAnyProject(string documentFilePath)
221221
=> documentFilePath == _documentSnapshot?.FilePath
222-
? Task.FromResult<IDocumentSnapshot?>(_documentSnapshot)
223-
: Task.FromResult<IDocumentSnapshot?>(null);
222+
? _documentSnapshot
223+
: null;
224224
}
225225
}

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SnapshotResolverTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task TryResolveDocumentInAnyProject_AsksPotentialParentProjectForDo
2424
var snapshotResolver = await CreateSnapshotResolverAsync(normalizedFilePath);
2525

2626
// Act
27-
var document = await snapshotResolver.ResolveDocumentInAnyProjectAsync(documentFilePath, DisposalToken);
27+
var document = snapshotResolver.ResolveDocumentInAnyProject(documentFilePath);
2828

2929
// Assert
3030
Assert.NotNull(document);
@@ -52,7 +52,7 @@ await projectManager.UpdateAsync(updater =>
5252
});
5353

5454
// Act
55-
var document = await snapshotResolver.ResolveDocumentInAnyProjectAsync(documentFilePath, DisposalToken);
55+
var document = snapshotResolver.ResolveDocumentInAnyProject(documentFilePath);
5656

5757
// Assert
5858
Assert.NotNull(document);
@@ -69,7 +69,7 @@ public async Task TryResolveDocumentInAnyProject_AsksPotentialParentProjectForDo
6969
await snapshotResolver.InitializeAsync(DisposalToken);
7070

7171
// Act
72-
var document = await snapshotResolver.ResolveDocumentInAnyProjectAsync(documentFilePath, DisposalToken);
72+
var document = snapshotResolver.ResolveDocumentInAnyProject(documentFilePath);
7373

7474
// Assert
7575
Assert.Null(document);

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestSnapshotResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public ImmutableArray<IProjectSnapshot> FindPotentialProjects(string documentFil
3838
public IProjectSnapshot GetMiscellaneousProject()
3939
=> _miscProject;
4040

41-
public Task<IDocumentSnapshot?> ResolveDocumentInAnyProjectAsync(string documentFilePath, CancellationToken cancellationToken)
42-
=> Task.FromResult<IDocumentSnapshot?>(null);
41+
public IDocumentSnapshot? ResolveDocumentInAnyProject(string documentFilePath)
42+
=> null;
4343
}

0 commit comments

Comments
 (0)