Exemplo n.º 1
0
 public MyWorkspaceSymbolsHandler(IServerWorkDoneManager serverWorkDoneManager, IProgressManager progressManager, ILogger <MyWorkspaceSymbolsHandler> logger) :
     base(new WorkspaceSymbolRegistrationOptions())
 {
     _serverWorkDoneManager = serverWorkDoneManager;
     _progressManager       = progressManager;
     this.logger            = logger;
 }
        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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
 public InnerCodeLensHandler(IServerWorkDoneManager workDoneManager, IProgressManager progressManager)
 {
     _workDoneManager = workDoneManager;
     _progressManager = progressManager;
 }
        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));
        }
Exemplo n.º 8
0
 public MyWorkspaceSymbolsHandler(IServerWorkDoneManager serverWorkDoneManager, IProgressManager progressManager, ILogger <MyWorkspaceSymbolsHandler> logger)
 {
     _serverWorkDoneManager = serverWorkDoneManager;
     _progressManager       = progressManager;
     _logger = logger;
 }
 public InnerCodeLensHandler(IServerWorkDoneManager workDoneManager, IProgressManager progressManager) : base(new CodeLensRegistrationOptions())
 {
     _workDoneManager = workDoneManager;
     _progressManager = progressManager;
 }
        internal LanguageServer(LanguageServerOptions options) : base(options)
        {
            var services = options.Services;
            var configurationProvider = new DidChangeConfigurationProvider(this, options.ConfigurationBuilderAction);

            services.AddSingleton <IJsonRpcHandler>(configurationProvider);
            options.RequestProcessIdentifier ??= (options.SupportsContentModified
                ? new RequestProcessIdentifier(RequestProcessType.Parallel)
                : new RequestProcessIdentifier(RequestProcessType.Serial));

            services.AddSingleton <IConfiguration>(configurationProvider);
            services.AddSingleton(Configuration = configurationProvider);

            services.AddLogging(builder => options.LoggingBuilderAction(builder));
            services.AddSingleton <IOptionsMonitor <LoggerFilterOptions>, LanguageServerLoggerFilterOptions>();

            _serverInfo              = options.ServerInfo;
            _serverReceiver          = options.Receiver;
            _serializer              = options.Serializer;
            _supportedCapabilities   = new SupportedCapabilities();
            _textDocumentIdentifiers = new TextDocumentIdentifiers();
            var collection = new SharedHandlerCollection(_supportedCapabilities, _textDocumentIdentifiers);

            services.AddSingleton <IHandlersManager>(collection);
            _collection           = collection;
            _initializeDelegates  = options.InitializeDelegates;
            _initializedDelegates = options.InitializedDelegates;
            _startedDelegates     = options.StartedDelegates;

            services.AddSingleton <IOutputHandler>(_ => new OutputHandler(
                                                       options.Output,
                                                       options.Serializer,
                                                       options.Receiver.ShouldFilterOutput,
                                                       _.GetService <ILogger <OutputHandler> >())
                                                   );
            services.AddSingleton(_collection);
            services.AddSingleton(_textDocumentIdentifiers);
            services.AddSingleton(_serializer);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(_serializer);
            services.AddSingleton(options.RequestProcessIdentifier);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.IReceiver>(options.Receiver);
            services.AddSingleton <ILspServerReceiver>(options.Receiver);

            services.AddTransient <IHandlerMatcher, TextDocumentMatcher>();
            services.AddSingleton <ILanguageServer>(this);
            services.AddTransient <IHandlerMatcher, ExecuteCommandMatcher>();
            services.AddTransient <IHandlerMatcher, ResolveCommandMatcher>();
            services.AddSingleton <LspRequestRouter>();
            services.AddSingleton <IRequestRouter <ILspHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>());
            services.AddSingleton <IRequestRouter <IHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>());
            services.AddSingleton <IResponseRouter, ResponseRouter>();
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ResolveCommandPipeline <,>));

            services.AddSingleton <IProgressManager, ProgressManager>();
            services.AddSingleton <IJsonRpcHandler>(_ => _.GetRequiredService <IProgressManager>() as IJsonRpcHandler);
            services.AddSingleton <IServerWorkDoneManager, ServerWorkDoneManager>();
            services.AddSingleton <IJsonRpcHandler>(_ => _.GetRequiredService <IServerWorkDoneManager>() as IJsonRpcHandler);

            EnsureAllHandlersAreRegistered();

            var serviceProvider = services.BuildServiceProvider();

            _disposable.Add(serviceProvider);
            _serviceProvider = serviceProvider;
            collection.SetServiceProvider(_serviceProvider);

            var requestRouter = _serviceProvider.GetRequiredService <IRequestRouter <ILspHandlerDescriptor> >();

            _responseRouter        = _serviceProvider.GetRequiredService <IResponseRouter>();
            ProgressManager        = _serviceProvider.GetRequiredService <IProgressManager>();
            _serverWorkDoneManager = _serviceProvider.GetRequiredService <IServerWorkDoneManager>();
            _connection            = new Connection(
                options.Input,
                _serviceProvider.GetRequiredService <IOutputHandler>(),
                options.Receiver,
                options.RequestProcessIdentifier,
                _serviceProvider.GetRequiredService <IRequestRouter <IHandlerDescriptor> >(),
                _responseRouter,
                _serviceProvider.GetRequiredService <ILoggerFactory>(),
                options.OnUnhandledException ?? (e => { ForcefulShutdown(); }),
                options.CreateResponseException,
                options.MaximumRequestTimeout,
                options.SupportsContentModified,
                options.Concurrency
                );

            // We need to at least create Window here in case any handler does loggin in their constructor
            TextDocument = new TextDocumentLanguageServer(this, _serviceProvider);
            Client       = new ClientLanguageServer(this, _serviceProvider);
            General      = new GeneralLanguageServer(this, _serviceProvider);
            Window       = new WindowLanguageServer(this, _serviceProvider);
            Workspace    = new WorkspaceLanguageServer(this, _serviceProvider);

            _disposable.Add(_collection.Add(this));

            {
                var serviceHandlers    = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray();
                var serviceIdentifiers = _serviceProvider.GetServices <ITextDocumentIdentifier>().ToArray();
                _disposable.Add(_textDocumentIdentifiers.Add(serviceIdentifiers));
                _disposable.Add(_collection.Add(serviceHandlers));
                options.AddLinks(_collection);
            }
        }
        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);
        }