Exemple #1
0
        public async Task DidChange_MultipleChanges()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";
            var expected =
                @"class A
{
    void M()
    {
        // hi there
        // this builds on that
    }
}";

            var(testLspServer, locationTyped, documentText) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                await DidOpen(testLspServer, CreateDidOpenTextDocumentParams(locationTyped, documentText));

                await DidChange(testLspServer, CreateDidChangeTextDocumentParams(locationTyped.Uri, (4, 8, "// hi there"), (5, 0, "        // this builds on that\r\n")));

                var document = testLspServer.GetQueueAccessor().GetTrackedTexts().FirstOrDefault();

                Assert.NotNull(document);
                Assert.Equal(expected, document.ToString());
            }
        }
Exemple #2
0
        public async Task DidChange_AppliesChanges()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";
            var expected =
                @"class A
{
    void M()
    {
        // hi there
    }
}";

            var(testLspServer, locationTyped, _) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                await DidOpen(testLspServer, locationTyped.Uri);

                await DidChange(testLspServer, locationTyped.Uri, (4, 8, "// hi there"));

                var document = testLspServer.GetQueueAccessor().GetTrackedTexts().FirstOrDefault();

                Assert.NotNull(document);
                Assert.Equal(expected, document.ToString());
            }
        }
Exemple #3
0
        public async Task LinkedDocuments_AllTextChanged()
        {
            var initialText =
                @"class A
{
    void M()
    {
        {|caret:|}
    }
}";
            var workspaceXml =
                @$ "<Workspace>
    <Project Language=" "C#" " CommonReferences=" "true" " AssemblyName=" "CSProj1" ">
        <Document FilePath=" "C:\C.cs" ">{initialText}</Document>
    </Project>
    <Project Language=" "C#" " CommonReferences=" "true" " AssemblyName=" "CSProj2" ">
        <Document IsLinkFile=" "true" " LinkFilePath=" "C:\C.cs" " LinkAssemblyName=" "CSProj1" "></Document>
    </Project>
</Workspace>";

            using var testLspServer = await CreateXmlTestLspServerAsync(workspaceXml);

            var caretLocation = testLspServer.GetLocations("caret").Single();

            var updatedText =
                @"class A
{
    void M()
    {
        // hi there
    }
}";

            await DidOpen(testLspServer, caretLocation.Uri);

            Assert.Equal(1, testLspServer.GetQueueAccessor().GetTrackedTexts().Length);

            await DidChange(testLspServer, caretLocation.Uri, (4, 8, "// hi there"));

            var solution = await GetLSPSolution(testLspServer, caretLocation.Uri);

            foreach (var document in solution.Projects.First().Documents)
            {
                Assert.Equal(updatedText, document.GetTextSynchronously(CancellationToken.None).ToString());
            }

            await DidClose(testLspServer, caretLocation.Uri);

            Assert.Empty(testLspServer.GetQueueAccessor().GetTrackedTexts());
        }
Exemple #4
0
        public async Task DidChangeWithoutDidOpen_Errors()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";

            var(testLspServer, locationTyped, documentText) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                await Assert.ThrowsAsync <InvalidOperationException>(() => DidChange(testLspServer, locationTyped.Uri, (0, 0, "goo")));
            }
        }
Exemple #5
0
        public async Task DocumentChanges_EndToEnd()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";
            var expected =
                @"class A
{
    void M()
    {
        // hi there
    }
}";

            var(testLspServer, locationTyped, documentText) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                Assert.Empty(testLspServer.GetQueueAccessor().GetTrackedTexts());

                await DidOpen(testLspServer, locationTyped.Uri);

                Assert.Single(testLspServer.GetQueueAccessor().GetTrackedTexts());

                var document = testLspServer.GetQueueAccessor().GetTrackedTexts().Single();
                Assert.Equal(documentText, document.ToString());

                await DidChange(testLspServer, locationTyped.Uri, (4, 8, "// hi there"));

                document = testLspServer.GetQueueAccessor().GetTrackedTexts().Single();
                Assert.Equal(expected, document.ToString());

                await DidClose(testLspServer, locationTyped.Uri);

                Assert.Empty(testLspServer.GetQueueAccessor().GetTrackedTexts());
            }
        }
Exemple #6
0
        public async Task DidChange_DoesntUpdateWorkspace()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";
            var expected =
                @"class A
{
    void M()
    {
        // hi there
    }
}";

            var(testLspServer, locationTyped, documentText) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                await DidOpen(testLspServer, locationTyped.Uri);

                await DidChange(testLspServer, locationTyped.Uri, (4, 8, "// hi there"));

                var documentTextFromWorkspace = (await testLspServer.GetCurrentSolution().GetDocuments(locationTyped.Uri).Single().GetTextAsync()).ToString();

                Assert.NotNull(documentTextFromWorkspace);
                Assert.Equal(documentText, documentTextFromWorkspace);

                // Just to ensure this test breaks if didChange stops working for some reason
                Assert.NotEqual(expected, documentTextFromWorkspace);
            }
        }
        public async Task DidChange_MultipleChanges()
        {
            var source =
                @"class A
{
    void M()
    {
        {|type:|}
    }
}";
            var expected =
                @"class A
{
    void M()
    {
        // hi there
        // this builds on that
    }
}";

            var(workspace, locationTyped, documentText) = await GetWorkspaceAndLocationAsync(source);

            using (workspace)
            {
                var queue = CreateRequestQueue(workspace.CurrentSolution);

                await DidOpen(queue, workspace.CurrentSolution, CreateDidOpenTextDocumentParams(locationTyped, documentText));

                await DidChange(queue, workspace.CurrentSolution, CreateDidChangeTextDocumentParams(locationTyped.Uri, (4, 8, "// hi there"), (5, 0, "        // this builds on that\r\n")));

                var document = queue.GetTestAccessor().GetTrackedTexts().FirstOrDefault();

                Assert.NotNull(document);
                Assert.Equal(expected, document.ToString());
            }
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_forbiddenQuery.CalculateEntityCount() > 0)
            {
                throw new System.Exception($"Entity can't have 'LookAtEntityComponent' and 'LookAtPositionComponent' at the same time");
            }
            inputDeps = new LookAtEntityJob {
                LocalToWorldFromEntity = GetComponentDataFromEntity <LocalToWorld>(true),
                ParentFromEntity       = GetComponentDataFromEntity <Parent>(true),
                LookFromEntity         = GetComponentDataFromEntity <LookAtEntity>(true)
            }.Schedule(this, inputDeps);


            inputDeps = JobHandle.CombineDependencies(
                m_changedLookAtEntities.Clear(inputDeps, m_query.CalculateEntityCount()),
                m_lookAtEntities.Clear(inputDeps, m_query.CalculateEntityCount()));

            inputDeps = new GatherLookAtEntities {
                LookAtEntities = m_lookAtEntities.AsParallelWriter()
            }.Schedule(this, inputDeps);

            inputDeps = new GatherLookAtEntityPlanes {
                LookAtEntities = m_lookAtEntities.AsParallelWriter()
            }.Schedule(this, inputDeps);

            inputDeps = new DidChange {
                LookAtEntities  = m_lookAtEntities,
                ChangedEntities = m_changedLookAtEntities.AsParallelWriter()
            }.Schedule(this, inputDeps);

            inputDeps = new LookAtEntityPlaneJob {
                LookAtType             = GetArchetypeChunkComponentType <LookAtEntityPlane>(true),
                LocalToWorldType       = GetArchetypeChunkComponentType <LocalToWorld>(false),
                LocalToWorldFromEntity = GetComponentDataFromEntity <LocalToWorld>(true),
                ParentFromEntity       = GetComponentDataFromEntity <Parent>(true),
                LookFromEntity         = GetComponentDataFromEntity <LookAtEntityPlane>(true),
                ChangedLookAtEntities  = m_changedLookAtEntities,
                LastSystemVersion      = LastSystemVersion
            }.Schedule(m_query, inputDeps);
            inputDeps = new LookAtPositionJob {
                LocalToWorldFromEntity = GetComponentDataFromEntity <LocalToWorld>(true),
                ParentFromEntity       = GetComponentDataFromEntity <Parent>(true),
                LookFromEntity         = GetComponentDataFromEntity <LookAtPosition>(true)
            }.Schedule(this, inputDeps);
            return(inputDeps);
        }
        public async Task FindReferencesInChangingDocument()
        {
            var source =
                @"class A
{
    public int {|type:|}someInt = 1;
    void M()
    {
    }
}
class B
{
    void M2()
    {
    }
}";

            var(testLspServer, locationTyped, _) = await GetTestLspServerAndLocationAsync(source);

            using (testLspServer)
            {
                Assert.Empty(testLspServer.GetQueueAccessor().GetTrackedTexts());

                await DidOpen(testLspServer, locationTyped.Uri);

                var findResults = await FindAllReferencesHandlerTests.RunFindAllReferencesAsync(testLspServer, locationTyped);

                Assert.Single(findResults);

                Assert.Equal("A", findResults[0].ContainingType);

                // Declare a local inside A.M()
                await DidChange(testLspServer, locationTyped.Uri, (5, 0, "var i = someInt + 1;\r\n"));

                findResults = await FindAllReferencesHandlerTests.RunFindAllReferencesAsync(testLspServer, locationTyped);

                Assert.Equal(2, findResults.Length);

                Assert.Equal("A", findResults[0].ContainingType);
                Assert.Equal("M", findResults[1].ContainingMember);

                // Declare a field in B
                await DidChange(testLspServer, locationTyped.Uri, (10, 0, "int someInt = A.someInt + 1;\r\n"));

                findResults = await FindAllReferencesHandlerTests.RunFindAllReferencesAsync(testLspServer, locationTyped);

                Assert.Equal(3, findResults.Length);

                Assert.Equal("A", findResults[0].ContainingType);
                Assert.Equal("B", findResults[2].ContainingType);
                Assert.Equal("M", findResults[1].ContainingMember);

                // Declare a local inside B.M2()
                await DidChange(testLspServer, locationTyped.Uri, (13, 0, "var j = someInt + A.someInt;\r\n"));

                findResults = await FindAllReferencesHandlerTests.RunFindAllReferencesAsync(testLspServer, locationTyped);

                Assert.Equal(4, findResults.Length);

                Assert.Equal("A", findResults[0].ContainingType);
                Assert.Equal("B", findResults[2].ContainingType);
                Assert.Equal("M", findResults[1].ContainingMember);
                Assert.Equal("M2", findResults[3].ContainingMember);

                // NOTE: This is not a real world scenario
                // By closing the document we revert back to the original state, but in the real world
                // the original state will have been updated by back channels (text buffer sync, file changed on disk, etc.)
                // This is validating that the above didn't succeed by any means except the FAR handler being passed
                // the updated document, so if we regress and get lucky, we still know about it.
                await DidClose(testLspServer, locationTyped.Uri);

                findResults = await FindAllReferencesHandlerTests.RunFindAllReferencesAsync(testLspServer, locationTyped);

                Assert.Single(findResults);

                Assert.Equal("A", findResults[0].ContainingType);
            }
        }