public async Task AddDiagnosticWithMappedFilesTestAsync()
        {
            using var workspace = CreateTestLspServer("", out _).TestWorkspace;
            var document = workspace.CurrentSolution.Projects.First().Documents.First();

            var diagnosticsMock = new Mock <IDiagnosticService>(MockBehavior.Strict);

            // Create two mapped diagnostics for the document.
            SetupMockWithDiagnostics(diagnosticsMock, document.Id,
                                     await CreateMockDiagnosticDatasWithMappedLocationAsync(document, ("id1", document.FilePath + "m1"), ("id2", document.FilePath + "m2")).ConfigureAwait(false));

            // Publish one document change diagnostic notification ->
            // 1.  doc1 with id1 = mapped file m1 and id2 = mapped file m2.
            //
            // We expect two publish diagnostic notifications ->
            // 1.  from m1 with id1 (from 1 above).
            // 2.  from m2 with id2 (from 1 above).
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(workspace, diagnosticsMock.Object, expectedNumberOfCallbacks : 2, document).ConfigureAwait(false);

            Assert.Equal(2, results.Count);
            Assert.Equal(new Uri(document.FilePath + "m1"), results[0].Uri);
            Assert.Equal("id1", results[0].Diagnostics.Single().Code);

            Assert.Equal(new Uri(document.FilePath + "m2"), results[1].Uri);
            Assert.Equal("id2", results[1].Diagnostics.Single().Code);
        }
Example #2
0
        public async Task ClearAllDiagnosticsForMappedFilesTestAsync()
        {
            using var workspace = CreateTestLspServer("", out _).TestWorkspace;
            var document = workspace.CurrentSolution.Projects.First().Documents.First();

            var diagnosticsMock  = new Mock <IDiagnosticService>(MockBehavior.Strict);
            var mappedFilePathM1 = document.FilePath + "m1";
            var mappedFilePathM2 = document.FilePath + "m2";

            // Create two mapped diagnostics for the document on first call.
            // On the second call, return only empty diagnostics.
            SetupMockDiagnosticSequence(
                diagnosticsMock,
                document.Id,
                await CreateMockDiagnosticDatasWithMappedLocationAsync(
                    document,
                    ("id1", mappedFilePathM1),
                    ("id2", mappedFilePathM2)
                    )
                .ConfigureAwait(false),
                ImmutableArray <DiagnosticData> .Empty
                );

            // Publish two document change diagnostic notifications ->
            // 1.  doc1 with id1 = mapped file m1 and id2 = mapped file m2.
            // 2.  doc1 with empty.
            //
            // We expect four publish diagnostic notifications - the first two are the two mapped files from 1.
            // The second two are the two mapped files being cleared by 2.
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(
                workspace,
                diagnosticsMock.Object,
                4,
                document,
                document
                )
                                         .ConfigureAwait(false);

            var mappedFileURIM1 = new Uri(document.FilePath + "m1");
            var mappedFileURIM2 = new Uri(document.FilePath + "m2");

            Assert.Equal(4, results.Count);

            // Document's first update.
            Assert.Equal(mappedFileURIM1, results[0].Uri);
            Assert.Equal("id1", results[0].Diagnostics.Single().Code);

            Assert.Equal(mappedFileURIM2, results[1].Uri);
            Assert.Equal("id2", results[1].Diagnostics.Single().Code);

            // Document's second update.
            Assert.Equal(mappedFileURIM1, results[2].Uri);
            Assert.True(results[2].Diagnostics.IsEmpty());

            Assert.Equal(mappedFileURIM2, results[3].Uri);
            Assert.True(results[3].Diagnostics.IsEmpty());

            Assert.Empty(testAccessor.GetDocumentIdsInPublishedUris());
            Assert.Empty(testAccessor.GetFileUrisInPublishDiagnostics());
        }
Example #3
0
        public async Task ClearAllDiagnosticsForMappedFileToManyDocumentsTestAsync()
        {
            using var server = await CreateTestLspServerAsync(new string[] { "", "" });

            var workspace = server.TestWorkspace;
            var documents = workspace.CurrentSolution.Projects.First().Documents.ToImmutableArray();

            var diagnosticsMock = new Mock <IDiagnosticService>(MockBehavior.Strict);
            // Create diagnostic for the first document that has a mapped location.
            var mappedFilePath        = documents[0].FilePath + "m1";
            var documentOneDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(documents[0], ("doc1Diagnostic", mappedFilePath)).ConfigureAwait(false);

            // Create diagnostic for the second document that maps to the same location as the first document diagnostic.
            var documentTwoDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(documents[1], ("doc2Diagnostic", mappedFilePath)).ConfigureAwait(false);

            // On the first call for the documents, return the mapped diagnostic.  On the second, return nothing.
            SetupMockDiagnosticSequence(diagnosticsMock, documents[0].Id, documentOneDiagnostic, ImmutableArray <DiagnosticData> .Empty);
            SetupMockDiagnosticSequence(diagnosticsMock, documents[1].Id, documentTwoDiagnostic, ImmutableArray <DiagnosticData> .Empty);

            // Publish four document change diagnostic notifications ->
            // 1.  doc1 with doc1Diagnostic = mapped file m1.
            // 2.  doc2 with doc2Diagnostic = mapped file m1.
            // 3.  doc1 with empty diagnostics.
            // 4.  doc2 with empty diagnostics.
            //
            // We expect four publish diagnostics ->
            // 1.  from URI m1 with doc1Diagnostic (triggered by 1 above to add doc1Diagnostic).
            // 2.  from URI m1 with doc1Diagnostic and doc2Diagnostic (triggered by 2 above to add doc2Diagnostic).
            // 3.  from URI m1 with just doc2Diagnostic (triggered by 3 above to clear doc1 diagnostic).
            // 4.  from URI m1 with empty (triggered by 4 above to also clear doc2 diagnostic).
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(workspace, diagnosticsMock.Object, 4, documents[0], documents[1], documents[0], documents[1]).ConfigureAwait(false);

            Assert.Equal(4, results.Count);
            var expectedUri = new Uri(mappedFilePath);

            Assert.Equal(expectedUri, results[0].Uri);
            Assert.Equal("doc1Diagnostic", results[0].Diagnostics.Single().Code);

            Assert.Equal(expectedUri, results[1].Uri);
            Assert.Equal(2, results[1].Diagnostics.Length);
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc1Diagnostic");
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc2Diagnostic");

            Assert.Equal(expectedUri, results[2].Uri);
            Assert.Equal(1, results[2].Diagnostics.Length);
            Assert.Contains(results[2].Diagnostics, d => d.Code == "doc2Diagnostic");

            Assert.Equal(expectedUri, results[3].Uri);
            Assert.True(results[3].Diagnostics.IsEmpty());

            Assert.Empty(testAccessor.GetDocumentIdsInPublishedUris());
            Assert.Empty(testAccessor.GetFileUrisInPublishDiagnostics());
        }
Example #4
0
        public async Task RemoveDiagnosticForMappedFilesTestAsync()
        {
            using var server = await CreateTestLspServerAsync("");

            var workspace = server.TestWorkspace;
            var document  = workspace.CurrentSolution.Projects.First().Documents.First();

            var diagnosticsMock = new Mock <IDiagnosticService>(MockBehavior.Strict);

            var mappedFilePathM1 = document.FilePath + "m1";
            var mappedFilePathM2 = document.FilePath + "m2";

            // Create two mapped diagnostics for the document on first call.
            // On the second call, return only the second mapped diagnostic for the document.
            SetupMockDiagnosticSequence(diagnosticsMock, document.Id,
                                        await CreateMockDiagnosticDatasWithMappedLocationAsync(document, ("id1", mappedFilePathM1), ("id2", mappedFilePathM2)).ConfigureAwait(false),
                                        await CreateMockDiagnosticDatasWithMappedLocationAsync(document, ("id2", mappedFilePathM2)).ConfigureAwait(false));

            // Publish three document change diagnostic notifications ->
            // 1.  doc1 with id1 = mapped file m1 and id2 = mapped file m2.
            // 2.  doc1 with just id2 = mapped file m2.
            //
            // We expect four publish diagnostic notifications ->
            // 1.  from m1 with id1 (from 1 above).
            // 2.  from m2 with id2 (from 1 above).
            // 3.  from m1 with empty (from 2 above clearing out diagnostics for m1).
            // 4.  from m2 with id2 (from 2 above clearing out diagnostics for m1).
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(workspace, diagnosticsMock.Object, 4, document, document).ConfigureAwait(false);

            var mappedFileURIM1 = new Uri(mappedFilePathM1);
            var mappedFileURIM2 = new Uri(mappedFilePathM2);

            Assert.Equal(4, results.Count);

            // First document update.
            Assert.Equal(mappedFileURIM1, results[0].Uri);
            Assert.Equal("id1", results[0].Diagnostics.Single().Code);

            Assert.Equal(mappedFileURIM2, results[1].Uri);
            Assert.Equal("id2", results[1].Diagnostics.Single().Code);

            // Second document update.
            Assert.Equal(mappedFileURIM1, results[2].Uri);
            Assert.True(results[2].Diagnostics.IsEmpty());

            Assert.Equal(mappedFileURIM2, results[3].Uri);
            Assert.Equal("id2", results[3].Diagnostics.Single().Code);

            Assert.Single(testAccessor.GetFileUrisForDocument(document.Id), mappedFileURIM2);
            Assert.Equal("id2", testAccessor.GetDiagnosticsForUriAndDocument(document.Id, mappedFileURIM2).Single().Code);
            Assert.Empty(testAccessor.GetDiagnosticsForUriAndDocument(document.Id, mappedFileURIM1));
        }
Example #5
0
        public async Task AddDiagnosticWithMappedFileToManyDocumentsTestAsync()
        {
            using var workspace = CreateTestLspServer(new string[] { "", "" }, out _).TestWorkspace;
            var documents = workspace.CurrentSolution.Projects.First().Documents.ToImmutableArray();

            var diagnosticsMock = new Mock <IDiagnosticService>(MockBehavior.Strict);
            // Create diagnostic for the first document that has a mapped location.
            var mappedFilePath        = documents[0].FilePath + "m1";
            var documentOneDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(
                documents[0],
                ("doc1Diagnostic", mappedFilePath)
                )
                                        .ConfigureAwait(false);

            // Create diagnostic for the second document that maps to the same location as the first document diagnostic.
            var documentTwoDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(
                documents[1],
                ("doc2Diagnostic", mappedFilePath)
                )
                                        .ConfigureAwait(false);

            SetupMockWithDiagnostics(diagnosticsMock, documents[0].Id, documentOneDiagnostic);
            SetupMockWithDiagnostics(diagnosticsMock, documents[1].Id, documentTwoDiagnostic);

            // Publish two document change diagnostic notifications ->
            // 1.  doc1 with doc1Diagnostic = mapped file m1.
            // 2.  doc2 with doc2Diagnostic = mapped file m1.
            //
            // We expect two publish diagnostic notifications ->
            // 1.  from m1 with doc1Diagnostic (from 1 above).
            // 2.  from m1 with doc1Diagnostic and doc2Diagnostic (from 2 above adding doc2Diagnostic to m1).
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(
                workspace,
                diagnosticsMock.Object,
                2,
                documents[0],
                documents[1]
                )
                                         .ConfigureAwait(false);

            Assert.Equal(2, results.Count);
            var expectedUri = new Uri(mappedFilePath);

            Assert.Equal(expectedUri, results[0].Uri);
            Assert.Equal("doc1Diagnostic", results[0].Diagnostics.Single().Code);

            Assert.Equal(expectedUri, results[1].Uri);
            Assert.Equal(2, results[1].Diagnostics.Length);
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc1Diagnostic");
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc2Diagnostic");
        }
        public async Task RemoveDiagnosticForMappedFileToManyDocumentsTestAsync()
        {
            using var workspace = CreateTestLspServer(new string[] { "", "" }, out _).TestWorkspace;
            var documents = workspace.CurrentSolution.Projects.First().Documents.ToImmutableArray();

            var diagnosticsMock = new Mock <IDiagnosticService>(MockBehavior.Strict);
            // Create diagnostic for the first document that has a mapped location.
            var mappedFilePath        = documents[0].FilePath + "m1";
            var documentOneDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(documents[0], ("doc1Diagnostic", mappedFilePath)).ConfigureAwait(false);

            // Create diagnostic for the second document that maps to the same location as the first document diagnostic.
            var documentTwoDiagnostic = await CreateMockDiagnosticDatasWithMappedLocationAsync(documents[1], ("doc2Diagnostic", mappedFilePath)).ConfigureAwait(false);

            // On the first call for this document, return the mapped diagnostic.  On the second, return nothing.
            SetupMockDiagnosticSequence(diagnosticsMock, documents[0].Id, documentOneDiagnostic, ImmutableArray <DiagnosticData> .Empty);
            // Always return the mapped diagnostic for this document.
            SetupMockWithDiagnostics(diagnosticsMock, documents[1].Id, documentTwoDiagnostic);

            // Publish three document change diagnostic notifications ->
            // 1.  doc1 with doc1Diagnostic = mapped file path m1
            // 2.  doc2 with doc2Diagnostic = mapped file path m1
            // 3.  doc1 with empty.
            //
            // We expect three publish diagnostics ->
            // 1.  from m1 with doc1Diagnostic (triggered by 1 above to add doc1Diagnostic).
            // 2.  from m1 with doc1Diagnostic and doc2Diagnostic (triggered by 2 above to add doc2Diagnostic).
            // 3.  from m1 with just doc2Diagnostic (triggered by 3 above to remove doc1Diagnostic).
            var(testAccessor, results) = await RunPublishDiagnosticsAsync(workspace, diagnosticsMock.Object, 3, documents[0], documents[1], documents[0]).ConfigureAwait(false);

            Assert.Equal(3, results.Count);
            var expectedUri = new Uri(mappedFilePath);

            Assert.Equal(expectedUri, results[0].Uri);
            Assert.Equal("doc1Diagnostic", results[0].Diagnostics.Single().Code);

            Assert.Equal(expectedUri, results[1].Uri);
            Assert.Equal(2, results[1].Diagnostics.Length);
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc1Diagnostic");
            Assert.Contains(results[1].Diagnostics, d => d.Code == "doc2Diagnostic");

            Assert.Equal(expectedUri, results[2].Uri);
            Assert.Equal(1, results[2].Diagnostics.Length);
            Assert.Contains(results[2].Diagnostics, d => d.Code == "doc2Diagnostic");

            Assert.Single(testAccessor.GetFileUrisForDocument(documents[1].Id), expectedUri);
            Assert.Equal("doc2Diagnostic", testAccessor.GetDiagnosticsForUriAndDocument(documents[1].Id, expectedUri).Single().Code);
            Assert.Empty(testAccessor.GetDiagnosticsForUriAndDocument(documents[0].Id, expectedUri));
        }