def handle_getusrlocations(self,data):
   '''Get all declarations and defintions of a symbol (given by an usr)'''
   projRoot = data['projRoot']
   unsavedFiles = self.aquireUnsavedFiles(data['unsavedFiles'])
   proj = projectDatabase.getProjectFromRoot(projRoot)
   if proj is None:
     return projNotFoundData
   else:
     self.request.sendall(json.dumps( {'kind':'result','locations':proj.getUsrLocations(data['usr'],data['type'])}))
 def setUp(self):
   self.proj = []
   '''Create the projects'''
   for pId in xrange(1,self.numProjects+1):
     p = "./testProject" + str(pId) + "/"
     if os.path.exists(p + ".clang_complete.project.dict"):
       os.remove(p + ".clang_complete.project.dict")
     pd.onLoadFile(p + "main.cpp",self.args,1)
     pd.createOrUpdateProjectForFile(p + "main.cpp",["-x","c++"],[])
     self.proj.append(pd.getProjectFromRoot(p))
     assert self.proj[pId-1] is not None
def getProjectsQuickFixList(projectPath):
  proj = projectDatabase.getProjectFromRoot(projectPath)
  if proj is None:
    return []
  def makeQuickFix(i):
    return { 'bufnr' : int (vim.eval("bufnr('" + i[0] + "', 1)")),
             'lnum'  : i[1],
             'col'   : i[2],
             'text'  : i[3],
             'type'  : i[4]
           }
  return map (makeQuickFix,proj.getAllDiagnostics())
 def handle_dumpsymbols(self,data):
   '''Dumb all symbols in a project'''
   projRoot     = data['projRoot']
   unsavedFiles = self.aquireUnsavedFiles(data['unsavedFiles'])
   proj = projectDatabase.getProjectFromRoot(projRoot)
   if proj is None:
     self.sendProjNotFound()
   else:
     f = tempfile.NamedTemporaryFile(delete = False)
     name = f.name
     f.write('\n'.join('%s,%s,%s' % x for x in proj.getAllTypeNamesInProject()))
     f.close()
     self.request.sendall(json.dumps({'kind':'result','symbols':name}))
def gotoNextOccurenceOfUsr(usr):
  projPath = vim.eval("b:clang_project_root")
  proj = projectDatabase.getProjectFromRoot(projPath)
  line, col = vim.current.window.cursor
  path = os.path.abspath(vim.current.buffer.name)
  currentLocation = (path,line,col)

  occ = proj.getUsrLocations(usr,"occurences")
  if len(occ) ==0:
    return
  for o in occ:
    if currentLocation < o:
      openLocation(o)
      return
  openLocation(occ[0])
def getOccurencesOfUsr(usr):
  '''Returns the occurnces of an usr in the format:
     [(buffernumber,line,col,extend)]
     '''
  if usr is None or usr == "":
    return []
  projPath = vim.eval("b:clang_project_root")
  if projPath is None or projPath == "":
    return []
  proj = projectDatabase.getProjectFromRoot(projPath)
  if not proj.usrInfos.has_key(usr):
    return []
  occ = proj.getUsrLocations(usr,"occurences")
  length = len(proj.getUsrSpelling(usr))
  res = []
  if occ is None:
    return res
  for o in occ:
    bufnr      = int(vim.eval("bufnr(\"" + o[0] + "\")"))
    if bufnr != -1:
      res.append((bufnr,o[1],o[2],length))
  return res
def renameUsr(usr):
  projPath = vim.eval("b:clang_project_root")
  bringProjectUpToDate(projPath)
  proj = projectDatabase.getProjectFromRoot(projPath)
  if proj is None:
    print "No project loaded"
    return

  if not proj.usrInfos.has_key(usr):
    print "Sorry, usr " + usr + " not found in project"

  oldName = proj.usrInfos[usr].spelling

  vim.command('call inputsave()')
  vim.command("let user_input = input('Replace " + oldName + " with: ')")
  vim.command('call inputrestore()')
  newName = vim.eval('user_input')

  if newName is None:
    return

  locs = proj.getUsrRenameLocations(usr)
  tryReplaceInFiles(locs,oldName,newName)