예제 #1
0
        public void Should_DisallowDynamicSupportedCapabilities(IJsonRpcHandler handler, object instance)
        {
            var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp");

            var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers())
            {
                textDocumentSyncHandler, handler
            };
            var provider = new ClientCapabilityProvider(collection);

            HasHandler(provider, instance).Should().BeFalse();
        }
        public ClientCapabilityProviderFixture()
        {
            var handler = Substitute.For <IExecuteCommandHandler>();

            handler.GetRegistrationOptions().Returns(new ExecuteCommandRegistrationOptions());

            var handlerCollection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue)
            {
                handler
            };
            var capabilityProvider = new ClientCapabilityProvider(handlerCollection);

            Provider = capabilityProvider;
        }
        public ClientCapabilityProviderFixture()
        {
            var handler = Substitute.For <IExecuteCommandHandler>();

            handler.GetRegistrationOptions().Returns(new ExecuteCommandRegistrationOptions());

            var handlerCollection = new OmniSharp.Extensions.LanguageServer.Server.HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers())
            {
                handler
            };
            var capabilityProvider = new ClientCapabilityProvider(handlerCollection);

            Provider = capabilityProvider;
        }
        public void Should_AllowUnsupportedCapabilities(IJsonRpcHandler handler, object instance)
        {
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp");

            var collection =
                new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), new ServiceCollection().BuildServiceProvider())
            {
                textDocumentSyncHandler, handler
            };
            var provider = new ClientCapabilityProvider(collection, true);

            HasHandler(provider, instance).Should().BeTrue();
        }
예제 #5
0
        public void Should_AllowNullSupportedCapabilities(IJsonRpcHandler handler, object instance)
        {
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp");

            var collection =
                new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(),
                                            new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly }))
            {
                textDocumentSyncHandler, handler
            };
            var provider = new ClientCapabilityProvider(collection, true);

            HasHandler(provider, instance).Should().BeTrue();
        }
 private void BindCapabilityValues(string capability)
 {
     if (capability != string.Empty)
     {
         var capabillityValues = new List <string>(ClientCapabilityProvider.Instance().GetAllClientCapabilityValues().Where(c => c.Key == capability).First().Value);
         capabillityValues.Sort();
         cboCapabilityValue.DataSource = capabillityValues;
     }
     else
     {
         cboCapabilityValue.DataSource = string.Empty;
         cboCapabilityValue.Text       = string.Empty;
     }
     cboCapabilityValue.DataBind();
 }
        public ClientCapabilityProviderFixture()
        {
            var handler = Substitute.For <IExecuteCommandHandler>();

            handler.GetRegistrationOptions().Returns(new ExecuteCommandRegistrationOptions());

            var handlerCollection = new SharedHandlerCollection(
                SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), new ServiceCollection().BuildServiceProvider()
                )
            {
                handler
            };
            var capabilityProvider = new ClientCapabilityProvider(handlerCollection, true);

            Provider = capabilityProvider;
        }
예제 #8
0
        public ClientCapabilityProviderFixture()
        {
            var handler = Substitute.For <IExecuteCommandHandler>();

            handler.GetRegistrationOptions().Returns(new ExecuteCommandRegistrationOptions());

            var handlerCollection = new SharedHandlerCollection(
                SupportedCapabilitiesFixture.AlwaysTrue,
                new TextDocumentIdentifiers(),
                Substitute.For <IResolverContext>(),
                new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })
                )
            {
                handler
            };
            var capabilityProvider = new ClientCapabilityProvider(handlerCollection, true);

            Provider = capabilityProvider;
        }
        public void GH162_TextDocumentSync_Should_Work_Without_WillSave_Or_WillSaveWaitUntil()
        {
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp");

            var collection =
                new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), new ServiceCollection().BuildServiceProvider())
            {
                textDocumentSyncHandler
            };
            var provider     = new ClientCapabilityProvider(collection, true);
            var capabilities = new ClientCapabilities {
                TextDocument = new TextDocumentClientCapabilities {
                    Synchronization = new SynchronizationCapability {
                        DidSave             = true,
                        DynamicRegistration = false,
                        WillSave            = true,
                        WillSaveWaitUntil   = true
                    },
                }
            };

            provider.HasStaticHandler(capabilities.TextDocument.Synchronization).Should().BeTrue();
        }
예제 #10
0
        public void Should_Handle_Mixed_Capabilities()
        {
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp");

            var codeActionHandler     = Substitute.For <ICodeActionHandler>();
            var definitionHandler     = Substitute.For <IDefinitionHandler>();
            var typeDefinitionHandler = Substitute.For <ITypeDefinitionHandler>();

            var collection =
                new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(),
                                            new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly }))
            {
                textDocumentSyncHandler, codeActionHandler, definitionHandler, typeDefinitionHandler
            };
            var provider     = new ClientCapabilityProvider(collection, true);
            var capabilities = new ClientCapabilities {
                TextDocument = new TextDocumentClientCapabilities {
                    CodeAction = new Supports <CodeActionCapability?>(
                        true, new CodeActionCapability {
                        DynamicRegistration = false,
                    }
                        ),
                    TypeDefinition = new Supports <TypeDefinitionCapability?>(
                        true, new TypeDefinitionCapability {
                        DynamicRegistration = true,
                    }
                        )
                }
            };

//            provider.GetStaticOptions(capabilities.TextDocument.CodeAction)
//                    .Get<ICodeActionOptions, CodeActionRegistrationOptions.StaticOptions>(CodeActionRegistrationOptions.StaticOptions.Of).Should().NotBeNull();
            provider.HasStaticHandler(capabilities.TextDocument.Definition).Should().BeTrue();
            provider.HasStaticHandler(capabilities.TextDocument.TypeDefinition).Should().BeFalse();
        }
예제 #11
0
        /// <summary>
        /// Get Redirection Url based on Http Context and Portal Id.
        /// </summary>
        /// <returns>string - Empty if redirection rules are not defined or no match found</returns>
        /// <param name="userAgent">User Agent - used for client capability detection.</param>
        /// <param name="portalId">Portal Id from which Redirection Rules should be applied.</param>
        /// <param name="currentTabId">Current Tab Id that needs to be evaluated.</param>
        public string GetRedirectUrl(string userAgent, int portalId, int currentTabId)
        {
            Requires.NotNull("userAgent", userAgent);

            string redirectUrl = string.Empty;

            IList <IRedirection> redirections = GetRedirectionsByPortal(portalId);

            //check for redirect only when redirect rules are defined
            if (redirections == null || redirections.Count == 0)
            {
                return(redirectUrl);
            }

            //try to get content from cache
            var cacheKey = string.Format(RedirectionUrlCacheKey, userAgent, portalId, currentTabId);

            redirectUrl = GetUrlFromCache(cacheKey);
            if (!string.IsNullOrEmpty(redirectUrl))
            {
                return(redirectUrl);
            }

            var clientCapability = ClientCapabilityProvider.Instance().GetClientCapability(userAgent);
            var tabController    = new TabController();

            foreach (var redirection in redirections)
            {
                if (redirection.Enabled)
                {
                    bool checkFurther = false;
                    //redirection is based on source tab
                    if (redirection.SourceTabId != Null.NullInteger)
                    {
                        //source tab matches current tab
                        if (currentTabId == redirection.SourceTabId)
                        {
                            checkFurther = true;
                        }
                        //is child tabs to be included as well
                        else if (redirection.IncludeChildTabs)
                        {
                            //Get all the descendents of the source tab and find out if current tab is in source tab's hierarchy or not.
                            foreach (var childTab in tabController.GetTabsByPortal(portalId).DescendentsOf(redirection.SourceTabId))
                            {
                                if (childTab.TabID == currentTabId)
                                {
                                    checkFurther = true;
                                    break;
                                }
                            }
                        }
                    }
                    //redirection is based on portal
                    else if (redirection.SourceTabId == Null.NullInteger)
                    {
                        checkFurther = true;
                    }

                    if (checkFurther)
                    {
                        //check if client capability matches with this rule
                        if (DoesCapabilityMatchWithRule(clientCapability, redirection))
                        {
                            //find the redirect url
                            redirectUrl = GetRedirectUrlFromRule(redirection, portalId, currentTabId);

                            //update cache content
                            SetUrlInCache(cacheKey, redirectUrl);
                            break;
                        }
                    }
                }
            }

            return(redirectUrl);
        }
예제 #12
0
 private static bool IsMobileClient()
 {
     return((HttpContext.Current.Request.Browser != null) && (ClientCapabilityProvider.Instance() != null) && ClientCapabilityProvider.CurrentClientCapability.IsMobile);
 }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!IsPostBack)
            {
                optRedirectType.Items[1].Enabled = optRedirectType.Items[2].Enabled = ClientCapabilityProvider.Instance().SupportsTabletDetection;
                BindSettingControls();
                BindRedirection(RedirectId);
            }
            BindRedirectionCapabilties();
        }
 private static bool GenericHasHandler <T>(ClientCapabilityProvider provider, Supports <T> supports)
     where T : DynamicCapability, ConnectedCapability <IJsonRpcHandler>
 {
     return(provider.HasStaticHandler(supports));
 }
 private static bool HasHandler(ClientCapabilityProvider provider, object instance)
 {
     return((bool)typeof(ClientCapabilityProviderTests).GetTypeInfo()
            .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic)
            .MakeGenericMethod(instance.GetType().GetTypeInfo().GetGenericArguments()[0]).Invoke(null, new[] { provider, instance }));
 }
예제 #16
0
 private static bool HasHandler(ClientCapabilityProvider provider, object instance) =>
 (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo()
 .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic) !
 .MakeGenericMethod(instance.GetType().GetTypeInfo().GetGenericArguments()[0])
예제 #17
0
 private static bool HasHandler(ClientCapabilityProvider provider, Type type)
 {
     return((bool)typeof(ClientCapabilityProviderTests).GetTypeInfo()
            .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic)
            .MakeGenericMethod(type).Invoke(null, new object[] { provider, null }));
 }