/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/WorkspaceProjectFactoryService.cs
69 строк
3 KB
David Barbet
Convert language server project/workspace creation stack into LSP services
28 май 2026, 20:24
28 май 2026, 20:24
dd8e404
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.LanguageServer.Telemetry; using Microsoft.CodeAnalysis.Remote.ProjectSystem; using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; /// <summary> /// An implementation of the brokered service <see cref="IWorkspaceProjectFactoryService"/> that just maps calls to the underlying project system. /// </summary> internal sealed class WorkspaceProjectFactoryService( LanguageServerWorkspaceFactory workspaceFactory, ProjectTargetFrameworkManager targetFrameworkManager, ProjectInitializationHandler projectInitializationHandler, ILoggerFactory loggerFactory) : IWorkspaceProjectFactoryService { private readonly LanguageServerWorkspaceFactory _workspaceFactory = workspaceFactory; private readonly ProjectInitializationHandler _projectInitializationHandler = projectInitializationHandler; private readonly ILogger _logger = loggerFactory.CreateLogger(nameof(WorkspaceProjectFactoryService)); private readonly ILoggerFactory _loggerFactory = loggerFactory; public async Task InitializeAsync(CancellationToken cancellationToken) => await _projectInitializationHandler.SubscribeToInitializationCompleteAsync(cancellationToken); public async Task<IWorkspaceProject> CreateAndAddProjectAsync(WorkspaceProjectCreationInfo creationInfo, CancellationToken cancellationToken) { VSCodeRequestTelemetryLogger.ReportProjectLoadStarted(); try { if (creationInfo.BuildSystemProperties.TryGetValue("SolutionPath", out var solutionPath)) { _workspaceFactory.HostProjectFactory.SolutionPath = solutionPath; } var project = await _workspaceFactory.HostProjectFactory.CreateAndAddToWorkspaceAsync( creationInfo.DisplayName, creationInfo.Language, new Workspaces.ProjectSystem.ProjectSystemProjectCreationInfo { FilePath = creationInfo.FilePath }, _workspaceFactory.ProjectSystemHostInfo, cancellationToken).ConfigureAwait(false); // We have now created the project and added it to the solution -- we are committed at this point // to returning a project or else we would never have a way to remove this project we created. cancellationToken = CancellationToken.None; var workspaceProject = new WorkspaceProject(project, _workspaceFactory.HostWorkspace.Services.SolutionServices, targetFrameworkManager, _loggerFactory); // We've created a new project, so initialize properties we have await workspaceProject.SetBuildSystemPropertiesAsync(creationInfo.BuildSystemProperties, CancellationToken.None); _logger.LogInformation(string.Format(LanguageServerResources.Project_0_loaded_by_CSharp_Dev_Kit, creationInfo.FilePath)); return workspaceProject; } catch (Exception e) when (LanguageServerFatalError.ReportAndLogAndPropagate(e, _logger, $"Failed to create project {creationInfo.DisplayName}")) { throw ExceptionUtilities.Unreachable(); } } public async Task<IReadOnlyCollection<string>> GetSupportedBuildSystemPropertiesAsync(CancellationToken _) { // TODO: implement return []; } }