eapache / starscope

Smart code search for Ruby, Go, and JavaScript
https://rubygems.org/gems/starscope
MIT License
266 stars 18 forks source link

"Find References..." In Vim #150

Closed jonahx closed 8 years ago

jonahx commented 8 years ago

Hi, just found your gem and it looks quite powerful. How would I use this to create a "Find References.." features in vim. I'm imagining my cursor is on a method name, eg, I press a hotkey that I've mapped to something in starscope, and it opens up a quickfix window with the references. Is something like this already supported or would I have to build it on top of starscope and, if so, any tips on doing that?

eapache commented 8 years ago

Does https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md#editor-and-workflow-integration answer your question? Vim's cscope integration is quite good already.

If you want to build proper, native integration you will need to write a vim plugin. http://mattmargolis.net/scripting_vim_with_ruby.pdf is a bit old and might be out-of-date, but will probably point you in the right direction.

jonahx commented 8 years ago

Thanks for the reply, Evan.

I do use tpopes setup for ctags. But I'm still a little unclear on the steps to use starscope with vim's builtin cscope support. Can you confirm I have it right?

  1. Add the line: starscope --quiet -e cscope & i to the tpope git hook files.
  2. Now a cscope db file with the name 'cscope' will be added... where exactly? Inside of '.git', like the ctags file?
  3. Now I have a cscope file vim can use, and so at this point it's just a matter of :he cscope and then setting up the mappings I want to vim's various cscope commands -- is that correct?
  4. Continuing point 3, I would have to :cs add .git/cscope or something like this, to setup the connection to the cscope db file created by starscope?
  5. Use :cs find... commands to implement "Find references..." and other similar queries.
  6. Roll my own vimscript if I want those commands wrapped up with nice names in a dropdown from the cursor?

Just want to make sure I'm understanding everything from a high-level before embarking on the actual setup...

Thanks again.

eapache commented 8 years ago
  1. You don't need to use it with git hooks. If you're still experimenting, you might do better to run it manually until you have a setup you're happy with.
  2. I'm not sure what the current working directory will be... your best bet is simply to run it once and see. I suspect it will either be inside the .git folder or it will be right at the root of your repository. It shouldn't be anywhere else so it will be easy to check.
  3. Yup, you can also :cscope help for a summary help.
  4. Yes, wherever the file ends up.
  5. Yes.
  6. I use bindings derived from http://cscope.sourceforge.net/cscope_maps.vim which you may find helpful.
eapache commented 8 years ago

For what it's worth, the exact section of my .vimrc dedicated to cscope looks like this:

set cscopetag                                                                    
set cscopetagorder=1                                                                       
cscope add cscope.out  

nnoremap <Leader>s :cs find s <C-R>=expand("<cword>")<CR><CR>                    
nnoremap <Leader>c :cs find c <C-R>=expand("<cword>")<CR><CR>                    
nnoremap <Leader>t :cs find t <C-R>=expand("<cword>")<CR><CR>                    
nnoremap <Leader>f :cs find f <C-R>=expand("<cfile>")<CR><CR>                    
nnoremap <Leader>i :cs find i <C-R>=expand("<cfile>")<CR><CR>
jonahx commented 8 years ago

Very helpful, ty.