Ejemplo n.º 1
0
 def quickpanel_extensive_search(self, idx):
     if idx == 0:
         for cpu in range(common.get_cpu_count()):
             t = threading.Thread(target=self.worker)
             t.start()
         self.queue.put((0, "*/+"))
     elif len(self.options) > 2:
         self.found_callback(self.options[idx][1])
Ejemplo n.º 2
0
 def quickpanel_extensive_search(self, idx):
     if idx == 0:
         for cpu in range(common.get_cpu_count()):
             t = threading.Thread(target=self.worker)
             t.start()
         self.queue.put((0, "*/+"))
     elif len(self.options) > 2:
         self.found_callback(self.options[idx][1])
Ejemplo n.º 3
0
 def quickpanel_extensive_search(self, idx):
     if idx == 0:
         for cpu in range(get_cpu_count()):
             t = threading.Thread(target=self.worker)
             t.start()
         self.queue.put(
             (0, "*/+", self.window.folders(),
              (translationunitcache.tuCache.get_opts(self.view),
               translationunitcache.tuCache.get_opts_script(self.view))))
Ejemplo n.º 4
0
 def do_analyze_project(self, folders):
     for dir in folders:
         for dirpath, dirnames, filenames in os.walk(dir):
             for file in filenames:
                 if "." in file:
                     extension = file[file.rfind(".") + 1 :]
                     if extension in self.extensions:
                         self.tasks.put((self.do_analyze_file, "%s/%s" % (dirpath, file)))
     if get_cpu_count() > 1:
         while not self.tasks.empty():
             time.sleep(0.25)
     self.tasks.put((self.set_status, "Project analyzed"))
Ejemplo n.º 5
0
 def do_analyze_project(self, folders):
     for dir in folders:
         for dirpath, dirnames, filenames in os.walk(dir):
             for file in filenames:
                 if "." in file:
                     extension = file[file.rfind(".") + 1:]
                     if extension in self.extensions:
                         self.tasks.put((self.do_analyze_file, "%s/%s" % (dirpath, file)))
     if get_cpu_count() > 1:
         while not self.tasks.empty():
             time.sleep(0.25)
     self.tasks.put((self.set_status, "Project analyzed"))
Ejemplo n.º 6
0
 def __init__(self, cursor, view, window, name):
     self.name = name
     self.re = re.compile(r"(\w+\s+|\w+::|\*|&)(%s\s*\([^;\{]*\))\s*\{" % cursor.spelling)
     self.view = view
     self.target = ""
     self.cursor = cursor
     self.window = window
     self.queue = Queue.PriorityQueue()
     self.candidates = Queue.Queue()
     for cpu in range(get_cpu_count()):
         t = threading.Thread(target=self.worker)
         t.start()
     self.queue.put((0, "*/+", window.folders(), (translationunitcache.tuCache.get_opts(view), translationunitcache.tuCache.get_opts_script(view))))
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
 def quickpanel_extensive_search(self, idx):
     if idx == 0:
         for cpu in range(get_cpu_count()):
             t = threading.Thread(target=self.worker)
             t.start()
         self.queue.put((0, "*/+", self.window.folders(), (translationunitcache.tuCache.get_opts(self.view), translationunitcache.tuCache.get_opts_script(self.view))))
Ejemplo n.º 11
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()