def add_completion_test(currtest, platformspecific=False, noneok=False): key = "%s-%s" % (currfile, currtest) add_test_ex(key, lambda: tu.cache.complete(currtest, ""), platformspecific, noneok) data = currfile_data if "{" not in currtest: data += "void __dummy__() {\n" + currtest else: data += currtest if currtest.startswith(currfile_data): # This is pretty much what we've already tested for the clangcomplete operation return data += " " row, col = parsehelp.get_line_and_column_from_offset(data, len(data)-1) def test(): #complete = tu.cache.complete(currtest, "") or [] memb = is_member_completion(data, len(data)-2) clangcomplete = tu.cache.clangcomplete(currfile, row, col, [(currfile,data)], memb) # for result in complete: # print "complete: ", result return clangcomplete add_test_ex(key + " (clangcomplete)", test, platformspecific, noneok)
def fixup(res): if res.count(":") == 2: name, line, col = res.split(":") else: name, line, col = res, 1, 1 line, col = int(line), int(col) name = os.path.relpath(name) # Just to ensure uniform results on all platforms name = name.replace(os.path.sep, "/") d = data if name != "src/main.cpp": d = read_file(name) off = parsehelp.get_offset_from_line_and_column(d, line, col) l2, c2 = parsehelp.get_line_and_column_from_offset(d, off) return "%s:%d:%d - %s - %s" % (name, line, col, word, parsehelp.extract_line_at_offset(d, off))
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()
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()