示例#1
0
    def run(self, edit):
        """ index - if specified goto that index location. """
        window = sublime.active_window()
        point = self.view.sel()[0].begin()
        word = get_word(self.view, point)
        locations = definition(word, self.view)

        if len(locations) == 0:
            symbols = find_symbols(self.view)            
            word_regions = self.view.find_all(r"\b{}\b".format(word))

            between_symbols_region = get_region_between_symbols(point, symbols, self.view)
            words_between_regions = filter_regions_by_region(word_regions, between_symbols_region)
            scope_name = self.view.scope_name(point)
            words_between_regions = filter_regions_by_scope_name(words_between_regions, scope_name, self.view)  

            # make sure that there is at least one item in list
            if len(words_between_regions) < 1:
                return 

            definition_point = words_between_regions[0].begin()
            file_name = self.view.file_name()
            row, col = self.view.rowcol(definition_point)
            row += 1
            col += 1
            location = (file_name, None, (row, col))
            open_view(location, self.view)
            return

        if len(locations) == 1:
            open_view(locations[0], self.view)
            return
        
        if len(locations) > 1:
            chose_one_location_from_many(locations, self.view)
示例#2
0
 def fix_window_focus_view_crash():
     open_view(location, self.view)
     self.view.hide_popup()
示例#3
0
文件: reference.py 项目: iamntz/SIDE
    def run(self, edit, find_all=True):
        window = sublime.active_window()
        word = get_word(self.view)

        locations = reference(word, self.view, find_all)

        if len(locations) == 0:
            window.destroy_output_panel('references')
            self.view.show_popup('No References',
                                 sublime.HIDE_ON_MOUSE_MOVE_AWAY)
            return

        panel = window.find_output_panel("references")
        if len(locations) == 1:
            open_view(locations[0], self.view)
            if panel is not None:
                window.destroy_output_panel('references')
            return

        if len(locations) > 1:
            if not find_all:
                chose_one_location_from_many(locations, self.view)
                return

            references_by_rel_file_path = {}  # type: Dict[str, List[line]]
            for location in locations:
                file_path, rel_file_path, row_col = location

                # create an array if it doesn't exist
                if references_by_rel_file_path.get(rel_file_path) is None:
                    references_by_rel_file_path[rel_file_path] = []

                row, col = row_col
                line = get_line(self.view, file_path, row).strip()
                ref = {'row': row, 'col': col, 'line': line}
                references_by_rel_file_path[rel_file_path].append(ref)

            # this string will be rendered in the panel
            find_result = ''
            for rel_file_path in references_by_rel_file_path:
                find_result += "{}:\n".format(rel_file_path)
                references = references_by_rel_file_path.get(rel_file_path)

                for ref in references:
                    find_result += "    {}:{}\t\t{}\n".format(
                        ref['row'], ref['col'], ref['line'])

                find_result += "\n"

            panel = window.create_output_panel("references")

            base_dir = get_project_path(window)
            panel.settings().set("result_base_dir", base_dir)

            panel.settings().set("gutter", False)
            panel.settings().set("result_file_regex", r"^(\S.*):$")
            panel.settings().set("result_line_regex",
                                 r"^\s+([0-9]+):([0-9]+).*$")
            panel.settings().set("draw_white_space", "none")
            panel.assign_syntax(
                'Packages/Default/Find Results.hidden-tmLanguage')

            panel = window.create_output_panel("references")

            window.run_command("show_panel", {"panel": "output.references"})
            panel.run_command(
                'append', {
                    'characters':
                    "{} references for '{}'\n\n{}".format(
                        len(locations), word, find_result),
                    'force':
                    True,
                    'scroll_to_end':
                    False
                })
            panel.set_read_only(True)

            # highlight region
            regions = panel.find_all(r"\b{}\b".format(word))
            panel.add_regions('highlight_references',
                              regions,
                              'comment',
                              flags=sublime.DRAW_OUTLINED)

            # perfect place to clear the linecache
            linecache.clearcache()