def on_text_command(self, view, command_name, args):
     # check if a completion may be inserted
     if command_name in settings.get("trigger_action", []) or command_name in settings.get("insert_action", []):
         self.start_tracking(view, command_name)
     elif command_name == "hide_auto_complete":
         self.on_query_abort()
         self.abort_tracking()
 def on_post_text_command(self, view, command_name, args):
     if len( view.sel() ) < 1:
         return
     current_line = Selection.get_line(view)
     command_trigger = command_name in settings.get("trigger_action", []) and self.track_insert["start_line"] != current_line
     if command_trigger or command_name in settings.get("insert_action", []):
         self.finish_tracking(view, command_name)
         self.on_post_insert_completion(view, command_name)
    def run(self, edit, a, b, string, move_cursor=False):
        if settings.get("DISABLE_KEYMAP_ACTIONS") is True:
            return False

        self.view.replace(edit, sublime.Region(a, b), string)

        if move_cursor and settings.get("POST_INSERT_MOVE_CHARACTERS"):
        	self.move_skip(a + len(string))
Пример #4
0
def get_file_cache(folder):
    if not folder in file_caches:
        valid_file_extensions = get_valid_extensions(settings.get("trigger"))
        logger.verbose(ID, "Build cache for " + folder + " (",
                       valid_file_extensions, ") excluding",
                       settings.get("exclude_folders"))
        file_caches[folder] = FileCache(valid_file_extensions,
                                        settings.get("exclude_folders"),
                                        folder)

    return file_caches.get(folder)
Пример #5
0
def find_trigger(current_scope, expression, byCommand=False):
    """ Returns the first trigger matching the given scope and expression """
    triggers = settings.get("TRIGGER")
    if not byCommand:
        # get any triggers that match the requirements and may start automatically
        triggers = get_matching_autotriggers(current_scope,
                                             settings.get("TRIGGER"))
    if not bool(triggers):
        verbose(ID, "abort query, no valid scope-regex for current context")
        return False
    # check if one of the triggers match the current context (expression, scope)
    return Context.find_trigger(expression, current_scope, triggers)
Пример #6
0
    def read(self, folder, base=None):
        """return all files in folder"""
        folder_cache = {}
        base = base if base is not None else folder

        if base is not folder:
            # ensure project_folders are not excluded by another folders exclude patterns
            # e.g. project/node_modules excludes project/node_modules/module, which is also a project folder
            relative_folder = os.path.relpath(folder, base)
            # test ignore expressions on current path
            for test in self.exclude_folders:
                if re.search(test, relative_folder) is not None:
                    # verbose(ID, "skip " + folder)
                    return folder_cache

        # ressources =
        for ressource in os.listdir(folder):
            current_path = os.path.join(folder, ressource)

            if (os.path.isfile(current_path)):

                relative_path = os.path.relpath(current_path, base)
                filename, extension = os.path.splitext(relative_path)
                extension = extension[1:]

                # posix required for windows, else absolute paths are wrong: /asd\ads\
                relative_path = posix(relative_path)
                # substitute $ which prevents errors in further processing. is replaced again in completion.py post repl
                relative_path = re.sub("\$", settings.get("escape_dollar"),
                                       relative_path)

                if extension in self.extensions:
                    current_filename = posix(filename)
                    folder_cache[relative_path] = [
                        # modified filepath. $ hack is reversed in post_commit_completion
                        re.sub("\$", settings.get("escape_dollar"),
                               current_filename),
                        # extension of file
                        extension,
                        # sublime completion text
                        current_filename + "\t" + extension
                    ]

            elif (not ressource.startswith('.')
                  and os.path.isdir(current_path)):
                folder_cache.update(self.read(current_path, base))

        return folder_cache
Пример #7
0
def resolve_path_type(needle, trigger):
    """ ^
        |  Force
        | --------
        |  Needle
        | --------
        | Trigger?
    """
    type_of_path = False  # OR RELATIVE BY DEFAULT?
    # test if forced by command
    if override.get("filepath_type"):
        type_of_path = override.get("filepath_type")
    # test path to trigger auto-completion by needle
    elif not by_command() and trigger.get("auto") is False and settings.get(
            "auto_trigger") and Path.is_absolute(needle):
        type_of_path = "absolute"
    elif Path.is_absolute(needle):
        type_of_path = "absolute"
    elif Path.is_relative(needle):
        type_of_path = "relative"
    elif trigger.get("relative") is True:
        type_of_path = "relative"
    elif trigger.get("relative") is False:
        type_of_path = "absolute"

    return type_of_path
Пример #8
0
def build(needle, trigger, current_folder):
    """
        updates state object for given trigger. The state object is then used to query the file cache:

        @see completion
        ProjectManager.search_completions(
                query.get_needle(),
                current_file.get_project_directory(),
                query.get_extensions(),
                query.get_base_path()
            )
    """
    needle = Path.sanitize(needle)
    needle_is_absolute = Path.is_absolute(needle)
    needle_is_path = needle_is_absolute or Path.is_relative(needle)

    if not trigger or not (
            by_command() or
        (settings.get("auto_trigger") if needle_is_path else trigger.get(
            "auto", settings.get("auto_trigger")))):
        return False
    """ Adjust current folder by specified base folder:

        BASE-FOLDER ->  CURRENT_FOLDER
        ------------------------------------------------------------
        True            use settings base_directory
        String          use string as base_directory
        False           use current file's directory (parameter)
    """
    base_path = resolve_value("base_directory", trigger, False)
    if base_path is True:
        current_folder = settings.get("base_directory")
    elif base_path:
        current_folder = Path.sanitize_base_directory(base_path)

    state["post_remove_path"] = current_folder if (
        base_path and needle_is_absolute) else False
    state["base_directory"] = current_folder if resolve_path_type(
        needle, trigger) == "relative" else False
    state["replace_on_insert"] = resolve_value("replace_on_insert", trigger,
                                               [])
    state["extensions"] = resolve_value("extensions", trigger, ["*"])
    state["needle"] = sanitize_needle(needle, current_folder)

    return True
Пример #9
0
def apply_post_replacements(path, base_directory, replace_on_insert):
    # hack reverse
    path = re.sub(settings.get("ESCAPE_DOLLAR"), "$", path)
    for replace in replace_on_insert:
        path = re.sub(replace[0], replace[1], path)

    if base_directory and path.startswith("/"):
        path = re.sub("^\/" + base_directory, "", path)
        path = Path.sanitize(path)

    return path
    def move_skip(self, point):
    	length = 0
    	word_region = self.view.word(point)
    	line_region = self.view.line(point)
    	post_region = sublime.Region(word_region.b, line_region.b)
    	post = self.view.substr(post_region)
    	to_move = re.search(settings.get("POST_INSERT_MOVE_CHARACTERS"), post)

    	if to_move:
    		length = len(to_move.group(0))

    	self.move_cursor(point + length)
Пример #11
0
def check_trigger(trigger, expression):
    # returns True if the expression statements match the trigger
    for statement in set(
            settings.get("trigger_statements")).intersection(trigger):
        values = trigger.get(statement)
        # statement values may be None (or any other value...)
        if type(values) is list and not expression.get(statement) in values:
            return False
        # validate other value by comparison
        # elif not values == expression.get(statement):
        # 	return False

    return True
    def on_query_completions(self, view, prefix, locations):
        if settings.get("disable_autocompletion") and not Query.by_command():
            return False

        if self.track_insert["active"] is False:
            self.start_tracking(view)

        completions = controller.get_filepath_completions(view)
        if completions is not False:
            return completions

        self.finish_tracking(view)
        return False
Пример #13
0
    def run(self,
            edit,
            type="default",
            base_directory=None,
            replace_on_insert=[],
            extensions=[]):
        if settings.get("DISABLE_KEYMAP_ACTIONS") is True:
            return False

        Query.override_trigger_setting("filepath_type", type)
        Query.override_trigger_setting("base_directory", base_directory)

        if len(replace_on_insert) > 0:
            Query.override_trigger_setting("replace_on_insert",
                                           replace_on_insert)
        if len(extensions) > 0:
            Query.override_trigger_setting("extensions", extensions)

        self.view.run_command('auto_complete', "insert")
Пример #14
0
def end_block():
	if settings.get("log") or settings.get("debug"):
		print("")
Пример #15
0
def log(*args):
	if settings.get("log"):
		print("FFP\t", *args)
Пример #16
0
def plugin_loaded():
    """ load settings """
    update_settings()
    settings_file = sublime.load_settings(Settings.get("ffp_settings_file"))
    settings_file.add_on_change("update", update_settings)
Пример #17
0
def verbose(*args):
    if settings.get("debug") is True and not args[0] in IGNORE:
        print("FFP\t", *args)