public void Should_Return_Did_Open_Text_Document_Handler_Descriptor_With_Sepcial_Character() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cshtml"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new DidOpenTextDocumentParams { TextDocument = new TextDocumentItem { Uri = new Uri("file://c:/users/myøasdf/d.cshtml") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public InterimLanguageProtocolRegistry(IServiceProvider serviceProvider, CompositeHandlersManager handlersManager, TextDocumentIdentifiers textDocumentIdentifiers) : base( handlersManager ) { _serviceProvider = serviceProvider; _textDocumentIdentifiers = textDocumentIdentifiers; }
internal LanguageClient( Connection connection, IOptions <LanguageClientOptions> options, IEnumerable <ICapability> capabilities, ClientInfo clientInfo, ClientCapabilities clientCapabilities, ILspClientReceiver lspClientReceiver, TextDocumentIdentifiers textDocumentIdentifiers, IServiceProvider serviceProvider, IEnumerable <OnLanguageClientStartedDelegate> startedDelegates, IEnumerable <IOnLanguageClientStarted> startedHandlers, ITextDocumentLanguageClient textDocumentLanguageClient, IClientLanguageClient clientLanguageClient, IGeneralLanguageClient generalLanguageClient, IWindowLanguageClient windowLanguageClient, IWorkspaceLanguageClient workspaceLanguageClient, LanguageProtocolSettingsBag languageProtocolSettingsBag, SharedHandlerCollection handlerCollection, IResponseRouter responseRouter, IProgressManager progressManager, IClientWorkDoneManager clientWorkDoneManager, IRegistrationManager registrationManager, ILanguageClientWorkspaceFoldersManager languageClientWorkspaceFoldersManager, IEnumerable <OnLanguageClientInitializeDelegate> initializeDelegates, IEnumerable <IOnLanguageClientInitialize> initializeHandlers, IEnumerable <OnLanguageClientInitializedDelegate> initializedDelegates, IEnumerable <IOnLanguageClientInitialized> initializedHandlers ) : base(handlerCollection, responseRouter) { _connection = connection; _capabilities = capabilities; _clientCapabilities = clientCapabilities; _clientInfo = clientInfo; _receiver = lspClientReceiver; _textDocumentIdentifiers = textDocumentIdentifiers; _startedDelegates = startedDelegates; _startedHandlers = startedHandlers; _rootUri = options.Value.RootUri; _trace = options.Value.Trace; _initializationOptions = options.Value.InitializationOptions; _settingsBag = languageProtocolSettingsBag; _collection = handlerCollection; Services = serviceProvider; _responseRouter = responseRouter; ProgressManager = progressManager; WorkDoneManager = clientWorkDoneManager; RegistrationManager = registrationManager; WorkspaceFoldersManager = languageClientWorkspaceFoldersManager; _initializeDelegates = initializeDelegates; _initializeHandlers = initializeHandlers; _initializedDelegates = initializedDelegates; _initializedHandlers = initializedHandlers; _concurrency = options.Value.Concurrency; // We need to at least create Window here in case any handler does loggin in their constructor TextDocument = textDocumentLanguageClient; Client = clientLanguageClient; General = generalLanguageClient; Window = windowLanguageClient; Workspace = workspaceLanguageClient; }
public async Task ShouldRouteToCorrect_Notification_WithManyHandlers() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()).Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers) { textDocumentSyncHandler, textDocumentSyncHandler2 }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var @params = new DidSaveTextDocumentParams() { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cake")) }; var request = new Notification(DocumentNames.DidSave, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings))); await mediator.RouteNotification(mediator.GetDescriptor(request), request, CancellationToken.None); await textDocumentSyncHandler.Received(0).Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); await textDocumentSyncHandler2.Received(1).Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); }
public void Should_Return_Did_Open_Text_Document_Handler_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new DidOpenTextDocumentParams { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.cs") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public void Should_Return_Did_Close_Text_Document_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new DidCloseTextDocumentParams { TextDocument = new VersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, collection.Where(x => x.Method == TextDocumentNames.DidClose) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidClose); }
public InterimLanguageProtocolRegistry(IResolverContext resolverContext, CompositeHandlersManager handlersManager, TextDocumentIdentifiers textDocumentIdentifiers) : base( handlersManager ) { _resolverContext = resolverContext; _textDocumentIdentifiers = textDocumentIdentifiers; }
public void Should_Return_Code_Lens_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); var codeLensHandler = (ICodeLensHandler)Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); codeLensHandler.GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cs" }) } ); var codeLensHandler2 = (ICodeLensHandler)Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); codeLensHandler2.GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cake" }) } ); collection.Add(codeLensHandler, codeLensHandler2); collection.Initialize(); // When var result = handlerMatcher.FindHandler( new CodeLensParams { TextDocument = new OptionalVersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, collection.Where(x => x.Method == TextDocumentNames.CodeLens) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.CodeLens); lspHandlerDescriptors.Should().Contain(x => ((LspHandlerDescriptor)x).Key == "[**/*.cs]"); }
public async Task ShouldRouteToCorrect_Request_WithManyHandlers() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()).Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()).Returns(Unit.Value); var codeActionHandler = Substitute.For <ICodeActionHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()) .Returns(new CommandOrCodeActionContainer()); var registry = new TestLanguageServerRegistry(); var codeActionDelegate = Substitute.For <Func <CodeActionParams, CancellationToken, Task <CommandOrCodeActionContainer> > >(); codeActionDelegate.Invoke(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()) .Returns(new CommandOrCodeActionContainer()); registry.OnCodeAction( codeActionDelegate, new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var handlerCollection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers) { textDocumentSyncHandler, textDocumentSyncHandler2, codeActionHandler }; handlerCollection.Add(registry.Handlers); AutoSubstitute.Provide <IHandlerCollection>(handlerCollection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(handlerCollection); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var id = Guid.NewGuid().ToString(); var @params = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cake")) }; var request = new Request(id, DocumentNames.CodeAction, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings))); await mediator.RouteRequest(mediator.GetDescriptor(request), request, CancellationToken.None); await codeActionHandler.Received(0).Handle(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()); await codeActionDelegate.Received(1).Invoke(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()); }
public async Task ShouldRouteToCorrect_Request_WithManyHandlers_CodeLensHandler() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var codeActionHandler = Substitute.For <ICodeLensHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var codeActionHandler2 = Substitute.For <ICodeLensHandler>(); codeActionHandler2.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") }); codeActionHandler2 .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var tdi = new TextDocumentIdentifiers(); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, tdi, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, textDocumentSyncHandler2, codeActionHandler, codeActionHandler2 }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); AutoSubstitute.Provide <IHandlerMatcher>(new TextDocumentMatcher(LoggerFactory.CreateLogger <TextDocumentMatcher>(), tdi)); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var id = Guid.NewGuid().ToString(); var @params = new CodeLensParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Request( id, TextDocumentNames.CodeLens, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteRequest(mediator.GetDescriptors(request), request, CancellationToken.None); await codeActionHandler2.Received(0).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); await codeActionHandler.Received(1).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); }
public void Should_Return_Code_Lens_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); var codeLensHandler = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler.GetRegistrationOptions() .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cs" }) } ); var codeLensHandler2 = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler2.GetRegistrationOptions() .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cake" }) } ); collection.Add(codeLensHandler, codeLensHandler2); // When var result = handlerMatcher.FindHandler( new CodeLensParams { TextDocument = new VersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, collection.Where(x => x.Method == TextDocumentNames.CodeLens) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.CodeLens); result.Should().Contain(x => ((LspHandlerDescriptor)x).Key == "[**/*.cs]"); }
public SharedHandlerCollection( ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers, IResolverContext resolverContext, ILspHandlerTypeDescriptorProvider handlerTypeDescriptorProvider) { _supportedCapabilities = supportedCapabilities; _textDocumentIdentifiers = textDocumentIdentifiers; _resolverContext = resolverContext; _handlerTypeDescriptorProvider = handlerTypeDescriptorProvider; }
public async Task ShouldRouteToCorrect_Notification_WithManyHandlers() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection( SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider( new[] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly } ) ) { textDocumentSyncHandler, textDocumentSyncHandler2 }; collection.Initialize(); AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); AutoSubstitute.Provide <IHandlerMatcher>(new TextDocumentMatcher(LoggerFactory.CreateLogger <TextDocumentMatcher>(), textDocumentIdentifiers)); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var @params = new DidSaveTextDocumentParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cake")) }; var request = new Notification( TextDocumentNames.DidSave, JObject.Parse(JsonConvert.SerializeObject(@params, new LspSerializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteNotification(mediator.GetDescriptors(request), request, CancellationToken.None); await textDocumentSyncHandler.Received(0) .Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); await textDocumentSyncHandler2.Received(1) .Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); }
public void Should_Return_Did_Folding_Range_handler() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.ps*1"), "powershell"); var handler = Substitute.For <IFoldingRangeHandler>(); handler.GetRegistrationOptions().Returns( new FoldingRangeRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.ps*1" }) } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler, handler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new FoldingRangeRequestParam { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.ps1") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public void Should_Return_Did_Folding_Range_handler() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.ps*1"), "powershell"); var handler = Substitute.For <IFoldingRangeHandler>(); handler.GetRegistrationOptions().Returns( new FoldingRangeRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.ps*1" }) } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, handler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new FoldingRangeRequestParam { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.ps1") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public DefaultLanguageClientFacade( IResponseRouter requestRouter, IResolverContext resolverContext, IProgressManager progressManager, ILanguageProtocolSettings languageProtocolSettings, Lazy <ITextDocumentLanguageClient> textDocument, Lazy <IClientLanguageClient> client, Lazy <IGeneralLanguageClient> general, Lazy <IWindowLanguageClient> window, Lazy <IWorkspaceLanguageClient> workspace, Lazy <IHandlersManager> handlersManager, TextDocumentIdentifiers textDocumentIdentifiers, IInsanceHasStarted instanceHasStarted ) : base(requestRouter, resolverContext, progressManager, languageProtocolSettings) { _textDocument = textDocument; _client = client; _general = general; _window = window; _workspace = workspace; _handlersManager = handlersManager; _textDocumentIdentifiers = textDocumentIdentifiers; _instanceHasStarted = instanceHasStarted; }
public SharedHandlerCollection(ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers) { _supportedCapabilities = supportedCapabilities; _textDocumentIdentifiers = textDocumentIdentifiers; }
public LangaugeClientRegistry(IServiceProvider serviceProvider, CompositeHandlersManager handlersManager, TextDocumentIdentifiers textDocumentIdentifiers) : base(serviceProvider, handlersManager, textDocumentIdentifiers) { }
internal LanguageClient(LanguageClientOptions options) : base(options) { _capabilities = options.SupportedCapabilities; _clientCapabilities = options.ClientCapabilities; var services = options.Services; services.AddLogging(builder => options.LoggingBuilderAction(builder)); options.RequestProcessIdentifier ??= (options.SupportsContentModified ? new RequestProcessIdentifier(RequestProcessType.Parallel) : new RequestProcessIdentifier(RequestProcessType.Serial)); // services.AddSingleton<IOptionsMonitor<LoggerFilterOptions>, LanguageClientLoggerFilterOptions>(); _clientInfo = options.ClientInfo; _receiver = options.Receiver; var serializer = options.Serializer; var supportedCapabilities = new SupportedCapabilities(); _textDocumentIdentifiers = new TextDocumentIdentifiers(); var collection = new SharedHandlerCollection(supportedCapabilities, _textDocumentIdentifiers); services.AddSingleton <IHandlersManager>(collection); _collection = collection; // _initializeDelegates = initializeDelegates; // _initializedDelegates = initializedDelegates; _startedDelegates = options.StartedDelegates; _rootUri = options.RootUri; _trace = options.Trace; _initializationOptions = options.InitializationOptions; 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(options.Receiver); services.AddSingleton <ILanguageClient>(this); services.AddSingleton <LspRequestRouter>(); services.AddSingleton <IRequestRouter <ILspHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>()); services.AddSingleton <IRequestRouter <IHandlerDescriptor> >(_ => _.GetRequiredService <LspRequestRouter>()); services.AddSingleton <IResponseRouter, ResponseRouter>(); services.AddSingleton <IProgressManager, ProgressManager>(); services.AddSingleton(_ => _.GetRequiredService <IProgressManager>() as IJsonRpcHandler); services.AddSingleton <IClientWorkDoneManager, ClientWorkDoneManager>(); services.AddSingleton(_ => _.GetRequiredService <IClientWorkDoneManager>() as IJsonRpcHandler); EnsureAllHandlersAreRegistered(); services.AddSingleton <RegistrationManager>(); services.AddSingleton <IRegistrationManager>(_ => _.GetRequiredService <RegistrationManager>()); if (options.DynamicRegistration) { services.AddSingleton(_ => _.GetRequiredService <RegistrationManager>() as IJsonRpcHandler); } var workspaceFoldersManager = new WorkspaceFoldersManager(this); services.AddSingleton(workspaceFoldersManager); services.AddSingleton <IWorkspaceFoldersManager>(workspaceFoldersManager); if (options.WorkspaceFolders) { services.AddSingleton <IJsonRpcHandler>(workspaceFoldersManager); } var serviceProvider = services.BuildServiceProvider(); _disposable.Add(serviceProvider); _serviceProvider = serviceProvider; collection.SetServiceProvider(_serviceProvider); _responseRouter = _serviceProvider.GetRequiredService <IResponseRouter>(); _progressManager = _serviceProvider.GetRequiredService <IProgressManager>(); _workDoneManager = _serviceProvider.GetRequiredService <IClientWorkDoneManager>(); _registrationManager = _serviceProvider.GetRequiredService <RegistrationManager>(); _workspaceFoldersManager = _serviceProvider.GetRequiredService <IWorkspaceFoldersManager>(); _connection = new Connection( options.Input, _serviceProvider.GetRequiredService <IOutputHandler>(), options.Receiver, options.RequestProcessIdentifier, _serviceProvider.GetRequiredService <IRequestRouter <IHandlerDescriptor> >(), _responseRouter, _serviceProvider.GetRequiredService <ILoggerFactory>(), options.OnUnhandledException ?? (e => { }), 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 TextDocumentLanguageClient(this, _serviceProvider); Client = new ClientLanguageClient(this, _serviceProvider); General = new GeneralLanguageClient(this, _serviceProvider); Window = new WindowLanguageClient(this, _serviceProvider); Workspace = new WorkspaceLanguageClient(this, _serviceProvider); workspaceFoldersManager.Add(options.Folders); 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); }
public LangaugeClientRegistry(IResolverContext resolverContext, CompositeHandlersManager handlersManager, TextDocumentIdentifiers textDocumentIdentifiers) : base( resolverContext, handlersManager, textDocumentIdentifiers ) { }
public TextDocumentMatcher(ILogger <TextDocumentMatcher> logger, TextDocumentIdentifiers textDocumentIdentifiers) { _logger = logger; _textDocumentIdentifiers = textDocumentIdentifiers; ; }
public SharedHandlerCollection(ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers, IServiceProvider serviceProvider) { _supportedCapabilities = supportedCapabilities; _textDocumentIdentifiers = textDocumentIdentifiers; _serviceProvider = serviceProvider; }