Exemplo n.º 1
0
def GetCallers():
  signature = _GetSignatureAtSource()
  if signature is None or signature == '':
    return ''

  cs = _GetCodeSearch()
  response = cs.SendRequestToServer(
      CompoundRequest(call_graph_request=[
          CallGraphRequest(
              signature=signature,
              file_spec=cs.GetFileSpec(),
              max_num_results=100)
      ]))
  if response is None or not hasattr(
      response, 'call_graph_response') or not hasattr(
          response.call_graph_response[0], 'node'):
    return ''

  node = response.call_graph_response[0].node
  if not hasattr(node, 'children'):
    return ''

  lines = []
  for c in node.children:
    if not hasattr(c, 'file_path') or not hasattr(c, 'call_site_range'):
      continue
    lines.append('{}:{}:{}: {}'.format(
        os.path.join(cs.GetSourceRoot(), c.file_path), c.call_site_range.
        start_line, c.call_site_range.start_column, c.display_name))
  return '\n'.join(lines)
Exemplo n.º 2
0
def RunCallgraphSearch():
  is_nested_query = (vim.current.buffer.vars.get('cs_buftype', '') == 'call')
  signature = None
  parent_node = None
  root_node = None
  if is_nested_query:
    if vim.current.buffer.number not in g_buffer_map_:
      return

    location_map = g_buffer_map_[vim.current.buffer.number]
    signature = location_map.SignatureAt(int(vim.eval("line('.')")))
    root_node = location_map.root_node
    parent_node = _FindNodeForSignature(root_node, signature)
    assert parent_node is not None
  else:
    signature = _GetSignatureAtSource()

  if signature is None:
    return

  # Children of parent node have already been resolved.
  if parent_node is not None and hasattr(parent_node, 'children'):
    return

  cs = _GetCodeSearch()
  response = cs.SendRequestToServer(
      CompoundRequest(call_graph_request=[
          CallGraphRequest(
              signature=signature,
              file_spec=cs.GetFileSpec(),
              max_num_results=100)
      ]))

  if response is None:
    return

  if parent_node is not None:
    assert root_node is not None

    if not hasattr(response, 'call_graph_response') or \
            not hasattr(response.call_graph_response[0], 'node'):
      # |parent_node| has no children known to the server.
      setattr(parent_node, 'children', [])
    else:
      # |new_node.children| are the new children that we are going to 
      # attach to the parent node.
      new_node = response.call_graph_response[0].node

      assert parent_node.signature == new_node.signature
      if hasattr(new_node, 'children'):
        setattr(parent_node, 'children', new_node.children)
      else:
        setattr(parent_node, 'children', [])
    buffer_num = vim.current.buffer.number

  else:
    root_node = response.call_graph_response[0].node
    buffer_num = _SetupVimBuffer('call', 'Callgraph')

  RenderCallGraphInBuffer(root_node, buffer_num)
Exemplo n.º 3
0
def RunCodeSearch(q):
    cs = _GetCodeSearch()
    buffer_num = _SetupVimBuffer('search', 'Codesearch: %s' % (q))
    response = cs.SendRequestToServer(
        CompoundRequest(search_request=[
            SearchRequest(query=q,
                          return_all_snippets=True,
                          return_snippets=True,
                          lines_context=3,
                          return_decorated_snippets=True)
        ]))

    location_map = RenderCompoundResponse(response)
    g_buffer_map_[buffer_num] = location_map
    vim.command('setlocal modifiable')
    vim.current.buffer[:] = location_map.Lines()
    vim.command('setlocal nomodifiable')
Exemplo n.º 4
0
def RunXrefSearch():
  signature = _GetSignatureAtSource()
  if signature is None:
    return

  buffer_num = _SetupVimBuffer('xref', 'Crossreferences')
  cs = _GetCodeSearch()
  response = cs.SendRequestToServer(
      CompoundRequest(xref_search_request=[
          XrefSearchRequest(
              query=signature, file_spec=cs.GetFileSpec(), max_num_results=100)
      ]))

  location_map = RenderCompoundResponse(response)
  g_buffer_map_[buffer_num] = location_map
  vim.command('setlocal modifiable')
  vim.current.buffer[:] = location_map.Lines()
  vim.command('setlocal nomodifiable')
Exemplo n.º 5
0
xrefs_command = subcommands.add_parser(
    'xrefs',
    help='Query cross-references',
    parents=[signature_specifiers, common_args])
xrefs_command.add_argument('--all',
                           '-A',
                           help='Include all outgoing references',
                           action='store_true')
xrefs_command.add_argument('--type',
                           '-T',
                           help='Include references of this type',
                           action='append')
xrefs_command.set_defaults(func=lambda cs, a: cs.SendRequestToServer(
    CompoundRequest(xref_search_request=[
        XrefSearchRequest(query=get_signature(cs, a),
                          file_spec=cs.GetFileSpec('.'),
                          edge_filter=get_edge_filter(a),
                          max_num_results=100)
    ])))

# callers
callers_command = subcommands.add_parser(
    'callers',
    help='Query callers for a signature',
    parents=[signature_specifiers, common_args])
callers_command.set_defaults(func=lambda cs, a: cs.SendRequestToServer(
    CompoundRequest(call_graph_request=[
        CallGraphRequest(signature=get_signature(cs, a),
                         file_spec=cs.GetFileSpec('.'),
                         max_num_results=100)
    ])))