def get_library_info(self, libname, create=True, current_doc_uri=None): """ :param libname: It may be a library name, a relative path to a .py file or an absolute path to a .py file. :rtype: LibraryDoc """ from robotframework_ls import uris libname_lower = libname.lower() if libname_lower.endswith((".py", ".class", ".java")): libname_lower = os.path.splitext(libname)[0] if "/" in libname_lower or "\\" in libname_lower: libname_lower = os.path.basename(libname_lower) for library_doc in self._iter_library_doc(): if library_doc.name and library_doc.name.lower() == libname_lower: return library_doc if create: additional_path = None abspath = None cwd = None if current_doc_uri is not None: cwd = os.path.dirname(uris.to_fs_path(current_doc_uri)) if os.path.isabs(libname): abspath = libname elif current_doc_uri is not None: # relative path: let's make it absolute fs_path = os.path.dirname(uris.to_fs_path(current_doc_uri)) abspath = os.path.abspath(os.path.join(fs_path, libname)) if abspath: additional_path = os.path.dirname(abspath) libname = os.path.basename(libname) if libname.lower().endswith((".py", ".class", ".java")): libname = os.path.splitext(libname)[0] if self._create_libspec(libname, additional_path=additional_path, cwd=cwd): self.synchronize_internal_libspec_folders() return self.get_library_info(libname, create=False, current_doc_uri=current_doc_uri) log.debug("Unable to find library named: %s", libname) return None
def __init__(self, root_uri, init_opts, process_id, capabilities): self._root_path = uris.to_fs_path(root_uri) self._root_uri = root_uri self._init_opts = init_opts self._process_id = process_id self._capabilities = capabilities self._settings = {} self._config_sources = {}
def __init__(self, root_uri, workspace_folders=None): self._root_uri = root_uri self._root_uri_scheme = uri_scheme(self._root_uri) self._root_path = to_fs_path(self._root_uri) self._folders = {} self._docs = {} if workspace_folders is not None: for folder in workspace_folders: self.add_folder(folder)
def add_workspace_folder(self, folder_uri): from robotframework_ls import uris if folder_uri not in self._workspace_folder_uri_to_folder_info: log.debug("Added workspace folder: %s", folder_uri) cp = self._workspace_folder_uri_to_folder_info.copy() folder_info = cp[folder_uri] = _FolderInfo( uris.to_fs_path(folder_uri), recursive=True) self._workspace_folder_uri_to_folder_info = cp folder_info.start_watch(self._observer, self._spec_changes_notifier) folder_info.synchronize() else: log.debug("Workspace folder already added: %s", folder_uri)
def test_keyword_completions_user_library( data_regression, workspace, tmpdir, cases, libspec_manager, library_import ): import os.path from robotframework_ls.impl import keyword_completions from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls_tests.fixtures import LIBSPEC_1 from robotframework_ls import uris workspace_dir = str(tmpdir.join("workspace")) cases.copy_to("case1", workspace_dir) workspace.set_root(workspace_dir, libspec_manager=libspec_manager) doc = workspace.get_doc("case1.robot") if library_import == "__FULL_PATH__": case1_robot_path = uris.to_fs_path(doc.uri) case1_py_path = os.path.join( os.path.dirname(case1_robot_path), "case1_library.py" ) library_import = case1_py_path doc.source = doc.source.replace("case1_library", library_import) doc.source = doc.source + "\n verify" completions = keyword_completions.complete( CompletionContext(doc, workspace=workspace.ws) ) data_regression.check(completions, basename="keyword_completions_1") # Now, let's put a .libspec file in the workspace and check whether # it has priority over the auto-generated spec file. with open(os.path.join(workspace_dir, "new_spec.libspec"), "w") as stream: stream.write(LIBSPEC_1) libspec_manager.synchronize_workspace_folders() completions = keyword_completions.complete( CompletionContext(doc, workspace=workspace.ws) ) data_regression.check(completions, basename="keyword_completions_2_new")
def find_parents(self, path, names): root_path = uris.to_fs_path(self._root_uri) return _utils.find_parents(root_path, path, names)
def test_win_to_fs_path(uri, path): assert uris.to_fs_path(uri) == path
def source(self): from robotframework_ls import uris return uris.to_fs_path(self.completion_context.doc.uri)