def test_resource_completions_resolve_var(data_regression, workspace, cases, libspec_manager, workspace_dir): from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_VARIABLES from robotframework_ls.robot_config import RobotConfig cases.copy_to("case4", workspace_dir) config = RobotConfig() config.update( {"robot": { "variables": { "ext_folder": cases.get_path("ext") } }}) assert config.get_setting(OPTION_ROBOT_VARIABLES, dict, {}) == { "ext_folder": cases.get_path("ext") } workspace.set_root(workspace_dir, libspec_manager=libspec_manager) doc = workspace.get_doc("case4.robot") doc.source = """*** Settings *** Resource ${ext_folder}/""" completions = filesystem_section_completions.complete( CompletionContext(doc, workspace=workspace.ws, config=config)) data_regression.check(completions)
def test_library_completions_in_dirs(data_regression, workspace, cases, libspec_manager, workspace_dir): from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl.completion_context import CompletionContext import os.path cases.copy_to("case1", workspace_dir) workspace.set_root(workspace_dir, libspec_manager=libspec_manager) doc = workspace.get_doc("case1.robot") doc.source = """*** Settings *** Library dir1/caseXXX""" dir1 = os.path.join(workspace_dir, "dir1") os.mkdir(dir1) mycase_py = os.path.join(dir1, "mycase.py") with open(mycase_py, "w") as stream: stream.write("""def my_method():\n pass""") line, col = doc.get_last_line_col() completions = filesystem_section_completions.complete( CompletionContext(doc, workspace=workspace.ws, line=line, col=col - len("XXX"))) data_regression.check(completions)
def _threaded_complete_all(self, doc_uri, line, col, monitor: IMonitor): from robotframework_ls.impl import section_name_completions from robotframework_ls.impl import keyword_completions from robotframework_ls.impl import variable_completions from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl import keyword_parameter_completions completion_context = self._create_completion_context( doc_uri, line, col, monitor) if completion_context is None: return [] ret = section_name_completions.complete(completion_context) if not ret: ret.extend( filesystem_section_completions.complete(completion_context)) if not ret: ret.extend(keyword_completions.complete(completion_context)) if not ret: ret.extend(variable_completions.complete(completion_context)) if not ret: ret.extend( keyword_parameter_completions.complete(completion_context)) return ret
def test_resource_completions_relative(data_regression, workspace, cases, libspec_manager, workspace_dir): from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl.completion_context import CompletionContext cases.copy_to("case4", workspace_dir) workspace.set_root(workspace_dir, libspec_manager=libspec_manager) doc = workspace.get_doc("case4.robot") doc.source = """*** Settings *** Resource case""" completions = filesystem_section_completions.complete( CompletionContext(doc, workspace=workspace.ws)) data_regression.check(completions)
def m_complete_all(self, doc_uri, line, col): from robotframework_ls.impl import section_name_completions from robotframework_ls.impl import keyword_completions from robotframework_ls.impl import variable_completions from robotframework_ls.impl import filesystem_section_completions completion_context = self._create_completion_context( doc_uri, line, col) if completion_context is None: return [] ret = section_name_completions.complete(completion_context) ret.extend(filesystem_section_completions.complete(completion_context)) ret.extend(keyword_completions.complete(completion_context)) ret.extend(variable_completions.complete(completion_context)) return ret
def _threaded_complete_all(self, doc_uri, line, col, monitor: IMonitor): from robotframework_ls.impl import section_name_completions from robotframework_ls.impl import keyword_completions from robotframework_ls.impl import variable_completions from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl import keyword_parameter_completions from robotframework_ls.impl import auto_import_completions from robotframework_ls.impl.collect_keywords import ( collect_keyword_name_to_keyword_found, ) from robotframework_ls.impl import ast_utils completion_context = self._create_completion_context( doc_uri, line, col, monitor ) if completion_context is None: return [] ret = section_name_completions.complete(completion_context) if not ret: ret.extend(filesystem_section_completions.complete(completion_context)) if not ret: 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: keyword_name_to_keyword_found: Dict[ str, List[IKeywordFound] ] = collect_keyword_name_to_keyword_found(completion_context) ret.extend(keyword_completions.complete(completion_context)) ret.extend( auto_import_completions.complete( completion_context, keyword_name_to_keyword_found ) ) return ret if not ret: ret.extend(variable_completions.complete(completion_context)) if not ret: ret.extend(keyword_parameter_completions.complete(completion_context)) return ret
def _complete_from_completion_context(self, completion_context): from robotframework_ls.impl import section_name_completions from robotframework_ls.impl import keyword_completions from robotframework_ls.impl import variable_completions from robotframework_ls.impl import dictionary_completions from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl import keyword_parameter_completions from robotframework_ls.impl import auto_import_completions from robotframework_ls.impl.collect_keywords import ( collect_keyword_name_to_keyword_found, ) from robotframework_ls.impl import ast_utils ret = section_name_completions.complete(completion_context) if not ret: ret.extend(filesystem_section_completions.complete(completion_context)) if not ret: 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: keyword_name_to_keyword_found: Dict[ str, List[IKeywordFound] ] = collect_keyword_name_to_keyword_found(completion_context) ret.extend(keyword_completions.complete(completion_context)) ret.extend( auto_import_completions.complete( completion_context, keyword_name_to_keyword_found ) ) return ret if not ret: ret.extend(variable_completions.complete(completion_context)) if not ret: ret.extend(dictionary_completions.complete(completion_context)) if not ret: ret.extend(keyword_parameter_completions.complete(completion_context)) return ret
def test_library_completions_local(data_regression, workspace, cases, libspec_manager, workspace_dir): from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl.completion_context import CompletionContext cases.copy_to("case1", workspace_dir) workspace.set_root(workspace_dir, libspec_manager=libspec_manager) doc = workspace.get_doc("case1.robot") doc.source = """*** Settings *** Library caseXXX""" line, col = doc.get_last_line_col() completions = filesystem_section_completions.complete( CompletionContext(doc, workspace=workspace.ws, line=line, col=col - len("XXX"))) data_regression.check(completions)
def test_library_completions_absolute(data_regression, workspace, cases, libspec_manager, workspace_dir): from robotframework_ls.impl import filesystem_section_completions from robotframework_ls.impl.completion_context import CompletionContext import os.path cases.copy_to("case1", workspace_dir) dir1 = os.path.join(workspace_dir, "dir1") os.mkdir(dir1) workspace.set_root(workspace_dir, libspec_manager=libspec_manager) directory = workspace_dir directory = directory.replace(u"\\", u"/") doc = workspace.get_doc("case1.robot") doc.source = u"""*** Settings *** Library %s/""" % (directory, ) completions = filesystem_section_completions.complete( CompletionContext(doc, workspace=workspace.ws)) _line, col = doc.get_last_line_col() for completion in completions: # The range will change based on the workspace_dir contents, so, # check it here and not in the data regression. found_range = completion["textEdit"].pop("range") assert found_range == { "start": { "line": 1, "character": col }, "end": { "line": 1, "character": col }, } data_regression.check(completions)