def _compute_symbols_from_ast(doc: IRobotDocument) -> ISymbolsCache:
    from robotframework_ls.impl import ast_utils
    from robocorp_ls_core.lsp import SymbolKind

    ast = doc.get_ast()
    symbols = []
    uri = doc.uri

    for keyword_node_info in ast_utils.iter_keywords(ast):
        symbols.append({
            "name": keyword_node_info.node.name,
            "kind": SymbolKind.Class,
            "location": {
                "uri": uri,
                "range": {
                    "start": {
                        "line": keyword_node_info.node.lineno - 1,
                        "character": keyword_node_info.node.col_offset,
                    },
                    "end": {
                        "line": keyword_node_info.node.end_lineno - 1,
                        "character": keyword_node_info.node.end_col_offset,
                    },
                },
            },
        })
    return SymbolsCache(symbols, None, doc)
예제 #2
0
def _collect_completions_from_ast(ast, completion_context, collector):
    from robotframework_ls.impl import ast_utils
    from robocode_ls_core.lsp import CompletionItemKind

    for keyword in ast_utils.iter_keywords(ast):
        keyword_name = keyword.node.name
        if collector.accepts(keyword_name):
            keyword_args = []
            for arg in ast_utils.iter_keyword_arguments_as_str(keyword.node):
                keyword_args.append(arg)

            collector.on_keyword(
                _KeywordFoundFromAst(
                    ast,
                    keyword.node,
                    keyword_name,
                    keyword_args,
                    completion_context,
                    CompletionItemKind.Function,
                ))