Add MEF exported VS RazorProjectInfoManager

This commit is contained in:
Dustin Campbell 2024-05-31 11:39:49 -07:00
Родитель e8e85ebd15
Коммит 02c1f553d5
2 изменённых файлов: 63 добавлений и 0 удалений

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

@ -0,0 +1,62 @@
// 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.ComponentModel.Composition;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.VisualStudio.Razor.LanguageClient.ProjectSystem;
[Export(typeof(IRazorStartupService)]
[Export(typeof(IRazorProjectInfoPublisher))]
internal sealed class VisualStudioRazorProjectInfoPublisher : CodeAnalysis.Razor.ProjectSystem.RazorProjectInfoPublisher, IRazorStartupService
{
[ImportingConstructor]
public VisualStudioRazorProjectInfoPublisher(IProjectSnapshotManager projectManager)
: base()
{
projectManager.Changed += ProjectManager_Changed;
}
private void ProjectManager_Changed(object sender, ProjectChangeEventArgs e)
{
// Don't do any work if the solution is closing
if (e.SolutionIsClosing)
{
return;
}
switch (e.Kind)
{
case ProjectChangeKind.ProjectAdded:
case ProjectChangeKind.ProjectChanged:
case ProjectChangeKind.DocumentRemoved:
case ProjectChangeKind.DocumentAdded:
var newer = e.Newer.AssumeNotNull();
AddWork(newer.ToRazorProjectInfo());
break;
case ProjectChangeKind.ProjectRemoved:
var older = e.Older.AssumeNotNull();
AddWork(new RazorProjectInfo(
older.Key,
older.FilePath,
configuration: FallbackRazorConfiguration.Latest,
rootNamespace: null,
displayName: "",
projectWorkspaceState: ProjectWorkspaceState.Default,
documents: []));
break;
case ProjectChangeKind.DocumentChanged:
break;
default:
throw new NotSupportedException($"Unsupported {nameof(ProjectChangeKind)}: {e.Kind}");
}
}
}

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

@ -37,6 +37,7 @@ internal class RazorLanguageServerClient(
LSPRequestInvoker requestInvoker,
ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
RazorProjectInfoEndpointPublisher projectInfoEndpointPublisher,
IRazorProjectInfoPublisher projectInfoManager,
ILoggerFactory loggerFactory,
RazorLogHubTraceProvider traceProvider,
LanguageServerFeatureOptions languageServerFeatureOptions,