Exemple #1
0
        public async Task <CompletionItem?> HandleRequestAsync(CompletionItem request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
        {
            if (request.Data is null)
            {
                _logger.LogInformation("Received no completion resolve data.");
                return(request);
            }

            _logger.LogInformation("Starting request to resolve completion.");

            var resolveData = request.Data is CompletionResolveData data ? data : ((JToken)request.Data).ToObject <CompletionResolveData>();

            if (resolveData is null)
            {
                _logger.LogInformation("CompletionResolveData failed to serialize.");
                return(request);
            }

            // Set the original resolve data back so the language server deserializes it correctly.
            request.Data = resolveData.OriginalData;

            if (!_completionRequestContextCache.TryGet(resolveData.ResultId, out var requestContext))
            {
                _logger.LogInformation("Could not find the associated request context.");
                return(request);
            }

            if (!_documentManager.TryGetDocument(requestContext.HostDocumentUri, out var documentSnapshot))
            {
                _logger.LogError("Could not find the associated host document for completion resolve: {0}.", requestContext.HostDocumentUri);
                return(request);
            }

            var serverKind         = requestContext.LanguageServerKind;
            var languageServerName = serverKind.ToLanguageServerName();
            var textBuffer         = serverKind.GetTextBuffer(documentSnapshot);
            var response           = await _requestInvoker.ReinvokeRequestOnServerAsync <CompletionItem, CompletionItem>(
                textBuffer,
                Methods.TextDocumentCompletionResolveName,
                languageServerName,
                request,
                cancellationToken).ConfigureAwait(false);

            if (!ReinvocationResponseHelper.TryExtractResultOrLog(response, _logger, RazorLSPConstants.RazorCSharpLanguageServerName, out var result))
            {
                return(request);
            }

            _logger.LogInformation("Received result, post-processing.");

            var postProcessedResult = await PostProcessCompletionItemAsync(request, result, requestContext, documentSnapshot, cancellationToken).ConfigureAwait(false);

            _logger.LogInformation("Returning resolved completion.");
            return(postProcessedResult);
        }
        public async Task <CompletionItem> HandleRequestAsync(CompletionItem request, ClientCapabilities clientCapabilities, CancellationToken cancellationToken)
        {
            if (request?.Data == null)
            {
                _logger.LogInformation("Received no completion resolve data.");
                return(request);
            }

            _logger.LogInformation("Starting request to resolve completion.");

            CompletionResolveData resolveData;

            if (request.Data is CompletionResolveData data)
            {
                resolveData = data;
            }
            else
            {
                resolveData = ((JToken)request.Data).ToObject <CompletionResolveData>();
            }

            // Set the original resolve data back so the language server deserializes it correctly.
            request.Data = resolveData.OriginalData;

            if (!_completionRequestContextCache.TryGet(resolveData.ResultId, out var requestContext))
            {
                _logger.LogInformation("Could not find the associated request context.");
                return(request);
            }

            var serverContentType = requestContext.LanguageServerKind.ToContentType();
            var result            = await _requestInvoker.ReinvokeRequestOnServerAsync <CompletionItem, CompletionItem>(
                Methods.TextDocumentCompletionResolveName,
                serverContentType,
                request,
                cancellationToken).ConfigureAwait(false);

            _logger.LogInformation("Received result, post-processing.");

            result = await PostProcessCompletionItemAsync(request, result, requestContext, cancellationToken).ConfigureAwait(false);

            _logger.LogInformation("Returning resolved completion.");
            return(result);
        }