def getCompileParams(fileName): global builtinHeaderPath params = getCompilationDBParams(fileName) args = params['args'] args += splitOptions(tm.config("clang_user_options")) if builtinHeaderPath: args.append("-I" + builtinHeaderPath) return { 'args' : args, 'cwd' : params['cwd'] }
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)