def _finish(self, output, matches, err=None, cancel=False):
        self._is_running = False
        if cancel:
            return

        view = self._get_results_view()
        view.erase_status('YetAnotherCodeSearch')

        if err:
            self._print_error(err, output)
            return

        if not matches:
            self._write_message('No matches found\n', view=view)
            return

        query = parser.parse_query(self._last_search)
        result = '\n\n'.join((str(f) for f in matches))
        num_files = len(matches)
        num_matches = functools.reduce(operator.add,
                                       (len(r.matches) for r in matches))
        result += '\n\n{0} matches across {1} files\n'.format(num_matches,
                                                              num_files)
        self._write_message(result, view=view)

        flags = 0
        if not query.case:
            flags = sublime.IGNORECASE
        reg = view.find_all(query.query_re(), flags)
        reg = reg[1:]  # Skip the first match, it's the "title"
        view.add_regions('YetAnotherCodeSearch', reg, 'text.csearch', '',
                         sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL)
        self.window.focus_view(view)
예제 #2
0
    def _finish(self, output, matches, err=None, cancel=False):
        self._is_running = False
        if cancel:
            return

        view = self._get_results_view()
        view.erase_status('YetAnotherCodeSearch')

        if err:
            self._print_error(err, output)
            return

        if not matches:
            self._write_message('No matches found\n', view=view)
            return

        query = parser.parse_query(self._last_search)
        result = '\n\n'.join((str(f) for f in matches))
        num_files = len(matches)
        num_matches = functools.reduce(operator.add,
                                       (len(r.matches) for r in matches))
        result += '\n\n{0} matches across {1} files\n'.format(num_matches,
                                                              num_files)
        self._write_message(result, view=view)

        flags = 0
        if not query.case:
            flags = sublime.IGNORECASE
        reg = view.find_all(query.query_re(), flags)
        reg = reg[1:]  # Skip the first match, it's the "title"
        view.add_regions('YetAnotherCodeSearch', reg, 'text.csearch', '',
                         sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL)
        self.window.focus_view(view)
    def _on_search(self, result):
        self._last_search = result

        view = self._get_results_view()
        self._write_message('Searching for "{0}"\n\n'.format(result), view=view, erase=True)
        view.set_status("YetAnotherCodeSearch", "Searching...")
        try:
            s = settings.get_project_settings(self.window.project_data())
            _CsearchThread(
                parser.parse_query(result), self, path_csearch=s.csearch_path, index_filename=s.index_filename
            ).start()
        except Exception as e:
            self._finish(None, err=e)
    def _on_search(self, result):
        self._last_search = result

        view = self._get_results_view()
        self._write_message('Searching for "{0}"\n\n'.format(result),
                            view=view, erase=True)
        view.set_status('YetAnotherCodeSearch', 'Searching...')
        try:
            s = settings.get_project_settings(self.window.project_data())
            _CsearchThread(parser.parse_query(result), self,
                           path_csearch=s.csearch_path,
                           index_filename=s.index_filename).start()
        except Exception as e:
            self._finish(None, err=e)
 def assertParse(self, search, query=None, file=None, case=True):
     expected = parser.Search(query=query, file=file, case=case)
     actual = parser.parse_query(search)
     self.assertEquals(expected, actual)
예제 #6
0
class ParseQueryTest(unittest.TestCase):

    def assertParse(self, search, query=None, file=None, case=True):
        expected = parser.Search(query=query, file=file, case=case)
        actual = parser.parse_query(search)
        self.assertEquals(expected, actual)