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 jumpToLocation(filename, line, column, preview): if preview: command = "pedit +%d %s" % (line, filename) elif filename != tm.filepath(): command = "edit %s" % filename else: command = "normal m" raise NotImplementedError
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)
def WarmupCache(): params = getCompileParams(tm.filepath()) timer = CodeCompleteTimer(0, "", -1, -1, params) t = CompleteThread(-1, -1, getCurrentFile(), tm.filepath(), params, timer) t.start()
def getCurrentQuickFixList(): if tm.filepath() in translationUnits: return getQuickFixList(translationUnits[tm.filepath()]) return []
def highlightCurrentDiagnostics(): if tm.filepath() in translationUnits: highlightDiagnostics(translationUnits[tm.filepath()])
def getCurrentFile(): return (tm.filepath(), tm.buffer())