def initClangComplete(clang_complete_flags, clang_compilation_database, \ library_path): global index debug = int(tm.debug()) == 1 if library_path: Config.set_library_path(library_path) Config.set_compatibility_check(False) try: index = Index.create() except Exception, e: if library_path: suggestion = "Are you sure '%s' contains libclang?" % library_path else: suggestion = "Consider setting g:clang_library_path." if debug: exception_msg = str(e) else: exception_msg = '' print '''Loading libclang failed, completion won't be available. %s %s ''' % (suggestion, exception_msg) return 0
def gotoDeclaration(preview=True): global debug debug = int(tm.debug()) == 1 params = getCompileParams(tm.filepath()) line, col = tm.line(), tm.column() timer = CodeCompleteTimer(debug, tm.filepath(), line, col, params) with libclangLock: with workingDir(params['cwd']): tu = getCurrentTranslationUnit(params['args'], getCurrentFile(), tm.filepath(), timer, update = True) if tu is None: print "Couldn't get the TranslationUnit" return f = File.from_name(tu, tm.filepath()) loc = SourceLocation.from_position(tu, f, line, col + 1) cursor = Cursor.from_location(tu, loc) defs = [cursor.get_definition(), cursor.referenced] for d in defs: if d is not None and loc != d.location: loc = d.location if loc.file is not None: jumpToLocation(loc.file.name, loc.line, loc.column, preview) break timer.finish()
def updateCurrentDiagnostics(): global debug debug = int(tm.debug()) == 1 params = getCompileParams(tm.filepath()) timer = CodeCompleteTimer(debug, tm.filepath(), -1, -1, params) with workingDir(params['cwd']): with libclangLock: getCurrentTranslationUnit(params['args'], getCurrentFile(), tm.filepath(), timer, update = True) timer.finish()
def getCurrentCompletions(base): global debug debug = int(tm.debug()) == 1 sorting = tm.config("clang_sort_algo") line, _ = tm.line() column = int(tm.column()) params = getCompileParams(tm.filepath()) timer = CodeCompleteTimer(debug, tm.filepath(), line, column, params) t = CompleteThread(line, column, getCurrentFile(), tm.filepath(), params, timer) t.start() while t.isAlive(): t.join(0.01) cr = t.result if cr is None: print "Cannot parse this source file. The following arguments " \ + "are used for clang: " + " ".join(params['args']) return (str([]), timer) results = cr.results timer.registerEvent("Count # Results (%s)" % str(len(results))) if base != "": results = filter(lambda x: getAbbr(x.string).startswith(base), results) timer.registerEvent("Filter") if sorting == 'priority': getPriority = lambda x: x.string.priority results = sorted(results, None, getPriority) if sorting == 'alpha': getAbbrevation = lambda x: getAbbr(x.string).lower() results = sorted(results, None, getAbbrevation) timer.registerEvent("Sort") result = map(formatResult, results) timer.registerEvent("Format") return (str(result), timer)