public override bool Walk(FunctionDefinition node)
        {
            _stack.Enter(SymbolKind.Function);
            foreach (var p in node.Parameters)
            {
                AddVarSymbol(p.NameExpression);
            }

            // don't bother to walk down locals for libraries
            // we don't care those for libraries
            WalkIfNotLibraryMode(node.Body);

            var children = _stack.Exit();

            SymbolKind symbolKind;
            string     functionKind;

            GetKinds(node, out symbolKind, out functionKind);

            var span = node.GetSpan(_ast);

            var ds = new HierarchicalSymbol(
                node.Name,
                symbolKind,
                span,
                node.IsLambda ? span : node.NameExpression.GetSpan(_ast),
                children,
                functionKind,
                ExistInAllVariable(node.Name)
                );

            _stack.AddSymbol(ds);
            return(false);
        }
Esempio n. 2
0
        public override bool Walk(FunctionDefinition node)
        {
            _stack.Enter(SymbolKind.Function);
            foreach (var p in node.Parameters)
            {
                AddVarSymbol(p.NameExpression);
            }
            node.Body?.Walk(this);
            var children = _stack.Exit();

            var span = node.GetSpan(_ast);

            var ds = new HierarchicalSymbol(
                node.Name,
                SymbolKind.Function,
                span,
                node.IsLambda ? span : node.NameExpression.GetSpan(_ast),
                children,
                FunctionKind.Function
                );

            if (_stack.Parent == SymbolKind.Class)
            {
                switch (ds.Name)
                {
                case "__init__":
                    ds.Kind = SymbolKind.Constructor;
                    break;

                case var name when DoubleUnderscore.IsMatch(name):
                    ds.Kind = SymbolKind.Operator;

                    break;

                default:
                    ds.Kind = SymbolKind.Method;

                    if (node.Decorators != null)
                    {
                        foreach (var dec in node.Decorators.Decorators)
                        {
                            var maybeKind = DecoratorExpressionToKind(dec);
                            if (maybeKind.HasValue)
                            {
                                ds.Kind          = maybeKind.Value.kind;
                                ds._functionKind = maybeKind.Value.functionKind;
                                break;
                            }
                        }
                    }

                    break;
                }
            }

            _stack.AddSymbol(ds);

            return(false);
        }