/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleLanguageServer.cs
67 строк
2 KB
David Barbet
Refactor LSP server logging to remove singleton lsp instance (#84001)
16 июн 2026, 05:04
Не верифицирован
16 июн 2026, 05:04
82e81e5
Код
Авторство
О чём код?
// 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 System; using System.Text.Json; using Microsoft.CodeAnalysis.LanguageServer; using Microsoft.CommonLanguageServerProtocol.Framework.Handlers; using Microsoft.Extensions.DependencyInjection; using Roslyn.LanguageServer.Protocol; using StreamJsonRpc; namespace Microsoft.CommonLanguageServerProtocol.Framework.Example; internal class ExampleLanguageServer : SystemTextJsonLanguageServer<ExampleRequestContext> { private readonly Action<IServiceCollection>? _addExtraHandlers; public ExampleLanguageServer(JsonRpc jsonRpc, JsonSerializerOptions options, Action<IServiceCollection>? addExtraHandlers) : base(jsonRpc, options) { _addExtraHandlers = addExtraHandlers; // This spins up the queue and ensure the LSP is ready to start receiving requests Initialize(); } protected override ILspServices ConstructLspServices() { var serviceCollection = new ServiceCollection(); var _ = AddHandlers(serviceCollection) .AddSingleton<ILspLogger>(NoOpLspLogger.Instance) .AddSingleton<AbstractRequestContextFactory<ExampleRequestContext>, ExampleRequestContextFactory>() .AddSingleton<AbstractHandlerProvider>(s => HandlerProvider) .AddSingleton<IInitializeManager<InitializeParams, InitializeResult>, CapabilitiesManager>() .AddSingleton(this); var onServerShutdown = GetOnServerShutdown(); if (onServerShutdown != null) { serviceCollection.AddSingleton(onServerShutdown); } var lspServices = new ExampleLspServices(serviceCollection); return lspServices; } protected virtual IOnServerShutdown? GetOnServerShutdown() { return null; } protected virtual IServiceCollection AddHandlers(IServiceCollection serviceCollection) { _ = serviceCollection .AddSingleton<IMethodHandler, MultiRegisteringHandler>() .AddSingleton<IMethodHandler, InitializeHandler<InitializeParams, InitializeResult, ExampleRequestContext>>() .AddSingleton<IMethodHandler, InitializedHandler<InitializedParams, ExampleRequestContext>>(); if (_addExtraHandlers is not null) { _addExtraHandlers(serviceCollection); } return serviceCollection; } }