コード例 #1
0
ファイル: services.cs プロジェクト: bitdotgames/bhl
        SignatureInformation GetFuncSignInfo(bhlParser.FuncDeclContext funcDecl)
        {
            SignatureInformation funcSignature = new SignatureInformation();

            string label = funcDecl.NAME().GetText() + "(";

            List <ParameterInformation> funcParameters = BHLSPUtil.GetInfoParams(funcDecl);

            if (funcParameters.Count > 0)
            {
                for (int k = 0; k < funcParameters.Count; k++)
                {
                    var funcParameter = funcParameters[k];
                    label += funcParameter.label.Value;
                    if (k != funcParameters.Count - 1)
                    {
                        label += ", ";
                    }
                }
            }
            else
            {
                label += "<no parameters>";
            }

            label += ")";

            if (funcDecl.retType() is bhlParser.RetTypeContext retType)
            {
                label += ":";

                var types = retType.type();
                for (int n = 0; n < types.Length; n++)
                {
                    var t = types[n];
                    if (t.exception != null)
                    {
                        continue;
                    }

                    label += t.NAME().GetText() + " ";
                }
            }
            else
            {
                label += ":void";
            }

            funcSignature.label      = label;
            funcSignature.parameters = funcParameters.ToArray();
            return(funcSignature);
        }
コード例 #2
0
ファイル: services.cs プロジェクト: bitdotgames/bhl
        public override RpcResult Hover(TextDocumentPositionParams args)
        {
            BHLSPWorkspace.self.TryAddDocument(args.textDocument.uri);
            if (BHLSPWorkspace.self.FindDocument(args.textDocument.uri) is BHLTextDocument document)
            {
                int line      = (int)args.position.line;
                int character = (int)args.position.character;

                int idx = document.GetIndex(line, character);

                bhlParser.CallExpContext callExp = null;

                foreach (IParseTree node in BHLSPUtil.DFS(document.ToParser().program()))
                {
                    if (node is ParserRuleContext prc)
                    {
                        if (prc.Start.StartIndex <= idx && idx <= prc.Stop.StopIndex)
                        {
                            callExp = prc as bhlParser.CallExpContext;
                            break;
                        }
                    }
                }

                bhlParser.FuncDeclContext funcDecl = null;

                if (callExp != null)
                {
                    string callExpName = callExp.NAME().GetText();

                    foreach (var doc in BHLSPWorkspace.self.ForEachBhlImports(document))
                    {
                        if (doc.FuncDecls.ContainsKey(callExpName))
                        {
                            funcDecl = doc.FuncDecls[callExpName];
                            break;
                        }
                    }
                }

                if (funcDecl != null)
                {
                    string label = funcDecl.NAME().GetText() + "(";

                    List <ParameterInformation> funcParameters = BHLSPUtil.GetInfoParams(funcDecl);

                    if (funcParameters.Count > 0)
                    {
                        for (int k = 0; k < funcParameters.Count; k++)
                        {
                            var funcParameter = funcParameters[k];
                            label += funcParameter.label.Value;
                            if (k != funcParameters.Count - 1)
                            {
                                label += ", ";
                            }
                        }
                    }
                    else
                    {
                        label += "<no parameters>";
                    }

                    label += ")";

                    if (funcDecl.retType() is bhlParser.RetTypeContext retType)
                    {
                        label += ":";

                        var types = retType.type();
                        for (int n = 0; n < types.Length; n++)
                        {
                            var t = types[n];
                            if (t.exception != null)
                            {
                                continue;
                            }

                            label += t.NAME().GetText() + " ";
                        }
                    }
                    else
                    {
                        label += ":void";
                    }

                    return(RpcResult.Success(new Hover
                    {
                        contents = new MarkupContent
                        {
                            kind = "plaintext",
                            value = label
                        }
                    }));
                }
            }

            return(RpcResult.Success());
        }