コード例 #1
0
        internal LanguageServer(
            Connection connection,
            IResponseRouter responseRouter,
            IOptions <LanguageServerOptions> options,
            ILanguageServerConfiguration configuration,
            ServerInfo serverInfo,
            ILspServerReceiver receiver,
            ISerializer serializer,
            IServiceProvider serviceProvider,
            ISupportedCapabilities supportedCapabilities,
            TextDocumentIdentifiers textDocumentIdentifiers,
            IEnumerable <OnLanguageServerInitializeDelegate> initializeDelegates,
            IEnumerable <OnLanguageServerInitializedDelegate> initializedDelegates,
            IEnumerable <OnLanguageServerStartedDelegate> startedDelegates,
            IEnumerable <IOnLanguageServerStarted> startedHandlers,
            IServerWorkDoneManager serverWorkDoneManager,
            ITextDocumentLanguageServer textDocumentLanguageServer,
            IClientLanguageServer clientLanguageServer,
            IGeneralLanguageServer generalLanguageServer,
            IWindowLanguageServer windowLanguageServer,
            IWorkspaceLanguageServer workspaceLanguageServer,
            LanguageProtocolSettingsBag languageProtocolSettingsBag,
            SharedHandlerCollection handlerCollection,
            IProgressManager progressManager,
            ILanguageServerWorkspaceFolderManager workspaceFolderManager, IEnumerable <IOnLanguageServerInitialize> initializeHandlers,
            IEnumerable <IOnLanguageServerInitialized> initializedHandlers
            ) : base(handlerCollection, responseRouter)
        {
            Configuration = configuration;

            _connection              = connection;
            _serverInfo              = serverInfo;
            _serverReceiver          = receiver;
            _serializer              = serializer;
            _supportedCapabilities   = supportedCapabilities;
            _textDocumentIdentifiers = textDocumentIdentifiers;
            _initializeDelegates     = initializeDelegates;
            _initializedDelegates    = initializedDelegates;
            _startedDelegates        = startedDelegates;
            _startedHandlers         = startedHandlers;
            WorkDoneManager          = serverWorkDoneManager;
            _settingsBag             = languageProtocolSettingsBag;
            Services    = serviceProvider;
            _collection = handlerCollection;

            // We need to at least create Window here in case any handler does logging in their constructor
            TextDocument           = textDocumentLanguageServer;
            Client                 = clientLanguageServer;
            General                = generalLanguageServer;
            Window                 = windowLanguageServer;
            Workspace              = workspaceLanguageServer;
            ProgressManager        = progressManager;
            WorkspaceFolderManager = workspaceFolderManager;
            _initializeHandlers    = initializeHandlers;
            _initializedHandlers   = initializedHandlers;
            _concurrency           = options.Value.Concurrency;

            _disposable.Add(_collection.Add(this));
        }
 public SharedHandlerCollection(
     ISupportedCapabilities supportedCapabilities,
     TextDocumentIdentifiers textDocumentIdentifiers,
     IResolverContext resolverContext,
     ILspHandlerTypeDescriptorProvider handlerTypeDescriptorProvider)
 {
     _supportedCapabilities         = supportedCapabilities;
     _textDocumentIdentifiers       = textDocumentIdentifiers;
     _resolverContext               = resolverContext;
     _handlerTypeDescriptorProvider = handlerTypeDescriptorProvider;
 }
コード例 #3
0
        internal static IDisposable RegisterHandlers(
            IObservable <Unit> initializeComplete,
            IClientLanguageServer client,
            IServerWorkDoneManager serverWorkDoneManager,
            ISupportedCapabilities supportedCapabilities,
            IEnumerable <ILspHandlerDescriptor> collection
            )
        {
            var descriptors = new List <ILspHandlerDescriptor>();

            foreach (var descriptor in collection)
            {
                if (
                    descriptor is LspHandlerDescriptor lspHandlerDescriptor &&
                    (lspHandlerDescriptor.TypeDescriptor is { } &&
        internal static IDisposable RegisterHandlers(
            IObservable <Unit> initializeComplete,
            IClientLanguageServer client,
            IServerWorkDoneManager serverWorkDoneManager,
            ISupportedCapabilities supportedCapabilities,
            IEnumerable <ILspHandlerDescriptor> collection
            )
        {
            var descriptors = new List <ILspHandlerDescriptor>();

            foreach (var descriptor in collection)
            {
                if (descriptor is LspHandlerDescriptor lspHandlerDescriptor &&
                    lspHandlerDescriptor.TypeDescriptor?.HandlerType != null &&
                    typeof(IDoesNotParticipateInRegistration).IsAssignableFrom(lspHandlerDescriptor.TypeDescriptor.HandlerType))
                {
                    continue;
                }

                descriptors.Add(descriptor);
            }

            return(DynamicallyRegisterHandlers(client, initializeComplete, serverWorkDoneManager, supportedCapabilities, descriptors));
        }
        internal static IDisposable RegisterHandlers(
            IObservable <Unit> initializeComplete,
            IClientLanguageServer client,
            IServerWorkDoneManager serverWorkDoneManager,
            ISupportedCapabilities supportedCapabilities,
            IDisposable handlerDisposable
            )
        {
            if (handlerDisposable is LspHandlerDescriptorDisposable lsp)
            {
                return(new CompositeDisposable(
                           lsp, RegisterHandlers(
                               initializeComplete,
                               client,
                               serverWorkDoneManager,
                               supportedCapabilities,
                               lsp.Descriptors
                               )
                           ));
            }

            if (!(handlerDisposable is CompositeDisposable cd))
            {
                return(Disposable.Empty);
            }
            cd.Add(
                RegisterHandlers(
                    initializeComplete,
                    client,
                    serverWorkDoneManager,
                    supportedCapabilities,
                    cd.OfType <LspHandlerDescriptorDisposable>().SelectMany(z => z.Descriptors)
                    )
                );
            return(cd);
        }
コード例 #6
0
 public HandlerCollection(ISupportedCapabilities supportedCapabilities)
 {
     _supportedCapabilities = supportedCapabilities;
 }
コード例 #7
0
        internal LanguageServer(
            Connection connection,
            IResponseRouter responseRouter,
            IOptions <LanguageServerOptions> options,
            ILanguageServerConfiguration configuration,
            ServerInfo serverInfo,
            ILspServerReceiver receiver,
            ISerializer serializer,
            IResolverContext resolverContext,
            ISupportedCapabilities supportedCapabilities,
            TextDocumentIdentifiers textDocumentIdentifiers,
            IEnumerable <OnLanguageServerInitializeDelegate> initializeDelegates,
            IEnumerable <OnLanguageServerInitializedDelegate> initializedDelegates,
            IEnumerable <OnLanguageServerStartedDelegate> startedDelegates,
            IEnumerable <IOnLanguageServerStarted> startedHandlers,
            IServerWorkDoneManager serverWorkDoneManager,
            ITextDocumentLanguageServer textDocumentLanguageServer,
            IClientLanguageServer clientLanguageServer,
            IGeneralLanguageServer generalLanguageServer,
            IWindowLanguageServer windowLanguageServer,
            IWorkspaceLanguageServer workspaceLanguageServer,
            LanguageProtocolSettingsBag languageProtocolSettingsBag,
            SharedHandlerCollection handlerCollection,
            IProgressManager progressManager,
            ILanguageServerWorkspaceFolderManager workspaceFolderManager, IEnumerable <IOnLanguageServerInitialize> initializeHandlers,
            IEnumerable <IOnLanguageServerInitialized> initializedHandlers,
            IEnumerable <IRegistrationOptionsConverter> registrationOptionsConverters,
            InstanceHasStarted instanceHasStarted
            ) : base(handlerCollection, responseRouter)
        {
            Configuration = configuration;

            _connection              = connection;
            _serverInfo              = serverInfo;
            _serverReceiver          = receiver;
            _serializer              = serializer;
            _supportedCapabilities   = supportedCapabilities;
            _textDocumentIdentifiers = textDocumentIdentifiers;
            _initializeDelegates     = initializeDelegates;
            _initializedDelegates    = initializedDelegates;
            _startedDelegates        = startedDelegates;
            _startedHandlers         = startedHandlers;
            WorkDoneManager          = serverWorkDoneManager;
            _settingsBag             = languageProtocolSettingsBag;
            Services    = _resolverContext = resolverContext;
            _collection = handlerCollection;

            // We need to at least create Window here in case any handler does logging in their constructor
            TextDocument                   = textDocumentLanguageServer;
            Client                         = clientLanguageServer;
            General                        = generalLanguageServer;
            Window                         = windowLanguageServer;
            Workspace                      = workspaceLanguageServer;
            ProgressManager                = progressManager;
            WorkspaceFolderManager         = workspaceFolderManager;
            _initializeHandlers            = initializeHandlers;
            _initializedHandlers           = initializedHandlers;
            _registrationOptionsConverters = registrationOptionsConverters;
            _instanceHasStarted            = instanceHasStarted;
            _concurrency                   = options.Value.Concurrency;

            _capabilityTypes = options
                               .Value.Assemblies
                               .SelectMany(z => z.ExportedTypes)
                               .Where(z => z.IsClass && !z.IsAbstract)
                               .Where(z => typeof(ICapability).IsAssignableFrom(z))
                               .Where(z => z.GetCustomAttributes <CapabilityKeyAttribute>().Any())
                               .ToLookup(z => string.Join(".", z.GetCustomAttribute <CapabilityKeyAttribute>().Keys));

            _disposable.Add(_collection.Add(this));
        }
コード例 #8
0
 internal static void InitHandlers(ILanguageServer client, CompositeDisposable result, ISupportedCapabilities supportedCapabilities)
 {
     Observable.Concat(
         GetUniqueHandlers <IOnLanguageServerInitialize>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnInitialize(client, client.ClientSettings, ct)))
         .Merge(),
         GetUniqueHandlers <IOnLanguageServerInitialized>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnInitialized(client, client.ClientSettings, client.ServerSettings, ct)))
         .Merge(),
         GetUniqueHandlers <IOnLanguageServerStarted>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnStarted(client, ct)))
         .Merge()
         ).Subscribe();
 }
コード例 #9
0
 public static IJsonRpcHandler InitializeHandler(ILspHandlerDescriptor descriptor, ISupportedCapabilities supportedCapabilities, IJsonRpcHandler handler)
 {
     supportedCapabilities.SetCapability(descriptor, handler);
     return(handler);
 }
コード例 #10
0
 public SharedHandlerCollection(ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers, IServiceProvider serviceProvider)
 {
     _supportedCapabilities   = supportedCapabilities;
     _textDocumentIdentifiers = textDocumentIdentifiers;
     _serviceProvider         = serviceProvider;
 }
コード例 #11
0
 public HandlerCollection(ISupportedCapabilities supportedCapabilities,
                          TextDocumentIdentifiers textDocumentIdentifiers)
 {
     _supportedCapabilities   = supportedCapabilities;
     _textDocumentIdentifiers = textDocumentIdentifiers;
 }
        internal static IDisposable DynamicallyRegisterHandlers(
            IClientLanguageServer client,
            IObservable <Unit> initializeComplete,
            IServerWorkDoneManager serverWorkDoneManager,
            ISupportedCapabilities supportedCapabilities,
            IReadOnlyList <ILspHandlerDescriptor> descriptors
            )
        {
            if (descriptors.Count == 0)
            {
                return(Disposable.Empty); // No dynamic registrations supported by client.
            }
            var disposable = new CompositeDisposable();

            var result = initializeComplete
                         .LastOrDefaultAsync()
                         .Select(
                _ => {
                var registrations = new List <Registration>();
                foreach (var descriptor in descriptors)
                {
                    if (descriptor.HasCapability && supportedCapabilities.AllowsDynamicRegistration(descriptor.CapabilityType))
                    {
                        if (descriptor.RegistrationOptions is IWorkDoneProgressOptions wdpo)
                        {
                            wdpo.WorkDoneProgress = serverWorkDoneManager.IsSupported;
                        }

                        registrations.Add(
                            new Registration {
                            Id              = descriptor.Id.ToString(),
                            Method          = descriptor.Method,
                            RegisterOptions = descriptor.RegistrationOptions
                        }
                            );
                    }
                }

                return(registrations);
            }
                )
                         .SelectMany(
                registrations => Observable.FromAsync(ct => client.RegisterCapability(new RegistrationParams {
                Registrations = registrations
            }, ct)), (a, b) => a
                )
                         .Aggregate((z, b) => z)
                         .Subscribe(
                registrations => {
                disposable.Add(
                    Disposable.Create(
                        () => {
                    client.UnregisterCapability(
                        new UnregistrationParams {
                        Unregisterations = registrations
                    }
                        ).ToObservable().Subscribe();
                }
                        )
                    );
            }
                );

            disposable.Add(result);
            return(disposable);
        }
 internal static void InitHandlers(ILanguageServer client, CompositeDisposable result, ISupportedCapabilities supportedCapabilities)
 {
     Observable.Concat(
         GetUniqueHandlers <IOnLanguageServerInitialize>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnInitialize(client, client.ClientSettings, ct)))
         .Merge(),
         GetAllDescriptors(result)
         .Select(item => LspHandlerDescriptorHelpers.InitializeHandler(item, supportedCapabilities, item.Handler))
         .ToObservable()
         .Select(z => Unit.Default),
         GetUniqueHandlers <IOnLanguageServerInitialized>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnInitialized(client, client.ClientSettings, client.ServerSettings, ct)))
         .Merge(),
         GetUniqueHandlers <IOnLanguageServerStarted>(result)
         .Select(handler => Observable.FromAsync(ct => handler.OnStarted(client, ct)))
         .Merge()
         ).Subscribe();
 }