예제 #1
0
        protected override async Task <CompletionDescription> GetDescriptionWorkerAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            var lspClient = _roslynLspClientServiceFactory.ActiveLanguageServerClient;

            if (lspClient == null)
            {
                return(await base.GetDescriptionWorkerAsync(document, item, cancellationToken).ConfigureAwait(false));
            }

            if (!item.Properties.TryGetValue("ResolveData", out var serializedItem))
            {
                return(await base.GetDescriptionWorkerAsync(document, item, cancellationToken).ConfigureAwait(false));
            }

            var completionItem         = JToken.Parse(serializedItem).ToObject <RoslynCompletionItem>();
            var request                = new LSP.LspRequest <RoslynCompletionItem, RoslynCompletionItem>(LSP.Methods.TextDocumentCompletionResolveName);
            var resolvedCompletionItem = await lspClient.RequestAsync(request, completionItem, cancellationToken).ConfigureAwait(false);

            if (resolvedCompletionItem?.Description == null)
            {
                return(await base.GetDescriptionWorkerAsync(document, item, cancellationToken).ConfigureAwait(false));
            }

            var parts = resolvedCompletionItem.Description.Select(tt => tt.ToTaggedText()).AsImmutable();

            return(CompletionDescription.Create(parts));
        }
예제 #2
0
        public async Task <ImmutableArray <Diagnostic> > GetDiagnosticsAsync(Document document, CancellationToken cancellationToken)
        {
            var lspClient = _roslynLspClientServiceFactory.ActiveLanguageServerClient;

            if (lspClient == null)
            {
                return(ImmutableArray <Diagnostic> .Empty);
            }

            var textDocumentParams = new TextDocumentParams
            {
                TextDocument = new LSP.TextDocumentIdentifier
                {
                    Uri = lspClient.ProtocolConverter.ToProtocolUri(new Uri(document.FilePath))
                }
            };

            var request        = new LSP.LspRequest <TextDocumentParams, RoslynDiagnostic[]>(Methods.GetDocumentDiagnosticsName);
            var lspDiagnostics = await lspClient.RequestAsync(request, textDocumentParams, cancellationToken).ConfigureAwait(false);

            if (lspDiagnostics == null)
            {
                return(ImmutableArray <Diagnostic> .Empty);
            }

            var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            var diagnostics = ImmutableArray.CreateBuilder <Diagnostic>();

            foreach (var diagnostic in lspDiagnostics)
            {
                var location = Location.Create(document.FilePath, ProtocolConversions.RangeToTextSpan(diagnostic.Range, text),
                                               ProtocolConversions.RangeToLinePositionSpan(diagnostic.Range));
                var severity = ToDiagnosticSeverity(diagnostic.Severity);
                var diag     = Diagnostic.Create(diagnostic.Code ?? "VSLS", string.Empty, diagnostic.Message, severity, severity,
                                                 true, severity == DiagnosticSeverity.Error ? 0 : 1, location: location, customTags: diagnostic.Tags);
                diagnostics.Add(diag);
            }

            return(diagnostics.ToImmutableArray());
        }
예제 #3
0
 public static LS.LspRequest <TIn, TOut> ToLSRequest <TIn, TOut>(this LSP.LspRequest <TIn, TOut> lspRequest)
 => new LS.LspRequest <TIn, TOut>(lspRequest.Name);
예제 #4
0
 public static LS.LspRequest <TIn, TOut> ToLSRequest <TIn, TOut>(this LSP.LspRequest <TIn, TOut> lspRequest)
 {
     return(new LS.LspRequest <TIn, TOut>(lspRequest.Name));
 }