コード例 #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 handle_hover(self, point, is_class=False):
        word = get_word(self.view, point)
        locations = definition(word, self.view)

        self.view.run_command('side_show_signature', {
            'locations': locations,
            'point': point
        })
コード例 #3
0
ファイル: code_action.py プロジェクト: yougotwill/SIDE
    def run(self, edit):
        region = self.view.sel()[0]
        point = region.begin()

        diagnostic_region = in_diagnostic_regions(point)

        word = get_word(self.view, region).strip()

        actions = None
        action_commands = None
        if word:
            # actions_and_commands ('Label', 'command', optional 'args')
            actions_and_commands = [('Search Web', 'side_search_web')]

            # add spell check if in diagnostics region
            if diagnostic_region is not None:
                # add divider at the beginning
                actions_and_commands.append(('-', None))

                misspelled_word = self.view.substr(diagnostic_region).lower()

                corrections = list(spell.candidates(misspelled_word))
                # suggestion_word == misspeled_word
                if len(corrections) == 1 and corrections[0] == misspelled_word:
                    pass
                else:
                    for suggested_word in corrections:
                        arguments = {
                            'region': {
                                'begin': diagnostic_region.begin(),
                                'end': diagnostic_region.end()
                            },
                            'suggested_word': suggested_word
                        }
                        actions_and_commands.append(
                            (suggested_word, 'side_spell_check', arguments))
                    actions_and_commands.append(('-', None))

                actions_and_commands.append(
                    ('Add ' + misspelled_word, 'side_add_word', {
                        'word': misspelled_word
                    }))
                actions_and_commands.append(
                    ('Ignore ' + misspelled_word, 'side_ignore_word', {
                        'word': misspelled_word
                    }))

            actions = pluck_tuples(actions_and_commands, 0)
            action_commands = pluck_tuples(actions_and_commands, 1)
        else:
            actions_and_commands = [('Tell Joke', 'side_tell_joke'),
                                    ('Ask Yes/NO Question',
                                     'side_ask_question'),
                                    ('Get Advice', 'side_advice')]

            actions = pluck_tuples(actions_and_commands, 0)
            action_commands = pluck_tuples(actions_and_commands, 1)

        def on_select(index):
            if index > -1:
                # if the length of the tuple is 3, than the 3rd item are the arguments
                if len(actions_and_commands[index]) == 3:
                    arguments = actions_and_commands[index][2]
                    self.view.run_command(action_commands[index], arguments)
                else:
                    self.view.run_command(action_commands[index])

        self.view.show_popup_menu(actions, on_select)
コード例 #4
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()