Exemplo n.º 1
0
        public static List <ParameterInformation> GetInfoParams(bhlParser.FuncDeclContext funcDecl)
        {
            List <ParameterInformation> funcParameters = new List <ParameterInformation>();

            if (funcDecl.funcParams() is bhlParser.FuncParamsContext funcParams)
            {
                var funcParamDeclares = funcParams.funcParamDeclare();
                for (int k = 0; k < funcParamDeclares.Length; k++)
                {
                    var fpd = funcParamDeclares[k];
                    if (fpd.exception != null)
                    {
                        continue;
                    }

                    var fpdl = $"{(fpd.isRef() != null ? "ref " : "")}{fpd.type().NAME().GetText()} {fpd.NAME().GetText()}";
                    if (fpd.assignExp() is bhlParser.AssignExpContext assignExp)
                    {
                        fpdl += assignExp.GetText();
                    }

                    funcParameters.Add(new ParameterInformation
                    {
                        label         = fpdl,
                        documentation = ""
                    });
                }
            }

            return(funcParameters);
        }
Exemplo n.º 2
0
        public override object VisitFuncDecl(bhlParser.FuncDeclContext ctx)
        {
            var funcDeclName = ctx.NAME();
            var retType      = ctx.retType();
            var funcParams   = ctx.funcParams();
            var funcBlock    = ctx.funcBlock();

            if (funcDeclName != null)
            {
                var funcDeclNameText = funcDeclName.GetText();
                if (!funcDecls.ContainsKey(funcDeclNameText))
                {
                    funcDecls.Add(funcDeclNameText, ctx);
                }
            }

            var keywordStopIdx = retType?.Start.StartIndex ?? (funcDeclName?.Symbol.StartIndex ?? 0);

            AddSemanticToken(ctx.Start.StartIndex, Math.Max(ctx.Start.StartIndex, keywordStopIdx - 1),
                             SemanticTokenTypes.keyword);

            if (retType != null)
            {
                foreach (var t in retType.type())
                {
                    if (t.exception != null)
                    {
                        continue;
                    }

                    Visit(t);
                }
            }

            if (funcDeclName != null)
            {
                AddSemanticToken(funcDeclName, SemanticTokenTypes.function,
                                 SemanticTokenModifiers.definition, SemanticTokenModifiers.@static);
            }

            if (funcParams != null)
            {
                foreach (var funcParamDeclare in funcParams.funcParamDeclare())
                {
                    VisitFuncParamDeclare(funcParamDeclare);
                }
            }

            if (funcBlock != null)
            {
                Visit(funcBlock);
            }

            return(null);
        }