def get_completions(self, document, complete_event): token = "" text = document.current_line_before_cursor completions = [] rcall(reval("utils:::.assignLinebuffer"), rstring(text)) rcall(reval("utils:::.assignEnd"), rint(len(text))) token = rcopy(text_type, rcall(reval("utils:::.guessTokenFromLine"))) completion_requested = complete_event.completion_requested completions = [] library_prefix = LIBRARY_PATTERN.match(text) if (len(token) >= 3 and text[-1].isalnum()) or completion_requested: orig_stderr = sys.stderr sys.stderr = None try: reval(""" local(suppressWarnings({{tryCatch( {{ if ({settimelimit}) base::setTimeLimit({timeout}) utils:::.completeToken() if ({settimelimit}) base::setTimeLimit() }}, error = function(e) {{ if ({settimelimit}) base::setTimeLimit() assign("comps", NULL, env = utils:::.CompletionEnv) }} )}})) """.format( settimelimit="TRUE" if not completion_requested and self.timeout > 0 else "FALSE", timeout=str(self.timeout))) except Exception as e: return finally: sys.stderr = orig_stderr completions = rcopy(list, rcall(reval("utils:::.retrieveCompletions"))) if not completions: completions = [] for c in completions: if c.startswith(token): yield Completion(c, -len(token)) if token and not library_prefix: if (len(token) >= 3 and text[-1].isalnum()) or completion_requested: packages = rcopy(list, reval(""" tryCatch( base::rownames(utils::installed.packages()), error = function(e) character(0) ) """)) for p in packages: if p.startswith(token): comp = p + "::" if comp not in completions: yield Completion(comp, -len(token))
def get_completions(self, document, complete_event): token = "" text = document.current_line_before_cursor text_after = document.text_after_cursor completions = [] rcall(reval("utils:::.assignLinebuffer"), rstring(text)) rcall(reval("utils:::.assignEnd"), rint(len(text))) token = rcopy(text_type, rcall(reval("utils:::.guessTokenFromLine"))) completion_requested = complete_event.completion_requested completions = [] if (len(token) >= 3 and text[-1].isalnum()) or completion_requested: orig_stderr = sys.stderr sys.stderr = None try: reval( CompleteCode.format( settimelimit="TRUE" if not completion_requested and self.timeout > 0 else "FALSE", timeout=str(self.timeout))) except Exception: return finally: sys.stderr = orig_stderr completions = rcopy(list, rcall(reval("utils:::.retrieveCompletions"))) if not completions: completions = [] for c in completions: if c.startswith(token): if c.endswith("="): c = c[:-1] + " = " yield Completion(c, -len(token)) library_prefix = LIBRARY_PATTERN.match(text) if token and not library_prefix: if (len(token) >= 3 and text[-1].isalnum()) or completion_requested: instring = text_after.startswith("'") or text_after.startswith( '"') packages = rcopy( list, reval(""" tryCatch( base::rownames(utils::installed.packages()), error = function(e) character(0) ) """)) for p in packages: if p.startswith(token): comp = p if instring else p + "::" if comp not in completions: yield Completion(comp, -len(token))
def configure(): def _configure(): rcall(("base", "source"), os.path.join(os.path.dirname(__file__), "config.R"), new_env()) if "reticulate" in rcopy(rcall(("base", "loadedNamespaces"))): _configure() else: set_hook(package_event("reticulate", "onLoad"), lambda x, y: _configure())
def assign_line_buffer(buf): rcall(reval("utils:::.assignLinebuffer"), rstring(buf)) rcall(reval("utils:::.assignEnd"), rint(len(buf))) token = rcopy(text_type, rcall(reval("utils:::.guessTokenFromLine"))) return token
def retrieve_completions(): completions = rcopy(list, rcall(reval("utils:::.retrieveCompletions"))) if not completions: return [] else: return completions