Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cscope like functionality for C++ (using vim)

Tags:

vim

cscope

Is there any utility or plugin which provides cscope like functionality for C++. I am looking for

  • all references to a symbol
  • global definitions
  • functions called by a function
  • functions calling a function
  • files including a file
like image 278
Yogesh Arora Avatar asked Mar 10 '10 14:03

Yogesh Arora


People also ask

Does cscope work for C++?

cscope is a programming tool which works in console mode, text-based interface, that allows computer programmers or software developers to search source code of the programming language C, with some support for C++ and Java.


2 Answers

There are some tools listed in the thread, https://www.reddit.com/r/emacs/comments/1qktcb/cscope_like_functionality_that_correctly_handles/:

  • Clang ctags https://github.com/drothlis/clang-ctags (uses clang to parse, supports C/C++) - seems to generate plain classic "TAGS" file (go to definition only, "level 1" of Exuberant Ctags) for Emacs and Vi
  • Clang tags https://github.com/ffevotte/clang-tags (uses clang to parse, supports C/C++; needs server running to use) - works with JSON Compilation Database, supports both go to definition (clang-tag find-def) / go to usage (clang-tag grep). vim-clang-tags can be used to list all usages (:ClangTagsGrep command); there is emacs plugin too
  • Rtags https://github.com/Andersbakken/rtags (named for Roberto Raggi who wrote c++ parser and assured to switch to clang parsing; C/C++ with limited ObjC/ObjC++; server-based with ./bin/rdm daemon) - has "follow-symbol" and "find-references". Intergates with emacs - "rtags.el"; there are two projects for Vim: https://github.com/lyuts/vim-rtags (rich support of rtags) and https://github.com/shaneharper/vim-rtags (only 2 commands) both with "Find references" and "find definition" functions
  • bear https://github.com/rizsotto/Bear (not based on clang, can generate "JSON compilation database" for cmake and non-cmake projects). No any cross-reference functionality?

Some other links

  • https://ruben2020.github.io/codequery/ "CodeQuery is a project that attempts to combine the features available from both cscope and ctags, provide faster database access compared to cscope (because it uses sqlite) and provides a nice GUI tool as well.", has own gui and vim plugin https://github.com/devjoe/vim-codequery; can't generate cscope database, but its own "CodeQuery sqlite3 db" is converted from cscope.out, generated by pycscope for python; starscope for Ruby, Go and Javascript; original cscope for C and limited C++; can also use TAGS.
  • https://github.com/cquery-project/cquery "cquery is a highly-scalable, low-latency language server for C/C++/Objective-C. It is tested and designed for large code bases like Chromium. cquery provides accurate and fast semantic analysis without interrupting workflow." ... finding definition/references, with clang, C/C++; very quick work, fast updates and eats a lot of RAM. Has vim support: https://github.com/cquery-project/cquery/wiki/Vim
  • https://www.gnu.org/software/global/ GNU Global is sometimes recommended as cscope replacement. It has "locate not only definitions but also references" and supports " 6 languages by built-in parser. (definition and reference): C, C++, Yacc, Java, PHP4 and assembly." And Vim integration: https://www.gnu.org/software/global/globaldoc_toc.html#Vim-editor

And there are some fast (indexed) greps like Russ Cox’ codesearch tools (It works with regex too - https://github.com/google/codesearch; example is https://codesearch.debian.net/about) or any other indexed grep...

And there are cross ref tools (GUI and web-servers) like LXR and other... https://github.com/oracle/opengrok/wiki/Comparison-with-Similar-Tools

like image 167
osgx Avatar answered Oct 12 '22 22:10

osgx


Vim can interface directly with cscope out of the box. Type :h cscope. This requires cscope functionality to be enabled when Vim is compiled and for cscope to be installed on your computer.

There is a Vim + cscope tutorial on the cscope web page.

like image 33
Dave Kirby Avatar answered Oct 12 '22 22:10

Dave Kirby