Beispiel #1
0
        public async Task TestGetDocumentSymbolsAsync()
        {
            var markup =
                @"{|class:class {|classSelection:A|}
{
    {|method:void {|methodSelection:M|}()
    {
    }|}
}|}";
            var clientCapabilities = new LSP.ClientCapabilities()
            {
                TextDocument = new LSP.TextDocumentClientCapabilities()
                {
                    DocumentSymbol = new LSP.DocumentSymbolSetting()
                    {
                        HierarchicalDocumentSymbolSupport = true
                    }
                }
            };

            using var testLspServer = await CreateTestLspServerAsync(markup, clientCapabilities);

            var expected = new LSP.DocumentSymbol[]
            {
                CreateDocumentSymbol(LSP.SymbolKind.Class, "A", "A", testLspServer.GetLocations("class").Single(), testLspServer.GetLocations("classSelection").Single())
            };

            CreateDocumentSymbol(LSP.SymbolKind.Method, "M", "M()", testLspServer.GetLocations("method").Single(), testLspServer.GetLocations("methodSelection").Single(), expected.First());

            var results = await RunGetDocumentSymbolsAsync <LSP.DocumentSymbol[]>(testLspServer);

            AssertJsonEquals(expected, results);
        }
Beispiel #2
0
        public async Task TestGetDocumentSymbolsAsync()
        {
            var markup =
                @"{|class:class {|classSelection:A|}
{
    {|method:void {|methodSelection:M|}()
    {
    }|}
}|}";

            using var testLspServer = CreateTestLspServer(markup, out var locations);
            var expected = new LSP.DocumentSymbol[]
            {
                CreateDocumentSymbol(
                    LSP.SymbolKind.Class,
                    "A",
                    "A",
                    locations["class"].Single(),
                    locations["classSelection"].Single()
                    )
            };

            CreateDocumentSymbol(
                LSP.SymbolKind.Method,
                "M",
                "M()",
                locations["method"].Single(),
                locations["methodSelection"].Single(),
                expected.First()
                );

            var results = await RunGetDocumentSymbolsAsync(testLspServer, true);

            AssertJsonEquals(expected, results);
        }
Beispiel #3
0
        private static LSP.DocumentSymbol CreateDocumentSymbol(
            LSP.SymbolKind kind,
            string name,
            string detail,
            LSP.Location location,
            LSP.Location selection,
            LSP.DocumentSymbol parent = null
            )
        {
            var documentSymbol = new LSP.DocumentSymbol()
            {
                Kind           = kind,
                Name           = name,
                Range          = location.Range,
                Children       = new LSP.DocumentSymbol[0],
                Detail         = detail,
                Deprecated     = false,
                SelectionRange = selection.Range
            };

            if (parent != null)
            {
                var children = parent.Children.ToList();
                children.Add(documentSymbol);
                parent.Children = children.ToArray();
            }

            return(documentSymbol);
        }
Beispiel #4
0
 private static void AssertDocumentSymbolEquals(LSP.DocumentSymbol expected, LSP.DocumentSymbol actual)
 {
     Assert.Equal(expected.Kind, actual.Kind);
     Assert.Equal(expected.Name, actual.Name);
     Assert.Equal(expected.Range, actual.Range);
     Assert.Equal(expected.Children.Length, actual.Children.Length);
     for (var i = 0; i < actual.Children.Length; i++)
     {
         AssertDocumentSymbolEquals(expected.Children[i], actual.Children[i]);
     }
 }