Ejemplo n.º 1
0
        public async Task TestStreamingDocumentDiagnostics()
        {
            var markup = @"class A {";

            using var testLspServer = CreateTestWorkspaceWithDiagnostics(
                      markup,
                      BackgroundAnalysisScope.OpenFilesAndProjects
                      );

            // Calling GetTextBuffer will effectively open the file.
            testLspServer.TestWorkspace.Documents.Single().GetTextBuffer();

            var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();

            await OpenDocumentAsync(testLspServer, document);

            var progress = BufferedProgress.Create <DiagnosticReport>(null);
            var results  = await RunGetDocumentPullDiagnosticsAsync(
                testLspServer,
                testLspServer.GetCurrentSolution().Projects.Single().Documents.Single(),
                progress : progress
                );

            Assert.Null(results);
            Assert.Equal("CS1513", progress.GetValues() !.Single().Diagnostics.Single().Code);
        }
Ejemplo n.º 2
0
        public async Task TestStreamingWorkspaceDiagnostics()
        {
            var markup1 =
                @"class A {";
            var markup2 = "";

            using var workspace = CreateTestWorkspaceWithDiagnostics(
                      new[] { markup1, markup2 }, BackgroundAnalysisScope.FullSolution);

            var queue  = CreateRequestQueue(workspace.CurrentSolution);
            var server = GetLanguageServer(workspace.CurrentSolution);

            var results = await RunGetWorkspacePullDiagnosticsAsync(workspace, queue, server);

            Assert.Equal(2, results.Length);
            Assert.Equal("CS1513", results[0].Diagnostics.Single().Code);
            Assert.Equal(new Position {
                Line = 0, Character = 9
            }, results[0].Diagnostics.Single().Range.Start);

            var progress = BufferedProgress.Create <DiagnosticReport>(null);

            results = await RunGetWorkspacePullDiagnosticsAsync(workspace, queue, server, progress : progress);

            Assert.Null(results);
            Assert.Equal("CS1513", progress.GetValues() ![0].Diagnostics ![0].Code);
        public async Task <TReport[]?> HandleRequestAsync(TDiagnosticsParams diagnosticsParams, RequestContext context, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(context.Solution);

            using var progress = BufferedProgress.Create(GetProgress(diagnosticsParams));

            // Get the set of results the request said were previously reported.
            var previousResults = GetPreviousResults(diagnosticsParams);

            var documentToPreviousResultId = new Dictionary <Document, string?>();

            if (previousResults != null)
            {
                // Go through the previousResults and check if we need to remove diagnostic information for any documents
                foreach (var previousResult in previousResults)
                {
                    if (previousResult.TextDocument != null)
                    {
                        var document = context.Solution.GetDocument(previousResult.TextDocument);
                        if (document == null)
                        {
                            // We can no longer get this document, return null for both diagnostics and resultId
                            progress.Report(CreateReport(previousResult.TextDocument, diagnostics: null, resultId: null));
                        }
                        else
                        {
                            // Cache the document to previousResultId mapping so we can easily retrieve the resultId later.
                            documentToPreviousResultId[document] = previousResult.PreviousResultId;
                        }
                    }
                }
            }

            // Go through the documents that we need to process and call XamlPullDiagnosticService to get the diagnostic report
            foreach (var document in GetDocuments(context))
            {
                var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

                var documentId = ProtocolConversions.DocumentToTextDocumentIdentifier(document);

                // If we can get a previousId of the document, use it,
                // otherwise use null as the previousId to pass into the XamlPullDiagnosticService
                var previousResultId = documentToPreviousResultId.TryGetValue(document, out var id) ? id : null;

                // Call XamlPullDiagnosticService to get the diagnostic report for this document.
                // We will compute what to report inside XamlPullDiagnosticService, for example, whether we should keep using the previousId or use a new resultId,
                // and the handler here just return the result get from XamlPullDiagnosticService.
                var diagnosticReport = await _xamlDiagnosticService.GetDiagnosticReportAsync(document, previousResultId, cancellationToken).ConfigureAwait(false);

                progress.Report(CreateReport(
                                    documentId,
                                    ConvertToVSDiagnostics(diagnosticReport.Diagnostics, document, text),
                                    diagnosticReport.ResultId));
            }

            return(progress.GetValues());
        }
Ejemplo n.º 4
0
        private async Task <SymbolInformation[]?> SearchAsync(Solution solution, WorkspaceSymbolParams args, CancellationToken cancellationToken)
        {
            using var progress = BufferedProgress.Create(args.PartialResultToken);

            var tasks = solution.Projects.SelectMany(p => p.Documents).Select(d => SearchDocumentAndReportSymbolsAsync(d, args.Query, progress, cancellationToken));
            await Task.WhenAll(tasks).ConfigureAwait(false);

            return(progress.GetValues());
        }
Ejemplo n.º 5
0
 protected override VSInternalDiagnosticReport[]? CreateReturn(BufferedProgress <VSInternalDiagnosticReport> progress)
 {
     return(progress.GetValues());
 }