Ejemplo n.º 1
0
        private async Task <IReadOnlyList <HierarchicalSymbol> > IndexAsync(IDocument doc, CancellationToken indexCt)
        {
            PythonAst ast = null;

            for (var i = 0; i < 5; i++)
            {
                ast = await doc.GetAstAsync(indexCt);

                if (ast != null)
                {
                    break;
                }
                await Task.Delay(100);
            }

            if (ast == null)
            {
                return(Array.Empty <HierarchicalSymbol>());
            }

            indexCt.ThrowIfCancellationRequested();
            var walker = new SymbolIndexWalker(ast);

            ast.Walk(walker);
            return(walker.Symbols);
        }
Ejemplo n.º 2
0
        private async Task <IReadOnlyList <HierarchicalSymbol> > IndexAsync(IDocument doc, CancellationToken cancellationToken)
        {
            PythonAst ast = null;

            for (var i = 0; i < 5; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();
                ast = await doc.GetAstAsync(cancellationToken);

                if (ast != null)
                {
                    break;
                }
                await Task.Delay(100);
            }

            if (ast == null)
            {
                return(ImmutableArray <HierarchicalSymbol> .Empty);
            }

            cancellationToken.ThrowIfCancellationRequested();
            var walker = new SymbolIndexWalker(ast, _library, cancellationToken);

            ast.Walk(walker);
            return(walker.Symbols);
        }
        private async Task <IReadOnlyList <HierarchicalSymbol> > IndexAsync(IDocument doc, CancellationToken indexCt)
        {
            var ast = await doc.GetAstAsync(indexCt);

            indexCt.ThrowIfCancellationRequested();
            var walker = new SymbolIndexWalker(ast);

            ast.Walk(walker);
            return(walker.Symbols);
        }
        private async Task <IReadOnlyList <HierarchicalSymbol> > ParseAsync(CancellationToken parseCancellationToken)
        {
            try {
                var ast = await _indexParser.ParseAsync(_path, parseCancellationToken);

                parseCancellationToken.ThrowIfCancellationRequested();
                var walker = new SymbolIndexWalker(ast);
                ast.Walk(walker);
                return(walker.Symbols);
            } catch (Exception e) when(e is IOException || e is UnauthorizedAccessException)
            {
                Trace.TraceError(e.Message);
            }

            return(new List <HierarchicalSymbol>());
        }
        private async Task <IReadOnlyList <HierarchicalSymbol> > ParseAsync(CancellationToken cancellationToken)
        {
            try {
                var ast = await _indexParser.ParseAsync(_path, cancellationToken);

                if (ast != null)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    var walker = new SymbolIndexWalker(ast, _library, cancellationToken);
                    ast.Walk(walker);
                    return(walker.Symbols);
                }
            } catch (Exception e) when(e is IOException || e is UnauthorizedAccessException)
            {
                Trace.TraceError(e.Message);
            }

            return(ImmutableArray <HierarchicalSymbol> .Empty);
        }