def get_completions(self, view, prefix, line): if not is_cwl_available(): return completions = get_cwl_completions().get_completions(env=True) + \ get_own_env_completion(view) if prefix: completions = [c for c in completions if c[1].startswith(prefix)] show_entries = [c[0].split('\t') for c in completions] completions = [c[1] for c in completions] return show_entries, completions
def on_query_completions(self, view, prefix, locations): if not is_cwl_available(): return [] point = locations[0] if not view.score_selector(point, "text.tex.latex"): return [] point_before = point - len(prefix) char_before = view.substr(getRegion(point_before - 1, point_before)) is_prefixed = char_before == "\\" line = view.substr(getRegion(view.line(point).begin(), point)) line = line[::-1] is_env = bool(BEGIN_END_BEFORE_REGEX.match(line)) # default completion level is "prefixed" completion_level = get_setting( "command_completion", "prefixed" ) do_complete = { "never": False, "prefixed": is_prefixed or is_env, "always": True }.get(completion_level, is_prefixed or is_env) if not do_complete: return [] # do not autocomplete if the leading backslash is escaped if ESCAPE_REGEX.match(line): # if there the autocompletion has been opened with the \ trigger # (no prefix) and the user has not enabled auto completion for the # scope, then hide the auto complete popup selector = view.settings().get("auto_complete_selector") if not prefix and not view.score_selector(point, selector): view.run_command("hide_auto_complete") return [] # Do not do completions in actions if ( latex_input_completions.TEX_INPUT_FILE_REGEX not in ENV_DONOT_AUTO_COM ): ENV_DONOT_AUTO_COM.append( latex_input_completions.TEX_INPUT_FILE_REGEX) for rex in ENV_DONOT_AUTO_COM: if match(rex, line) is not None: return [] # load the completions for the document if is_env: completions = CWL_COMPLETIONS.get_completions(env=True) + \ get_own_env_completion(view) else: completions = CWL_COMPLETIONS.get_completions() + \ get_own_command_completion(view) # autocompleting with slash already on line # this is necessary to work around a short-coming in ST where having a # keyed entry appears to interfere with it recognising that there is a # \ already on the line # # NB this may not work if there are other punctuation marks in the # completion if is_prefixed: completions = [ (c[0], c[1][1:]) if c[1].startswith("\\") else c for c in completions ] return ( completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS )
def on_query_completions(self, view, prefix, locations): if not is_cwl_available(): return [] point = locations[0] if not view.score_selector(point, "text.tex.latex"): return [] point_before = point - len(prefix) char_before = view.substr(getRegion(point_before - 1, point_before)) is_prefixed = char_before == "\\" line = view.substr(getRegion(view.line(point).begin(), point)) line = line[::-1] is_env = bool(BEGIN_END_BEFORE_REGEX.match(line)) # default completion level is "prefixed" completion_level = get_setting("command_completion", "prefixed") do_complete = { "never": False, "prefixed": is_prefixed or is_env, "always": True }.get(completion_level, is_prefixed or is_env) if not do_complete: return [] # do not autocomplete if the leading backslash is escaped if ESCAPE_REGEX.match(line): # if there the autocompletion has been opened with the \ trigger # (no prefix) and the user has not enabled auto completion for the # scope, then hide the auto complete popup selector = view.settings().get("auto_complete_selector") if not prefix and not view.score_selector(point, selector): view.run_command("hide_auto_complete") return [] # Do not do completions in actions if (latex_input_completions.TEX_INPUT_FILE_REGEX not in ENV_DONOT_AUTO_COM): ENV_DONOT_AUTO_COM.append( latex_input_completions.TEX_INPUT_FILE_REGEX) for rex in ENV_DONOT_AUTO_COM: if match(rex, line) is not None: return [] # load the completions for the document if is_env: completions = CWL_COMPLETIONS.get_completions(env=True) + \ get_own_env_completion(view) else: completions = CWL_COMPLETIONS.get_completions() + \ get_own_command_completion(view) # autocompleting with slash already on line # this is necessary to work around a short-coming in ST where having a # keyed entry appears to interfere with it recognising that there is a # \ already on the line # # NB this may not work if there are other punctuation marks in the # completion if is_prefixed: completions = [(c[0], c[1][1:]) if c[1].startswith("\\") else c for c in completions] return (completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)