Create `LspProjectSnapshotManager` with misc files project baked in

Update `ProjectSnapshotManger` to take an optional delegate that can be used to populate the initial set of projects and documents in the constructor. In the language server, this is used to add the miscellaneous files project.
This commit is contained in:
Dustin Campbell 2024-06-06 15:12:53 -07:00
Родитель ed752fd8e3
Коммит 72b93ffd5f
12 изменённых файлов: 128 добавлений и 78 удалений

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

@ -211,7 +211,6 @@ internal static class IServiceCollectionExtensions
services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
services.AddSingleton<ISnapshotResolver, SnapshotResolver>();
services.AddSingleton<IOnInitialized>(sp => (SnapshotResolver)sp.GetRequiredService<ISnapshotResolver>());
services.AddSingleton<IRazorProjectService, RazorProjectService>();
services.AddSingleton<IRazorStartupService, OpenDocumentGenerator>();
services.AddSingleton<IRazorDocumentMappingService, RazorDocumentMappingService>();
@ -256,7 +255,7 @@ internal static class IServiceCollectionExtensions
// Add project snapshot manager
services.AddSingleton<IProjectEngineFactoryProvider, LspProjectEngineFactoryProvider>();
services.AddSingleton<IProjectSnapshotManager, ProjectSnapshotManager>();
services.AddSingleton<IProjectSnapshotManager, LspProjectSnapshotManager>();
}
public static void AddHandlerWithCapabilities<T>(this IServiceCollection services)

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

@ -0,0 +1,24 @@
// 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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectEngineHost;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal class LspProjectSnapshotManager(
IProjectEngineFactoryProvider projectEngineFactoryProvider,
ILoggerFactory loggerFactory)
: ProjectSnapshotManager(projectEngineFactoryProvider, loggerFactory, initializer: AddMiscFilesProject)
{
private static void AddMiscFilesProject(Updater updater)
{
updater.ProjectAdded(MiscFilesHostProject.Instance);
}
}

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

@ -17,26 +17,10 @@ using Microsoft.CommonLanguageServerProtocol.Framework;
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
internal sealed class SnapshotResolver : ISnapshotResolver, IOnInitialized
internal sealed class SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory loggerFactory) : ISnapshotResolver
{
private readonly IProjectSnapshotManager _projectManager;
private readonly ILogger _logger;
public SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory loggerFactory)
{
_projectManager = projectManager;
_logger = loggerFactory.GetOrCreateLogger<SnapshotResolver>();
}
public Task OnInitializedAsync(ILspServices services, CancellationToken cancellationToken)
{
// This is called when the language server is initialized.
return _projectManager.UpdateAsync(
(updater, miscHostProject) => updater.ProjectAdded(miscHostProject),
state: MiscFilesHostProject.Instance,
cancellationToken);
}
private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<SnapshotResolver>();
/// <inheritdoc/>
public ImmutableArray<IProjectSnapshot> FindPotentialProjects(string documentFilePath)

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

@ -24,15 +24,13 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;
// (language version, extensions, named configuration).
//
// The implementation will create a ProjectSnapshot for each HostProject.
internal partial class ProjectSnapshotManager(
IProjectEngineFactoryProvider projectEngineFactoryProvider,
ILoggerFactory loggerFactory)
: IProjectSnapshotManager, IDisposable
internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDisposable
{
private static readonly LoadTextOptions s_loadTextOptions = new(SourceHashAlgorithm.Sha256);
private readonly IProjectEngineFactoryProvider _projectEngineFactoryProvider = projectEngineFactoryProvider;
private readonly Dispatcher _dispatcher = new(loggerFactory);
private readonly IProjectEngineFactoryProvider _projectEngineFactoryProvider;
private readonly Dispatcher _dispatcher;
private readonly bool _initialized;
public event EventHandler<ProjectChangeEventArgs>? PriorityChanged;
public event EventHandler<ProjectChangeEventArgs>? Changed;
@ -63,6 +61,28 @@ internal partial class ProjectSnapshotManager(
// we want to make sure the "add" finishes running first before "open" is notified.
private readonly Queue<ProjectChangeEventArgs> _notificationQueue = new();
/// <summary>
/// Constructs an instance of <see cref="ProjectSnapshotManager"/>.
/// </summary>
/// <param name="projectEngineFactoryProvider">The <see cref="IProjectEngineFactoryProvider"/> to
/// use when creating <see cref="ProjectState"/>.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> to use.</param>
/// <param name="initializer">An optional callback to set up the initial set of projects and documents.
/// Note that this is called during construction, so it does not run on the dispatcher and notifications
/// will not be sent.</param>
public ProjectSnapshotManager(
IProjectEngineFactoryProvider projectEngineFactoryProvider,
ILoggerFactory loggerFactory,
Action<Updater>? initializer = null)
{
_projectEngineFactoryProvider = projectEngineFactoryProvider;
_dispatcher = new(loggerFactory);
initializer?.Invoke(new(this));
_initialized = true;
}
public void Dispose()
{
_dispatcher.Dispose();
@ -159,7 +179,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentAdded(ProjectKey projectKey, HostDocument document, TextLoader textLoader)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -174,7 +197,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentRemoved(ProjectKey projectKey, HostDocument document)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -189,7 +215,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentOpened(ProjectKey projectKey, string documentFilePath, SourceText sourceText)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -204,7 +233,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentClosed(ProjectKey projectKey, string documentFilePath, TextLoader textLoader)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -219,7 +251,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentChanged(ProjectKey projectKey, string documentFilePath, SourceText sourceText)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -234,7 +269,10 @@ internal partial class ProjectSnapshotManager(
private void DocumentChanged(ProjectKey projectKey, string documentFilePath, TextLoader textLoader)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -249,7 +287,10 @@ internal partial class ProjectSnapshotManager(
private void ProjectAdded(HostProject hostProject)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
hostProject.Key,
@ -264,7 +305,10 @@ internal partial class ProjectSnapshotManager(
private void ProjectConfigurationChanged(HostProject hostProject)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
hostProject.Key,
@ -279,7 +323,10 @@ internal partial class ProjectSnapshotManager(
private void ProjectWorkspaceStateChanged(ProjectKey projectKey, ProjectWorkspaceState projectWorkspaceState)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -294,7 +341,10 @@ internal partial class ProjectSnapshotManager(
private void ProjectRemoved(ProjectKey projectKey)
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
if (TryUpdate(
projectKey,
@ -309,7 +359,10 @@ internal partial class ProjectSnapshotManager(
private void SolutionOpened()
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
using (_readerWriterLock.DisposableWrite())
{
@ -319,7 +372,10 @@ internal partial class ProjectSnapshotManager(
private void SolutionClosed()
{
_dispatcher.AssertRunningOnDispatcher();
if (_initialized)
{
_dispatcher.AssertRunningOnDispatcher();
}
using (_readerWriterLock.DisposableWrite())
{
@ -329,6 +385,11 @@ internal partial class ProjectSnapshotManager(
private void NotifyListeners(IProjectSnapshot? older, IProjectSnapshot? newer, string? documentFilePath, ProjectChangeKind kind)
{
if (!_initialized)
{
return;
}
_notificationQueue.Enqueue(new ProjectChangeEventArgs(older, newer, documentFilePath, kind, IsSolutionClosing));
if (_notificationQueue.Count == 1)

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

@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Moq;
using Xunit;
using Xunit.Abstractions;
@ -48,7 +47,6 @@ public class DefaultRazorComponentSearchEngineTest(ITestOutputHelper testOutput)
_projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(_projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var documentVersionCache = new DocumentVersionCache(_projectManager);
var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>();

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

@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
@ -16,8 +15,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentPresentation;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.Copilot;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using Xunit;
@ -35,7 +32,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
@ -100,7 +96,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
@ -170,7 +165,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");
@ -402,7 +396,6 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var project = await projectManager.UpdateAsync(updater => updater.CreateAndAddProject("c:/path/project.csproj"));
await projectManager.CreateAndAddDocumentAsync(project, "c:/path/index.razor");

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

@ -18,7 +18,6 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Moq;
using Xunit;
using Xunit.Abstractions;
@ -38,13 +37,12 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
private TestRazorProjectService _projectService;
#nullable enable
protected override async Task InitializeAsync()
protected override Task InitializeAsync()
{
var optionsMonitor = TestRazorLSPOptionsMonitor.Create();
var projectEngineFactoryProvider = new LspProjectEngineFactoryProvider(optionsMonitor);
_projectManager = CreateProjectSnapshotManager(projectEngineFactoryProvider);
_snapshotResolver = new SnapshotResolver(_projectManager, LoggerFactory);
await _snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
_documentVersionCache = new DocumentVersionCache(_projectManager);
var remoteTextLoaderFactoryMock = new StrictMock<RemoteTextLoaderFactory>();
@ -58,6 +56,8 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer
_documentVersionCache,
_projectManager,
LoggerFactory);
return Task.CompletedTask;
}
[Fact]

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

@ -24,7 +24,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using Xunit;
@ -613,7 +612,6 @@ public class RenameEndpointTest(ITestOutputHelper testOutput) : LanguageServerTe
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var documentVersionCache = new DocumentVersionCache(projectManager);
var documentContextFactory = new DocumentContextFactory(projectManager, snapshotResolver, documentVersionCache, LoggerFactory);

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

@ -4,12 +4,10 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Xunit;
using Xunit.Abstractions;
@ -40,7 +38,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var normalizedFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
await projectManager.UpdateAsync(updater =>
{
@ -60,13 +57,12 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}
[Fact]
public async Task TryResolveDocumentInAnyProject_AsksPotentialParentProjectForDocumentItsNotTrackingAndMiscellaneousProjectIsNotTrackingEither_ReturnsFalse()
public void TryResolveDocumentInAnyProject_AsksPotentialParentProjectForDocumentItsNotTrackingAndMiscellaneousProjectIsNotTrackingEither_ReturnsFalse()
{
// Arrange
var documentFilePath = @"C:\path\to\document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
Assert.False(snapshotResolver.TryResolveDocumentInAnyProject(documentFilePath, out var document));
@ -76,26 +72,24 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}
[Fact]
public async Task TryResolveAllProjects_NoProjects_ReturnsFalse()
public void TryResolveAllProjects_NoProjects_ReturnsFalse()
{
// Arrange
var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
Assert.False(snapshotResolver.TryResolveAllProjects(documentFilePath, out _));
}
[Fact]
public async Task TryResolveAllProjects_OnlyMiscellaneousProjectDoesNotContainDocument_ReturnsFalse()
public void TryResolveAllProjects_OnlyMiscellaneousProjectDoesNotContainDocument_ReturnsFalse()
{
// Arrange
var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
Assert.False(snapshotResolver.TryResolveAllProjects(documentFilePath, out _));
@ -107,7 +101,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
// Arrange
var documentFilePath = Path.Combine(MiscFilesHostProject.Instance.DirectoryPath, "document.cshtml");
var snapshotResolver = await CreateSnapshotResolverAsync(documentFilePath, addToMiscellaneous: true);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
Assert.True(snapshotResolver.TryResolveAllProjects(documentFilePath, out var projects));
@ -124,7 +117,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var documentFilePath = "C:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
await projectManager.UpdateAsync(updater =>
{
@ -143,7 +135,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var expectedProject = await projectManager.UpdateAsync(updater =>
{
@ -171,7 +162,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var miscProject = await projectManager.UpdateAsync(updater =>
{
@ -197,7 +187,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var documentFilePath = "c:/path/to/document.cshtml";
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
var ownerProject = await projectManager.UpdateAsync(updater =>
{
@ -216,12 +205,11 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}
[Fact]
public async Task GetMiscellaneousProject_ProjectLoaded_ReturnsExistingProject()
public void GetMiscellaneousProject_ProjectLoaded_ReturnsExistingProject()
{
// Arrange
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
var project = snapshotResolver.GetMiscellaneousProject();
@ -232,12 +220,11 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
}
[Fact]
public async Task GetMiscellaneousProject_ProjectNotLoaded_CreatesProjectAndReturnsCreatedProject()
public void GetMiscellaneousProject_ProjectNotLoaded_CreatesProjectAndReturnsCreatedProject()
{
// Arrange
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
// Act
var project = snapshotResolver.GetMiscellaneousProject();
@ -253,7 +240,6 @@ public class SnapshotResolverTest(ITestOutputHelper testOutput) : LanguageServer
var projectManager = CreateProjectSnapshotManager();
var snapshotResolver = new SnapshotResolver(projectManager, LoggerFactory);
await snapshotResolver.OnInitializedAsync(StrictMock.Of<ILspServices>(), DisposalToken);
if (addToMiscellaneous)
{

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

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.AspNetCore.Razor.ProjectEngineHost;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
@ -50,8 +51,13 @@ public abstract class LanguageServerTestBase : ToolingTestBase
private protected TestProjectSnapshotManager CreateProjectSnapshotManager()
=> CreateProjectSnapshotManager(ProjectEngineFactories.DefaultProvider);
private protected TestProjectSnapshotManager CreateProjectSnapshotManager(IProjectEngineFactoryProvider projectEngineFactoryProvider)
=> new(projectEngineFactoryProvider, LoggerFactory, DisposalToken);
private protected TestProjectSnapshotManager CreateProjectSnapshotManager(
IProjectEngineFactoryProvider projectEngineFactoryProvider)
=> new(
projectEngineFactoryProvider,
LoggerFactory,
DisposalToken,
initializer: static updater => updater.ProjectAdded(MiscFilesHostProject.Instance));
internal RazorRequestContext CreateRazorRequestContext(VersionedDocumentContext? documentContext, ILspServices? lspServices = null)
{

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

@ -14,8 +14,9 @@ namespace Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
internal partial class TestProjectSnapshotManager(
IProjectEngineFactoryProvider projectEngineFactoryProvider,
ILoggerFactory loggerFactory,
CancellationToken disposalToken)
: ProjectSnapshotManager(projectEngineFactoryProvider, loggerFactory)
CancellationToken disposalToken,
Action<ProjectSnapshotManager.Updater>? initializer = null)
: ProjectSnapshotManager(projectEngineFactoryProvider, loggerFactory, initializer)
{
private readonly CancellationToken _disposalToken = disposalToken;

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

@ -8,8 +8,8 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common.VisualStudio;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
@ -20,7 +20,7 @@ using Xunit.Sdk;
namespace Microsoft.VisualStudio.Razor.LanguageClient;
public class RazorProjectInfoPublisherTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
public class RazorProjectInfoPublisherTest(ITestOutputHelper testOutput) : VisualStudioWorkspaceTestBase(testOutput)
{
[Fact]
[WorkItem("https://github.com/dotnet/aspnetcore/issues/35945")]