public DefaultLSPRequestInvoker(ILanguageClientBroker languageClientBroker)
        {
            if (languageClientBroker is null)
            {
                throw new ArgumentNullException(nameof(languageClientBroker));
            }

            _languageClientBroker = languageClientBroker;

            // Ideally we want to call ILanguageServiceBroker2.RequestAsync directly but it is not referenced
            // because the LanguageClient.Implementation assembly isn't published to a public feed.
            // So for now, we invoke it using reflection. This will go away eventually.
            var type = _languageClientBroker.GetType();

            _requestAsyncMethod = type.GetMethod(
                "RequestAsync",
                new[]
            {
                typeof(string[]),
                typeof(Func <JToken, bool>),
                typeof(string),
                typeof(JToken),
                typeof(CancellationToken)
            });
        }
Ejemplo n.º 2
0
        public DefaultLSPRequestInvoker(ILanguageClientBroker languageClientBroker)
        {
            if (languageClientBroker is null)
            {
                throw new ArgumentNullException(nameof(languageClientBroker));
            }

            _languageClientBroker = languageClientBroker;

            // Ideally we want to call ILanguageServiceBroker2.RequestAsync directly but it is not referenced
            // because the LanguageClient.Implementation assembly isn't published to a public feed.
            // So for now, we invoke it using reflection. This will go away eventually.
            var type = _languageClientBroker.GetType();

            _requestAsyncMethod = type.GetMethod(
                "RequestAsync",
                new[]
            {
                typeof(string[]),
                typeof(Func <JToken, bool>),
                typeof(string),
                typeof(JToken),
                typeof(CancellationToken)
            });
            _synchronizedRequestAsyncMethod = type.GetMethod(
                "SynchronizedRequestAsync",
                new[]
            {
                typeof(string[]),
                typeof(Func <JToken, bool>),
                typeof(string),
                typeof(JToken),
                typeof(CancellationToken)
            });

            // The LSP platform is adding a SynchronizedRequestAsync method; however, until that change is in we need to conditionally fallback to the old RequestAsync.
            // Removal tracked by: https://github.com/dotnet/aspnetcore/issues/21468
            _synchronizedRequestAsyncMethod ??= _requestAsyncMethod;

            // We need these converters so we don't lose information as part of the deserialization.
            _serializer = new JsonSerializer();
            _serializer.Converters.Add(new VSExtensionConverter <ClientCapabilities, VSClientCapabilities>());
            _serializer.Converters.Add(new VSExtensionConverter <CompletionItem, VSCompletionItem>());
            _serializer.Converters.Add(new VSExtensionConverter <SignatureInformation, VSSignatureInformation>());
            _serializer.Converters.Add(new VSExtensionConverter <Hover, VSHover>());
            _serializer.Converters.Add(new VSExtensionConverter <ServerCapabilities, VSServerCapabilities>());
            _serializer.Converters.Add(new VSExtensionConverter <SymbolInformation, VSSymbolInformation>());
            _serializer.Converters.Add(new VSExtensionConverter <CompletionList, VSCompletionList>());
        }