This commit is contained in:
Dustin Campbell 2024-06-06 16:41:18 -07:00
Родитель ecf6e10dc9
Коммит a94b7f36e5
12 изменённых файлов: 19 добавлений и 161 удалений

Просмотреть файл

@ -18,13 +18,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer;
internal sealed class DocumentContextFactory( internal sealed class DocumentContextFactory(
IProjectSnapshotManager projectManager, IProjectSnapshotManager projectManager,
ISnapshotResolver snapshotResolver,
IDocumentVersionCache documentVersionCache, IDocumentVersionCache documentVersionCache,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
: IDocumentContextFactory : IDocumentContextFactory
{ {
private readonly IProjectSnapshotManager _projectManager = projectManager; private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly ISnapshotResolver _snapshotResolver = snapshotResolver;
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache; private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<DocumentContextFactory>(); private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<DocumentContextFactory>();

Просмотреть файл

@ -210,7 +210,6 @@ internal static class IServiceCollectionExtensions
services.AddSingleton((services) => (IRazorStartupService)services.GetRequiredService<IDocumentVersionCache>()); services.AddSingleton((services) => (IRazorStartupService)services.GetRequiredService<IDocumentVersionCache>());
services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>(); services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
services.AddSingleton<ISnapshotResolver, SnapshotResolver>();
services.AddSingleton<IRazorProjectService, RazorProjectService>(); services.AddSingleton<IRazorProjectService, RazorProjectService>();
services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>(); services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>();
services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>(); services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>();

Просмотреть файл

@ -1,20 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal interface ISnapshotResolver
{
/// <summary>
/// Finds a <see cref="IDocumentSnapshot"/> for the given document path that is contained within any project, and returns the first
/// 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
/// </summary>
bool TryResolveDocumentInAnyProject(string documentFilePath, [NotNullWhen(true)] out IDocumentSnapshot? document);
}

Просмотреть файл

@ -25,7 +25,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal class RazorProjectService( internal class RazorProjectService(
RemoteTextLoaderFactory remoteTextLoaderFactory, RemoteTextLoaderFactory remoteTextLoaderFactory,
ISnapshotResolver snapshotResolver,
IDocumentVersionCache documentVersionCache, IDocumentVersionCache documentVersionCache,
IProjectSnapshotManager projectManager, IProjectSnapshotManager projectManager,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
@ -33,7 +32,6 @@ internal class RazorProjectService(
{ {
private readonly IProjectSnapshotManager _projectManager = projectManager; private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly RemoteTextLoaderFactory _remoteTextLoaderFactory = remoteTextLoaderFactory; private readonly RemoteTextLoaderFactory _remoteTextLoaderFactory = remoteTextLoaderFactory;
private readonly ISnapshotResolver _snapshotResolver = snapshotResolver;
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache; private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<RazorProjectService>(); private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<RazorProjectService>();

Просмотреть файл

@ -1,57 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CommonLanguageServerProtocol.Framework;
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal sealed class SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory loggerFactory) : ISnapshotResolver
{
private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<SnapshotResolver>();
public bool TryResolveDocumentInAnyProject(string documentFilePath, [NotNullWhen(true)] out IDocumentSnapshot? document)
{
_logger.LogTrace($"Looking for {documentFilePath}.");
var normalizedDocumentPath = FilePathNormalizer.Normalize(documentFilePath);
var potentialProjects = _projectManager.FindPotentialProjects(documentFilePath);
foreach (var project in potentialProjects)
{
if (project.GetDocument(normalizedDocumentPath) is { } projectDocument)
{
_logger.LogTrace($"Found {documentFilePath} in {project.FilePath}");
document = projectDocument;
return true;
}
}
_logger.LogTrace($"Looking for {documentFilePath} in miscellaneous project.");
var miscellaneousProject = _projectManager.GetMiscellaneousProject();
if (miscellaneousProject.GetDocument(normalizedDocumentPath) is { } miscDocument)
{
_logger.LogTrace($"Found {documentFilePath} in miscellaneous project.");
document = miscDocument;
return true;
}
_logger.LogTrace($"{documentFilePath} not found in {string.Join(", ", _projectManager.GetProjects().SelectMany(p => p.DocumentFilePaths))}");
document = null;
return false;
}
}

Просмотреть файл

@ -46,7 +46,6 @@ public class DefaultRazorComponentSearchEngineTest(ITestOutputHelper testOutput)
{ {
_projectManager = CreateProjectSnapshotManager(); _projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(_projectManager, LoggerFactory);
var documentVersionCache = new DocumentVersionCache(_projectManager); var documentVersionCache = new DocumentVersionCache(_projectManager);
var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>(); var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>();
@ -64,7 +63,6 @@ public class DefaultRazorComponentSearchEngineTest(ITestOutputHelper testOutput)
var projectService = new TestRazorProjectService( var projectService = new TestRazorProjectService(
remoteTextLoaderFactoryMock.Object, remoteTextLoaderFactoryMock.Object,
snapshotResolver,
documentVersionCache, documentVersionCache,
_projectManager, _projectManager,
LoggerFactory); LoggerFactory);

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See License.txt in the project root for license information. // Licensed under the MIT license. See License.txt in the project root for license information.
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language;
@ -38,9 +37,7 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
var filePath = FilePathNormalizer.Normalize(Path.Combine(s_baseDirectory, "file.cshtml")); var filePath = FilePathNormalizer.Normalize(Path.Combine(s_baseDirectory, "file.cshtml"));
var uri = new Uri(filePath); var uri = new Uri(filePath);
var snapshotResolver = new TestSnapshotResolver(); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory);
// Act // Act
Assert.False(factory.TryCreate(uri, out _)); Assert.False(factory.TryCreate(uri, out _));
@ -53,9 +50,7 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
var filePath = FilePathNormalizer.Normalize(Path.Combine(s_baseDirectory, "file.cshtml")); var filePath = FilePathNormalizer.Normalize(Path.Combine(s_baseDirectory, "file.cshtml"));
var uri = new Uri(filePath); var uri = new Uri(filePath);
var snapshotResolver = new TestSnapshotResolver(); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory);
// Act // Act
Assert.False(factory.TryCreateForOpenDocument(uri, out _)); Assert.False(factory.TryCreateForOpenDocument(uri, out _));
@ -75,8 +70,7 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
updater.DocumentAdded(MiscFilesHostProject.Instance.Key, hostDocument, CreateTextLoader(filePath, "")); updater.DocumentAdded(MiscFilesHostProject.Instance.Key, hostDocument, CreateTextLoader(filePath, ""));
}); });
var snapshotResolver = new TestSnapshotResolver(); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory);
// Act // Act
Assert.False(factory.TryCreateForOpenDocument(uri, out _)); Assert.False(factory.TryCreateForOpenDocument(uri, out _));
@ -100,8 +94,7 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
var documentSnapshot = miscFilesProject.GetDocument(filePath); var documentSnapshot = miscFilesProject.GetDocument(filePath);
Assert.NotNull(documentSnapshot); Assert.NotNull(documentSnapshot);
var snapshotResolver = new TestSnapshotResolver(); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory);
// Act // Act
Assert.True(factory.TryCreate(uri, out var documentContext)); Assert.True(factory.TryCreate(uri, out var documentContext));
@ -120,8 +113,7 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
var projectFilePath = Path.Combine(s_baseDirectory, "project.csproj"); var projectFilePath = Path.Combine(s_baseDirectory, "project.csproj");
var uri = new Uri(filePath); var uri = new Uri(filePath);
var snapshotResolver = new TestSnapshotResolver(); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory);
var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default, rootNamespace: null); var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default, rootNamespace: null);
var hostDocument = new HostDocument(filePath, "file.cshtml"); var hostDocument = new HostDocument(filePath, "file.cshtml");
@ -157,9 +149,8 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
var documentSnapshot = miscFilesProject.GetDocument(filePath); var documentSnapshot = miscFilesProject.GetDocument(filePath);
Assert.NotNull(documentSnapshot); Assert.NotNull(documentSnapshot);
var snapshotResolver = new TestSnapshotResolver();
_documentVersionCache.TrackDocumentVersion(documentSnapshot, version: 1337); _documentVersionCache.TrackDocumentVersion(documentSnapshot, version: 1337);
var factory = new DocumentContextFactory(_projectManager, snapshotResolver, _documentVersionCache, LoggerFactory); var factory = new DocumentContextFactory(_projectManager, _documentVersionCache, LoggerFactory);
// Act // Act
Assert.True(factory.TryCreateForOpenDocument(uri, out var documentContext)); Assert.True(factory.TryCreateForOpenDocument(uri, out var documentContext));
@ -169,21 +160,4 @@ public class DocumentContextFactoryTest : LanguageServerTestBase
Assert.Equal(uri, documentContext.Uri); Assert.Equal(uri, documentContext.Uri);
Assert.Same(documentSnapshot, documentContext.Snapshot); Assert.Same(documentSnapshot, documentContext.Snapshot);
} }
private sealed class TestSnapshotResolver(IDocumentSnapshot? documentSnapshot = null) : ISnapshotResolver
{
private readonly IDocumentSnapshot? _documentSnapshot = documentSnapshot;
public bool TryResolveDocumentInAnyProject(string documentFilePath, [NotNullWhen(true)] out IDocumentSnapshot? document)
{
if (documentFilePath == _documentSnapshot?.FilePath)
{
document = _documentSnapshot;
return true;
}
document = null;
return false;
}
}
} }

Просмотреть файл

@ -6,7 +6,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
@ -31,8 +30,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
// Arrange // Arrange
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj")); var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/MyTagHelper.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/MyTagHelper.razor");
@ -54,7 +51,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>"))); await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>")));
var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull(); var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull();
documentVersionCache.TrackDocumentVersion(documentSnapshot, 1); documentVersionCache.TrackDocumentVersion(documentSnapshot, 1);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory); var documentContextFactory = new DocumentContextFactory(projectManager, documentVersionCache, LoggerFactory);
Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext)); Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext));
var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict); var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict);
@ -95,8 +92,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
// Arrange // Arrange
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj")); var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/MyTagHelper.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/MyTagHelper.razor");
@ -118,7 +113,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>"))); await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>")));
var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull(); var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull();
documentVersionCache.TrackDocumentVersion(documentSnapshot, 1); documentVersionCache.TrackDocumentVersion(documentSnapshot, 1);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory); var documentContextFactory = new DocumentContextFactory(projectManager, documentVersionCache, LoggerFactory);
Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext)); Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext));
var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict); var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict);
@ -164,8 +159,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
// Arrange // Arrange
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj")); var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/fetchdata.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/fetchdata.razor");
@ -193,7 +186,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>"))); await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>")));
var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull(); var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull();
documentVersionCache.TrackDocumentVersion(documentSnapshot, 1); documentVersionCache.TrackDocumentVersion(documentSnapshot, 1);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory); var documentContextFactory = new DocumentContextFactory(projectManager, documentVersionCache, LoggerFactory);
Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext)); Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext));
var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict); var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict);
@ -395,8 +388,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
// Arrange // Arrange
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj")); var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/fetchdata.razor"); await projectManager.CreateAndAddDocumentAsync(project, "c:/path/fetchdata.razor");
@ -419,7 +410,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>"))); await projectManager.UpdateAsync(updater => updater.DocumentOpened(project.Key, razorFilePath, SourceText.From("<div></div>")));
var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull(); var documentSnapshot = projectManager.GetLoadedProject(project.Key).GetDocument(razorFilePath).AssumeNotNull();
documentVersionCache.TrackDocumentVersion(documentSnapshot, 1); documentVersionCache.TrackDocumentVersion(documentSnapshot, 1);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory); var documentContextFactory = new DocumentContextFactory(projectManager, documentVersionCache, LoggerFactory);
Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext)); Assert.True(documentContextFactory.TryCreateForOpenDocument(uri, null, out var documentContext));
var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict); var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict);

Просмотреть файл

@ -32,7 +32,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
// Each of these is initialized by InitializeAsync() below. // Each of these is initialized by InitializeAsync() below.
#nullable disable #nullable disable
private TestProjectSnapshotManager _projectManager; private TestProjectSnapshotManager _projectManager;
private SnapshotResolver _snapshotResolver;
private DocumentVersionCache _documentVersionCache; private DocumentVersionCache _documentVersionCache;
private TestRazorProjectService _projectService; private TestRazorProjectService _projectService;
#nullable enable #nullable enable
@ -42,7 +41,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
var optionsMonitor = TestRazorLSPOptionsMonitor.Create(); var optionsMonitor = TestRazorLSPOptionsMonitor.Create();
var projectEngineFactoryProvider = new LspProjectEngineFactoryProvider(optionsMonitor); var projectEngineFactoryProvider = new LspProjectEngineFactoryProvider(optionsMonitor);
_projectManager = CreateProjectSnapshotManager(projectEngineFactoryProvider); _projectManager = CreateProjectSnapshotManager(projectEngineFactoryProvider);
_snapshotResolver = new SnapshotResolver(_projectManager, LoggerFactory);
_documentVersionCache = new DocumentVersionCache(_projectManager); _documentVersionCache = new DocumentVersionCache(_projectManager);
var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>(); var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>();
@ -52,7 +50,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
_projectService = new TestRazorProjectService( _projectService = new TestRazorProjectService(
remoteTextLoaderFactoryMock.Object, remoteTextLoaderFactoryMock.Object,
_snapshotResolver,
_documentVersionCache, _documentVersionCache,
_projectManager, _projectManager,
LoggerFactory); LoggerFactory);
@ -681,8 +678,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken);
var miscProject = _projectManager.GetMiscellaneousProject();
using var listener = _projectManager.ListenToNotifications(); using var listener = _projectManager.ListenToNotifications();
// Act // Act
@ -863,8 +858,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
var ownerProjectKey = await _projectService.AddProjectAsync( var ownerProjectKey = await _projectService.AddProjectAsync(
ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken);
var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey);
using var listener = _projectManager.ListenToNotifications(); using var listener = _projectManager.ListenToNotifications();
// Act // Act
@ -880,8 +873,6 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
// Arrange // Arrange
const string DocumentFilePath = "document.cshtml"; const string DocumentFilePath = "document.cshtml";
var miscProject = _projectManager.GetMiscellaneousProject();
Assert.False(_projectManager.IsDocumentOpen(DocumentFilePath)); Assert.False(_projectManager.IsDocumentOpen(DocumentFilePath));
using var listener = _projectManager.ListenToNotifications(); using var listener = _projectManager.ListenToNotifications();

Просмотреть файл

@ -611,10 +611,8 @@ public class RenameEndpointTest(ITestOutputHelper testOutput) : LanguageServerTe
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var documentVersionCache = new DocumentVersionCache(projectManager); var documentVersionCache = new DocumentVersionCache(projectManager);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory); var documentContextFactory = new DocumentContextFactory(projectManager, documentVersionCache, LoggerFactory);
var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>(); var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>();
remoteTextLoaderFactoryMock remoteTextLoaderFactoryMock
@ -631,7 +629,6 @@ public class RenameEndpointTest(ITestOutputHelper testOutput) : LanguageServerTe
var projectService = new TestRazorProjectService( var projectService = new TestRazorProjectService(
remoteTextLoaderFactoryMock.Object, remoteTextLoaderFactoryMock.Object,
snapshotResolver,
documentVersionCache, documentVersionCache,
projectManager, projectManager,
LoggerFactory); LoggerFactory);

Просмотреть файл

@ -21,10 +21,10 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = @"C:\path\to\document.cshtml"; var documentFilePath = @"C:\path\to\document.cshtml";
var normalizedFilePath = "C:/path/to/document.cshtml"; var normalizedFilePath = "C:/path/to/document.cshtml";
var (snapshotResolver, _) = await CreateSnapshotResolverAsync(normalizedFilePath); var projectManager = await CreateProjectManagerAsync(normalizedFilePath);
// Act // Act
Assert.True(snapshotResolver.TryResolveDocumentInAnyProject(documentFilePath, out var document)); Assert.True(projectManager.TryResolveDocumentInAnyProject(documentFilePath, Logger, out var document));
// Assert // Assert
Assert.Equal(normalizedFilePath, document.FilePath); Assert.Equal(normalizedFilePath, document.FilePath);
@ -37,7 +37,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var documentFilePath = @"C:\path\to\document.cshtml"; var documentFilePath = @"C:\path\to\document.cshtml";
var normalizedFilePath = "C:/path/to/document.cshtml"; var normalizedFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await projectManager.UpdateAsync(updater => await projectManager.UpdateAsync(updater =>
{ {
@ -50,7 +49,7 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}); });
// Act // Act
Assert.True(snapshotResolver.TryResolveDocumentInAnyProject(documentFilePath, out var document)); Assert.True(projectManager.TryResolveDocumentInAnyProject(documentFilePath, Logger, out var document));
// Assert // Assert
Assert.Equal(normalizedFilePath, document.FilePath); Assert.Equal(normalizedFilePath, document.FilePath);
@ -62,10 +61,9 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = @"C:\path\to\document.cshtml"; var documentFilePath = @"C:\path\to\document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
// Act // Act
Assert.False(snapshotResolver.TryResolveDocumentInAnyProject(documentFilePath, out var document)); Assert.False(projectManager.TryResolveDocumentInAnyProject(documentFilePath, Logger, out var document));
// Assert // Assert
Assert.Null(document); Assert.Null(document);
@ -77,7 +75,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = "C:/path/to/document.cshtml"; var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
// Act // Act
Assert.False(projectManager.TryResolveAllProjects(documentFilePath, out _)); Assert.False(projectManager.TryResolveAllProjects(documentFilePath, out _));
@ -89,7 +86,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = "C:/path/to/document.cshtml"; var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
// Act // Act
Assert.False(projectManager.TryResolveAllProjects(documentFilePath, out _)); Assert.False(projectManager.TryResolveAllProjects(documentFilePath, out _));
@ -100,7 +96,7 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
{ {
// Arrange // Arrange
var documentFilePath = Path.Combine(MiscFilesHostProject.Instance.DirectoryPath, "document.cshtml"); var documentFilePath = Path.Combine(MiscFilesHostProject.Instance.DirectoryPath, "document.cshtml");
var (snapshotResolver, projectManager) = await CreateSnapshotResolverAsync(documentFilePath, addToMiscellaneous: true); var projectManager = await CreateProjectManagerAsync(documentFilePath, addToMiscellaneous: true);
// Act // Act
Assert.True(projectManager.TryResolveAllProjects(documentFilePath, out var projects)); Assert.True(projectManager.TryResolveAllProjects(documentFilePath, out var projects));
@ -116,7 +112,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = "C:/path/to/document.cshtml"; var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await projectManager.UpdateAsync(updater => await projectManager.UpdateAsync(updater =>
{ {
@ -134,8 +129,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var documentFilePath = "C:/path/to/document.cshtml"; var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var expectedProject = await projectManager.UpdateAsync(updater => var expectedProject = await projectManager.UpdateAsync(updater =>
{ {
var expectedProject = updater.CreateAndAddProject("C:/path/to/project.csproj"); var expectedProject = updater.CreateAndAddProject("C:/path/to/project.csproj");
@ -161,7 +154,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
documentFilePath = FilePathNormalizer.Normalize(documentFilePath); documentFilePath = FilePathNormalizer.Normalize(documentFilePath);
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var miscProject = await projectManager.UpdateAsync(updater => var miscProject = await projectManager.UpdateAsync(updater =>
{ {
@ -186,7 +178,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange // Arrange
var documentFilePath = "c:/path/to/document.cshtml"; var documentFilePath = "c:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
var ownerProject = await projectManager.UpdateAsync(updater => var ownerProject = await projectManager.UpdateAsync(updater =>
{ {
@ -232,12 +223,11 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
Assert.Equal(MiscFilesHostProject.Instance.FilePath, project.FilePath); Assert.Equal(MiscFilesHostProject.Instance.FilePath, project.FilePath);
} }
private async Task<(ISnapshotResolver, TestProjectSnapshotManager)> CreateSnapshotResolverAsync(string filePath, bool addToMiscellaneous = false) private async Task<TestProjectSnapshotManager> CreateProjectManagerAsync(string filePath, bool addToMiscellaneous = false)
{ {
filePath = FilePathNormalizer.Normalize(filePath); filePath = FilePathNormalizer.Normalize(filePath);
var projectManager = CreateProjectSnapshotManager(); var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
if (addToMiscellaneous) if (addToMiscellaneous)
{ {
@ -259,7 +249,7 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}); });
} }
return (snapshotResolver, projectManager); return projectManager;
} }
private static void AssertSnapshotsEqual(IProjectSnapshot first, IProjectSnapshot second) private static void AssertSnapshotsEqual(IProjectSnapshot first, IProjectSnapshot second)

Просмотреть файл

@ -17,11 +17,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal class TestRazorProjectService( internal class TestRazorProjectService(
RemoteTextLoaderFactory remoteTextLoaderFactory, RemoteTextLoaderFactory remoteTextLoaderFactory,
ISnapshotResolver snapshotResolver,
IDocumentVersionCache documentVersionCache, IDocumentVersionCache documentVersionCache,
IProjectSnapshotManager projectManager, IProjectSnapshotManager projectManager,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
: RazorProjectService(remoteTextLoaderFactory, snapshotResolver, documentVersionCache, projectManager, loggerFactory) : RazorProjectService(remoteTextLoaderFactory, documentVersionCache, projectManager, loggerFactory)
{ {
private readonly IProjectSnapshotManager _projectManager = projectManager; private readonly IProjectSnapshotManager _projectManager = projectManager;