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); }
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); }
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()); }