def complete(completion_context): """ Provides the completions for 'Library' and 'Resource' imports. :param CompletionContext completion_context: """ from robotframework_ls.impl import ast_utils ret = [] try: token_info = completion_context.get_current_token() if token_info is not None: token = ast_utils.get_library_import_name_token( token_info.node, token_info.token) if token is not None: ret = _get_library_completions(completion_context, token) else: token = ast_utils.get_resource_import_name_token( token_info.node, token_info.token) if token is not None: ret = _get_resource_completions(completion_context, token) except: log.exception() return ret
def find_definition(completion_context): """ :param CompletionContext completion_context: :rtype: list(IDefinition) :note: Definitions may be found even if a given source file no longer exists at this place (callers are responsible for validating entries). """ from robotframework_ls.impl import ast_utils from robotframework_ls.impl.collect_keywords import collect_keywords from robotframework_ls.impl.string_matcher import RobotStringMatcher from robotframework_ls.impl.variable_completions import collect_variables token_info = completion_context.get_current_token() if token_info is not None: token = ast_utils.get_keyword_name_token(token_info.node, token_info.token) if token is not None: collector = _FindDefinitionKeywordCollector(token.value) collect_keywords(completion_context, collector) return collector.matches token = ast_utils.get_library_import_name_token( token_info.node, token_info.token) if token is not None: libspec_manager = completion_context.workspace.libspec_manager library_doc = libspec_manager.get_library_info( token.value, create=True, current_doc_uri=completion_context.doc.uri) if library_doc is not None: definition = _DefinitionFromLibrary(library_doc) return [definition] token = ast_utils.get_resource_import_name_token( token_info.node, token_info.token) if token is not None: resource_import_as_doc = completion_context.get_resource_import_as_doc( token_info.node) if resource_import_as_doc is not None: return [_DefinitionFromResource(resource_import_as_doc)] token_info = completion_context.get_current_variable() if token_info is not None: token = token_info.token value = token.value collector = _FindDefinitionVariablesCollector( completion_context.sel, token, RobotStringMatcher(value)) collect_variables(completion_context, collector) return collector.matches return []
def find_definition( completion_context: ICompletionContext) -> Sequence[IDefinition]: """ :note: Definitions may be found even if a given source file no longer exists at this place (callers are responsible for validating entries). """ from robotframework_ls.impl import ast_utils from robotframework_ls.impl.string_matcher import RobotStringMatcher from robotframework_ls.impl.variable_completions import collect_variables token_info = completion_context.get_current_token() if token_info is not None: matches = find_keyword_definition(completion_context, token_info) if matches is not None: return matches token = ast_utils.get_library_import_name_token( token_info.node, token_info.token) if token is not None: libspec_manager = completion_context.workspace.libspec_manager completion_context.check_cancelled() library_doc = libspec_manager.get_library_info( completion_context.token_value_resolving_variables(token), create=True, current_doc_uri=completion_context.doc.uri, ) if library_doc is not None: definition = _DefinitionFromLibrary(library_doc) return [definition] token = ast_utils.get_resource_import_name_token( token_info.node, token_info.token) if token is not None: completion_context.check_cancelled() resource_import_as_doc = completion_context.get_resource_import_as_doc( token_info.node) if resource_import_as_doc is not None: return [_DefinitionFromResource(resource_import_as_doc)] token = ast_utils.get_variables_import_name_token( token_info.node, token_info.token) if token is not None: completion_context.check_cancelled() variable_import_as_doc = completion_context.get_variable_import_as_doc( token_info.node) if variable_import_as_doc is not None: return [_DefinitionFromVariableImport(variable_import_as_doc)] token_info = completion_context.get_current_variable() if token_info is not None: token = token_info.token value = token.value match = next(iter(_RF_VARIABLE.findall(value)), value) collector = _FindDefinitionVariablesCollector( completion_context.sel, token, RobotStringMatcher(match)) collect_variables(completion_context, collector) return collector.matches return []