def task_reparse(self, data): filename, opts, opts_script, unsaved_files, on_done = data if self.add_busy(filename, self.task_reparse, data): return try: self.set_status("Reparsing %s" % filename) tu = self.get_translation_unit(filename, opts, opts_script, unsaved_files) if tu != None: tu.lock() try: tu.var.reparse(unsaved_files) tu.cache = Cache(tu.var, filename) self.set_status("Reparsing %s done" % filename) finally: tu.unlock() finally: l = self.parsingList.lock() try: l.remove(filename) finally: self.parsingList.unlock() self.remove_busy(filename) if not on_done is None: run_in_main_thread(on_done)
def task_parse_database(self, data): filename, on_done = data if self.add_busy(filename, self.task_parse_database, data): return try: self.set_status('Parsing compilation database: %s' % filename) with open(filename) as compilation_database_file: compilation_database_entries = json.load(compilation_database_file) total = len(compilation_database_entries) entry = 0 for compilation_entry in compilation_database_entries: entry = entry + 1 self.set_status('Parsing compilation database: %s (%d/%d)' % (filename, entry, total)) entry_folder = os.path.dirname(compilation_entry["file"]) if entry_folder not in self.compilation_database: self.compilation_database[entry_folder] = [] self.compilation_database[entry_folder].extend([ p.strip() for p in compilation_database_pattern.findall(compilation_entry["command"]) ]) for k,v in self.compilation_database.items(): self.compilation_database[k] = list(set(self.compilation_database[k])) self.set_status("Parsing %s done" % filename) finally: l = self.parsingList.lock() try: l.remove(filename) finally: self.parsingList.unlock() self.remove_busy(filename) if not on_done is None: run_in_main_thread(on_done)
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()
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()
def task_parse(self, data): filename, opts, opts_script, on_done = data if self.add_busy(filename, self.task_parse, data): return try: self.set_status("Parsing %s" % filename) self.get_translation_unit(filename, opts, opts_script) self.set_status("Parsing %s done" % filename) finally: l = self.parsingList.lock() try: l.remove(filename) finally: self.parsingList.unlock() self.remove_busy(filename) if not on_done is None: run_in_main_thread(on_done)
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()
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()