Exemplo n.º 1
0
 def do_message(self):
     try:
         self.lock.acquire()
         common.run_in_main_thread(lambda: common.status_message(self.status))
         self.status_count = 0
         self.timer = None
     finally:
         self.lock.release()
Exemplo n.º 2
0
 def do_message(self):
     try:
         self.lock.acquire()
         run_in_main_thread(lambda: status_message(self.status))
         self.status_count = 0
         self.timer = None
     finally:
         self.lock.release()
Exemplo n.º 3
0
    def worker(self):
        try:
            while len(self.target) == 0:
                prio, name = self.queue.get(timeout=60)
                if name == "*/+":
                    common.run_in_main_thread(lambda: common.status_message("Searching for %s..." % ("implementation" if self.impl else "definition")))
                    name = os.path.basename(self.name)
                    for folder in self.folders:
                        for dirpath, dirnames, filenames in os.walk(folder):
                            for filename in filenames:
                                full_path = os.path.join(dirpath, filename)
                                ok = not "./src/build" in full_path and not "\\src\\build" in full_path
                                if not ok:
                                    full_path = os.path.abspath(full_path)
                                    ok = not "SublimeClang" in full_path and not "Y:\\src\\build" in full_path
                                if ok and self.impre.search(filename) != None:
                                    score = 1000
                                    for i in range(min(len(filename), len(name))):
                                        if filename[i] == name[i]:
                                            score -= 1
                                        else:
                                            break
                                    self.queue.put((score, full_path))
                    for i in range(common.get_cpu_count()-1):
                        self.queue.put((1001, "*/+++"))

                    self.queue.put((1010, "*/++"))
                    self.queue.task_done()
                    continue
                elif name == "*/++":
                    common.run_in_main_thread(self.done)
                    break
                elif name == "*/+++":
                    self.queue.task_done()
                    break

                remove = tuCache.get_status(name) == TranslationUnitCache.STATUS_NOT_IN_CACHE
                fine_search = not remove

                self.set_status("Searching %s" % name)

                # try a regex search first
                f = open(name, "r")
                data = f.read()
                f.close()
                fine_cands = []
                for match in self.re.finditer(data):
                    fine_search = True
                    loc = match.start()
                    for i in range(len(match.groups())+1):
                        m = match.group(i)
                        if self.spelling in m:
                            loc = match.start(i)

                    line, column = get_line_and_column_from_offset(data, loc)
                    fine_cands.append((name, line, column))
                    self.candidates.put((name, match.group(0), line, column))

                if fine_search and self.cursor and self.impl:
                    tu2 = tuCache.get_translation_unit(name, self.opts)
                    if tu2 != None:
                        tu2.lock()
                        try:
                            for cand in fine_cands:
                                cursor2 = cindex.Cursor.get(
                                        tu2.var, cand[0],
                                        cand[1],
                                        cand[2])
                                if cursor2 != None:
                                    d = cursor2.canonical_cursor
                                    if d != None and cursor2 != d:
                                        if format_cursor(d) == self.cursor:
                                            self.target = format_cursor(cursor2)
                                            common.run_in_main_thread(self.done)
                                            break
                        finally:
                            tu2.unlock()
                        if remove:
                            tuCache.remove(name)
                self.queue.task_done()
        except Queue.Empty as e:
            pass
        except:
            import traceback
            traceback.print_exc()
Exemplo n.º 4
0
    def worker(self):
        try:
            while len(self.target) == 0:
                prio, name = self.queue.get(timeout=60)
                if name == "*/+":
                    common.run_in_main_thread(
                        lambda: common.status_message("Searching for %s..." % (
                            "implementation" if self.impl else "definition")))
                    name = os.path.basename(self.name)
                    for folder in self.folders:
                        for dirpath, dirnames, filenames in os.walk(folder):
                            for filename in filenames:
                                full_path = os.path.join(dirpath, filename)
                                ok = not "./src/build" in full_path and not "\\src\\build" in full_path
                                if not ok:
                                    full_path = os.path.abspath(full_path)
                                    ok = not "SublimeClang" in full_path and not "Y:\\src\\build" in full_path
                                if ok and self.impre.search(filename) != None:
                                    score = 1000
                                    for i in range(
                                            min(len(filename), len(name))):
                                        if filename[i] == name[i]:
                                            score -= 1
                                        else:
                                            break
                                    self.queue.put((score, full_path))
                    for i in range(common.get_cpu_count() - 1):
                        self.queue.put((1001, "*/+++"))

                    self.queue.put((1010, "*/++"))
                    self.queue.task_done()
                    continue
                elif name == "*/++":
                    common.run_in_main_thread(self.done)
                    break
                elif name == "*/+++":
                    self.queue.task_done()
                    break

                remove = tuCache.get_status(
                    name) == TranslationUnitCache.STATUS_NOT_IN_CACHE
                fine_search = not remove

                self.set_status("Searching %s" % name)

                # try a regex search first
                f = open(name, "r")
                data = f.read()
                f.close()
                fine_cands = []
                for match in self.re.finditer(data):
                    fine_search = True
                    loc = match.start()
                    for i in range(len(match.groups()) + 1):
                        m = match.group(i)
                        if self.spelling in m:
                            loc = match.start(i)

                    line, column = get_line_and_column_from_offset(data, loc)
                    fine_cands.append((name, line, column))
                    self.candidates.put((name, match.group(0), line, column))

                if fine_search and self.cursor and self.impl:
                    tu2 = tuCache.get_translation_unit(name, self.opts)
                    if tu2 != None:
                        tu2.lock()
                        try:
                            for cand in fine_cands:
                                cursor2 = cindex.Cursor.get(
                                    tu2.var, cand[0], cand[1], cand[2])
                                if cursor2 != None:
                                    d = cursor2.canonical_cursor
                                    if d != None and cursor2 != d:
                                        if format_cursor(d) == self.cursor:
                                            self.target = format_cursor(
                                                cursor2)
                                            common.run_in_main_thread(
                                                self.done)
                                            break
                        finally:
                            tu2.unlock()
                        if remove:
                            tuCache.remove(name)
                self.queue.task_done()
        except Queue.Empty as e:
            pass
        except:
            import traceback
            traceback.print_exc()
Exemplo n.º 5
0
    def worker(self):
        try:
            while len(self.target) == 0:
                prio, name, opts, opts_script = self.queue.get(timeout=60)
                if name == "*/+":
                    run_in_main_thread(lambda: status_message("Searching for %s..." % ("implementation" if self.impl else "definition")))
                    name = os.path.basename(self.name)
                    folders = opts
                    opts, opts_script = opts_script
                    for folder in folders:
                        for dirpath, dirnames, filenames in os.walk(folder):
                            for filename in filenames:
                                if self.impre.search(filename) != None:
                                    score = 1000
                                    for i in range(min(len(filename), len(name))):
                                        if filename[i] == name[i]:
                                            score -= 1
                                        else:
                                            break
                                    self.queue.put((score, os.path.join(dirpath, filename), opts, opts_script))
                    for i in range(get_cpu_count()-1):
                        self.queue.put((1001, "*/+++", None, None))

                    self.queue.put((1010, "*/++", None, None))
                    self.queue.task_done()
                    continue
                elif name == "*/++":
                    run_in_main_thread(self.done)
                    break
                elif name == "*/+++":
                    self.queue.task_done()
                    break

                remove = translationunitcache.tuCache.get_status(name) == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE
                fine_search = not remove

                self.set_status("Searching %s" % name)

                # try a regex search first
                f = file(name, "r")
                data = f.read()
                f.close()
                match = self.re.search(data)
                if match != None:
                    fine_search = True
                    line, column = parsehelp.get_line_and_column_from_offset(data, match.start())
                    self.candidates.put((name, "".join(match.groups()), line, column))

                if fine_search and self.cursor and self.impl:
                    tu2 = translationunitcache.tuCache.get_translation_unit(name, opts, opts_script)
                    if tu2 != None:
                        tu2.lock()
                        try:
                            cursor2 = cindex.Cursor.get(
                                    tu2.var, self.cursor.location.file.name,
                                    self.cursor.location.line,
                                    self.cursor.location.column)
                            if not cursor2 is None:
                                d = cursor2.get_definition()
                                if not d is None and cursor2 != d:
                                    self.target = format_cursor(d)
                                    run_in_main_thread(self.done)
                        finally:
                            tu2.unlock()
                        if remove:
                            translationunitcache.tuCache.remove(name)
                self.queue.task_done()
        except Queue.Empty as e:
            pass
        except:
            import traceback
            traceback.print_exc()
Exemplo n.º 6
0
    def worker(self):
        try:
            while len(self.target) == 0:
                prio, name, opts, opts_script = self.queue.get(timeout=60)
                if name == "*/+":
                    run_in_main_thread(
                        lambda: status_message("Searching for %s..." % (
                            "implementation" if self.impl else "definition")))
                    name = os.path.basename(self.name)
                    folders = opts
                    opts, opts_script = opts_script
                    for folder in folders:
                        for dirpath, dirnames, filenames in os.walk(folder):
                            for filename in filenames:
                                if self.impre.search(filename) != None:
                                    score = 1000
                                    for i in range(
                                            min(len(filename), len(name))):
                                        if filename[i] == name[i]:
                                            score -= 1
                                        else:
                                            break
                                    self.queue.put(
                                        (score,
                                         os.path.join(dirpath, filename), opts,
                                         opts_script))
                    for i in range(get_cpu_count() - 1):
                        self.queue.put((1001, "*/+++", None, None))

                    self.queue.put((1010, "*/++", None, None))
                    self.queue.task_done()
                    continue
                elif name == "*/++":
                    run_in_main_thread(self.done)
                    break
                elif name == "*/+++":
                    self.queue.task_done()
                    break

                remove = translationunitcache.tuCache.get_status(
                    name
                ) == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE
                fine_search = not remove

                self.set_status("Searching %s" % name)

                # try a regex search first
                f = file(name, "r")
                data = f.read()
                f.close()
                match = self.re.search(data)
                if match != None:
                    fine_search = True
                    line, column = parsehelp.get_line_and_column_from_offset(
                        data, match.start())
                    self.candidates.put(
                        (name, "".join(match.groups()), line, column))

                if fine_search and self.cursor and self.impl:
                    tu2 = translationunitcache.tuCache.get_translation_unit(
                        name, opts, opts_script)
                    if tu2 != None:
                        tu2.lock()
                        try:
                            cursor2 = cindex.Cursor.get(
                                tu2.var, self.cursor.location.file.name,
                                self.cursor.location.line,
                                self.cursor.location.column)
                            if not cursor2 is None:
                                d = cursor2.get_definition()
                                if not d is None and cursor2 != d:
                                    self.target = format_cursor(d)
                                    run_in_main_thread(self.done)
                        finally:
                            tu2.unlock()
                        if remove:
                            translationunitcache.tuCache.remove(name)
                self.queue.task_done()
        except Queue.Empty as e:
            pass
        except:
            import traceback
            traceback.print_exc()