コード例 #1
0
 def start_tracking(self, view, command_name=None):
     self.track_insert["active"] = True
     self.track_insert["start_line"] = Selection.get_line(view)
     """
         - sublime inserts completions by replacing the current word
         - this results in wrong path insertions if the query contains word_separators like slashes
         - thus the path until current word has to be removed after insertion
         - ... and possibly afterwards
     """
     context = Context.get_context(view)
     needle = context.get("needle")
     word = re.escape(Selection.get_word(view))
     self.post_remove = re.sub(word + "$", "", needle)
     verbose(ID, "start tracking", self.post_remove)
コード例 #2
0
    def on_query_completions(view, project_folder, current_folder):
        global Context, Selection

        current_scope = Selection.get_scope(view)

        if not Query.by_command():
            triggers = get_matching_autotriggers(current_scope, config["TRIGGER"])
        else:
            triggers = config["TRIGGER"]

        if not bool(triggers):
            verbose(ID, "abort query, no valid scope-regex for current context")
            return False

        # parse current context, may contain 'is_valid: False'
        expression = Context.get_context(view)
        if expression["error"] and not Query.by_command():
            verbose(ID, "abort not a valid context")
            return False

        # check if there is a trigger for the current expression
        trigger = Context.find_trigger(expression, current_scope, triggers)
        # verbose("trigger", trigger)

        # expression | trigger  | force | ACTION            | CURRENT
        # -----------|----------|-------|-------------------|--------
        # invalid    | False    | False | abort             | abort
        # invalid    | False    | True  | query needle      | abort
        # invalid    | True     | False | query             |
        # invalid    | True     | True  | query +override   |
        # valid      | False    | False | abort             | abort
        # valid      | False    | True  | query needle      | abort
        # valid      | True     | False | query             |
        # valid      | True     | True  | query +override   |

        # currently trigger is required in Query.build
        if trigger is False:
            verbose(ID, "abort completion, no trigger found")
            return False

        if not expression["valid_needle"]:
            word = Selection.get_word(view)
            expression["needle"] = re.sub("[^\.A-Za-z0-9\-\_$]", "", word)
            verbose(ID, "changed invalid needle to {0}".format(expression["needle"]))
        else:
            verbose(ID, "context evaluation {0}".format(expression))

        if Query.build(expression.get("needle"), trigger, current_folder, project_folder) is False:
            # query is valid, but may not be triggered: not forced, no auto-options
            verbose(ID, "abort valid query: auto trigger disabled")
            return False

        verbose(ID, ".───────────────────────────────────────────────────────────────")
        verbose(ID, "| scope settings: {0}".format(trigger))
        verbose(ID, "| search needle: '{0}'".format(Query.needle))
        verbose(ID, "| in base path: '{0}'".format(Query.base_path))

        FuzzyFilePath.start_expression = expression
        completions = ProjectManager.search_completions(Query.needle, project_folder, Query.extensions, Query.base_path)

        if completions and len(completions[0]) > 0:
            Completion.start(Query.replace_on_insert)
            view.run_command('_enter_insert_mode') # vintageous
            log("| => {0} completions found".format(len(completions)))
        else:
            sublime.status_message("FFP no filepaths found for '" + Query.needle + "'")
            Completion.stop()
            log("| => no valid files found for needle: {0}".format(Query.needle))

        log("")

        Query.reset()
        return completions
コード例 #3
0
    def on_query_completions(view, project_folder, current_folder):
        global Context, Selection

        current_scope = Selection.get_scope(view)

        if not Query.by_command():
            triggers = get_matching_autotriggers(current_scope,
                                                 config["TRIGGER"])
        else:
            triggers = config["TRIGGER"]

        if not bool(triggers):
            verbose(ID,
                    "abort query, no valid scope-regex for current context")
            return False

        # parse current context, may contain 'is_valid: False'
        expression = Context.get_context(view)
        if expression["error"] and not Query.by_command():
            verbose(ID, "abort not a valid context")
            return False

        # check if there is a trigger for the current expression
        trigger = Context.find_trigger(expression, current_scope, triggers)
        # verbose("trigger", trigger)

        # expression | trigger  | force | ACTION            | CURRENT
        # -----------|----------|-------|-------------------|--------
        # invalid    | False    | False | abort             | abort
        # invalid    | False    | True  | query needle      | abort
        # invalid    | True     | False | query             |
        # invalid    | True     | True  | query +override   |
        # valid      | False    | False | abort             | abort
        # valid      | False    | True  | query needle      | abort
        # valid      | True     | False | query             |
        # valid      | True     | True  | query +override   |

        # currently trigger is required in Query.build
        if trigger is False:
            verbose(ID, "abort completion, no trigger found")
            return False

        if not expression["valid_needle"]:
            word = Selection.get_word(view)
            expression["needle"] = re.sub("[^\.A-Za-z0-9\-\_$]", "", word)
            verbose(
                ID,
                "changed invalid needle to {0}".format(expression["needle"]))
        else:
            verbose(ID, "context evaluation {0}".format(expression))

        if Query.build(expression.get("needle"), trigger, current_folder,
                       project_folder) is False:
            # query is valid, but may not be triggered: not forced, no auto-options
            verbose(ID, "abort valid query: auto trigger disabled")
            return False

        verbose(
            ID,
            ".───────────────────────────────────────────────────────────────")
        verbose(ID, "| scope settings: {0}".format(trigger))
        verbose(ID, "| search needle: '{0}'".format(Query.needle))
        verbose(ID, "| in base path: '{0}'".format(Query.base_path))

        FuzzyFilePath.start_expression = expression
        completions = ProjectManager.search_completions(
            Query.needle, project_folder, Query.extensions, Query.base_path)

        if completions and len(completions[0]) > 0:
            Completion.start(Query.replace_on_insert)
            view.run_command('_enter_insert_mode')  # vintageous
            log("| => {0} completions found".format(len(completions)))
        else:
            sublime.status_message("FFP no filepaths found for '" +
                                   Query.needle + "'")
            Completion.stop()
            log("| => no valid files found for needle: {0}".format(
                Query.needle))

        log("")

        Query.reset()
        return completions