Example #1
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()
Example #2
0
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)