private DocumentSymbol ToDocumentSymbol(IMemberResult m, Dictionary <IMemberResult, List <IMemberResult> > childMap, int currentDepth)
        {
            var res = new DocumentSymbol {
                name          = m.Name,
                detail        = m.Name,
                kind          = ToSymbolKind(m.MemberType),
                deprecated    = false,
                _functionKind = GetFunctionKind(m)
            };

            if (childMap.TryGetValue(m, out var children) && currentDepth < _symbolHierarchyDepthLimit)
            {
                res.children = children
                               .Select(x => ToDocumentSymbol(x, childMap, currentDepth + 1))
                               .ToArray();
            }
            else
            {
                res.children = Array.Empty <DocumentSymbol>();
            }

            var loc = m.Locations.FirstOrDefault(l => !string.IsNullOrEmpty(l.FilePath));

            if (loc != null)
            {
                res.range = new SourceSpan(
                    new SourceLocation(loc.StartLine, loc.StartColumn),
                    new SourceLocation(loc.EndLine ?? loc.StartLine, loc.EndColumn ?? loc.StartColumn)
                    );
                res.selectionRange = res.range;
            }
            return(res);
        }
示例#2
0
 public DocumentSymbolData(DocumentSymbol documentSymbol, SnapshotSpan rangeSpan, SnapshotSpan selectionRangeSpan, ImmutableArray <DocumentSymbolData> children)
 {
     Name               = documentSymbol.Name;
     SymbolKind         = documentSymbol.Kind;
     RangeSpan          = rangeSpan;
     SelectionRangeSpan = selectionRangeSpan;
     Children           = children;
 }
 public void AddSymbol(DocumentSymbol ds)
 {
     if (Scopes.Count > 0)
     {
         Scopes.Peek().Children.Add(ds);
     }
     else
     {
         Symbols.Add(ds);
     }
 }
示例#4
0
        public DocumentSymbol Parse(string content)
        {
            var splitContent = content.Split('\n').Select(x => x.TrimEnd());
            var lines        = new Queue <string>(splitContent);

            RegisterParsers();
            var symbols = ProcessLines(lines);

            var doc = new DocumentSymbol(symbols);

            return(doc);
        }
示例#5
0
        public DocumentSymbol Parse(string content)
        {
            var lines = content.Split('\n').Select(x => x.TrimEnd());

            _lines   = new Queue <string>(lines);
            _symbols = new List <Symbol>();

            while (_lines.Count > 0)
            {
                ProcessLines();
            }

            var doc = new DocumentSymbol(_symbols);

            return(doc);
        }
        public async Task DocumentSymbols_DocumentSymbol_Success()
        {
            await Connect();

            const int line                 = 5;
            const int character            = 6;
            var       expectedDocumentPath = AbsoluteDocumentPath;
            var       expectedDocumentUri  = DocumentUri.FromFileSystemPath(expectedDocumentPath);
            var       detail               = "some detail";

            var documentSymbol = new DocumentSymbol {
                Detail = detail,
                Kind   = SymbolKind.Class,
                Range  = new Range(new Position(line, character), new Position(line, character))
            };
            var expectedSymbols = new SymbolInformationOrDocumentSymbolContainer(
                new SymbolInformationOrDocumentSymbol(documentSymbol));

            ServerDispatcher.HandleRequest <DocumentSymbolParams, SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, (request, cancellationToken) => {
                Assert.NotNull(request.TextDocument);

                Assert.Equal(expectedDocumentUri, request.TextDocument.Uri);

                return(Task.FromResult(expectedSymbols));
            });
            var documentSymbolParams = new DocumentSymbolParams {
                TextDocument = new TextDocumentIdentifier(expectedDocumentUri)
            };
            var symbols = await LanguageClient.SendRequest <SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, documentSymbolParams);

            var actualSymbols = symbols.ToArray();

            Assert.Collection(actualSymbols, actualSymbol => {
                var expectedSymbol = expectedSymbols.Single();

                Assert.True(expectedSymbol.IsDocumentSymbol);

                Assert.NotNull(actualSymbol.DocumentSymbol);
                Assert.Equal(expectedSymbol.DocumentSymbol.Detail, actualSymbol.DocumentSymbol.Detail);
                Assert.Equal(expectedSymbol.DocumentSymbol.Kind, actualSymbol.DocumentSymbol.Kind);
                Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Line, actualSymbol.DocumentSymbol.Range.Start.Line);
                Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Character, actualSymbol.DocumentSymbol.Range.Start.Character);
                Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Line, actualSymbol.DocumentSymbol.Range.End.Line);
                Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Character, actualSymbol.DocumentSymbol.Range.End.Character);
            });
        }
 public SymbolInformationOrDocumentSymbol(DocumentSymbol documentSymbol)
 {
     _documentSymbol    = documentSymbol;
     _symbolInformation = default;
 }
 public static SymbolInformationOrDocumentSymbol Create(DocumentSymbol value)
 {
     return(value);
 }
 public SymbolInformationOrDocumentSymbol(SymbolInformation symbolInformation)
 {
     _documentSymbol    = default;
     _symbolInformation = symbolInformation;
 }
 public Scope(IAstNode node, DocumentSymbol ds)
 {
     Node   = node;
     Symbol = ds;
 }
 public DocumentSymbolInformationOrDocumentSymbol(DocumentSymbol value)
 {
     _documentSymbol = value;
     _command        = default;
 }