Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fuzzy tag search #27

Closed
claytron opened this issue Nov 9, 2011 · 42 comments
Closed

Add support for fuzzy tag search #27

claytron opened this issue Nov 9, 2011 · 42 comments

Comments

@claytron
Copy link

claytron commented Nov 9, 2011

The one feature that is keeping me on FuzzyFinder at the moment is the :FufTag mode. Would it be possible to add a fuzzy tag search to ctrlp?

@graudeejs
Copy link

I was about to post this as well... but thought that someone would implement it, since ctrlp now has support for user extensions (judging by commits)

I already ditched Command-T :D, FuzzyFinder to be next

@kien
Copy link
Owner

kien commented Nov 9, 2011

Yup, I've made it very simple to add extensions to ctrlp. Everything you need to know is here.

But I guess it's unlikely that someone will do this, so I'll give it a shot once I have some more free time.

Thanks for the suggestion!

@kien
Copy link
Owner

kien commented Nov 28, 2011

Added along with another extension for quickfix. You can enable it with:

let g:ctrlp_extensions = ['tag']

Start in tag mode with :CtrlPTag.

If you find any problem or see anything that can be improved, let me know.

Thanks!

@graudeejs
Copy link

I also use EazyTags, and I'd like to leave tag updating to it.
Right now when I start CtrlPTag EasyTags complains that updatetime is set to less than 400.
(I know I can set g:easytags_updatetime_min which would resolve, that but that's not what I want)

Also I don't see any tags if EasyTags is enabled

(Didn't thought this extensions will be ready so soon and so short :) )

Feel free to check my vim config for details:
https://github.com/graudeejs/dot.vim

to install extensions run make in ~/.vim

@graudeejs
Copy link

This problem also occurs with tags extension disabled.

kien added a commit that referenced this issue Nov 28, 2011
* Only change 'updatetime' if lazy_update is enabled.
  Continue #27 and #37.
@kien
Copy link
Owner

kien commented Nov 28, 2011

c3b316a should take care of the updatetime complaint from easytags.

This tag extension only looks for tags files defined with the Vim's tags option. So you'll need to include the name and location of the tags file generated by easytags in this option. Try something like this for your vimrc:

let &tags .= ','.vim_tmp.'/easytags'

@graudeejs
Copy link

Yes the issue is solved, but I still don't see tags

Yes tags file is included. But I've set easytags to create tags file for each filetype I edit.
So when I edit ruby my tagsfile is ~/tmp/.vim/eazytags/ruby, when I edit sh it's ~/tmp/.vim/eazytags/sh

I suppose CtrlPTag should check tag file after each time it's invoked (since tags setting is dynamic)

(EasyTags is managing last tags option (path to file))

@kien
Copy link
Owner

kien commented Nov 28, 2011

Assuming that the tags option is changed each time you switch to a different filetype, then I think pressing <F5> will update the results. Can you test that and let me know if it helps at all?

@claytron
Copy link
Author

When I try and launch the :CtrlPTag, the vim process instantly goes to 100% CPU and never loads the tags. I tried with both MacVim snapshot 62 and my MacPorts compiled vim. Here is the console vim version info:

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Nov 14 2011 13:08:56)
MacOS X (unix) version
Included patches: 1-244, 246-353
Compiled by clayton@clyde.local
Normal version without GUI.  Features included (+) or not (-):
-arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset +cindent 
-clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
-conceal +cryptv -cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path 
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv 
+insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
-mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse 
+mouse_xterm -mouse_urxvt +multi_byte +multi_lang -mzscheme +netbeans_intg 
+path_extra +perl +persistent_undo +postscript +printer -profile +python 
-python3 +quickfix +reltime -rightleft +ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
 -xterm_clipboard -xterm_save 
   system vimrc file: "/opt/local/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/opt/local/share/vim"
Compilation: /usr/bin/gcc-4.2 -c -I. -Iproto -DHAVE_CONFIG_H   -I/opt/local/include -DMACOS_X_UNIX -no-cpp-precomp  -pipe -O2 -arch x86_64 -D_FORTIFY_SOURCE=1      
Linking: /usr/bin/gcc-4.2   -L. -L/opt/local/lib      -L/opt/local/lib -arch x86_64 -L/usr/local/lib -o vim       -lncurses -liconv -framework Cocoa    -L/opt/local/lib  -fstack-protector  -L/opt/local/lib/perl5/5.12.3/darwin-multi-2level/CORE -lperl -lm -lutil -lc -L/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config -lpython2.6 -framework CoreFoundation -u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.6/Python   -lruby -lobjc  -L/opt/local/lib

@graudeejs
Copy link

Nope, F5 doesn't help

kien added a commit that referenced this issue Nov 28, 2011
@kien
Copy link
Owner

kien commented Nov 28, 2011

Let know me know how a4b8d4c works?

Thanks!

@graudeejs
Copy link

Still nothing... I'll get home and check my config... perhaps I'm missing something...

@graudeejs
Copy link

:set tags output:

tags=~/.vim/.git/vim.tags,~/.vim/.git/tags,./tags,./TAGS,tags,TAGS,~/.vimtags,/tmp/.graudeejs/.vim/easytags/vim

(~/tmp is link to /tmp/.graudeejs)
However CtrlPTag show nothing (tagfile is generated)

@kien
Copy link
Owner

kien commented Nov 28, 2011

Do :echo tagfiles() and :echo taglist('.*') return anything before and
after running :CtrlPTag? What's the output of :echo tagfiles()?

@graudeejs
Copy link

On Mon, 28 Nov 2011 10:42:27 -0800
kien
reply@reply.github.com
wrote:

Do :echo tagfiles() and :echo taglist('.*') return anything
before and after running :CtrlPTag? What's the output of :echo tagfiles()?


Reply to this email directly or view it on GitHub:
#27 (comment)

:echo tagfiles() returns ['/tmp/.graudeejs/.vim/easytags/vim']
Which is correct. After running :CtrlPTag output is the same.

:echo taglist('.*') before and after return massive array of
dictionaries with tags

[{'cmd': '/^map ,$ <plug>NERDCommenterToEOL$/', 'static': 0, 'name':
',$', 'language': 'Vim', 'kind': 'm', 'filename': '/home/graudeejs/
.vim/vimrc'},...

Aldis Berjoza
http://www.bsdroot.lv/

@kien
Copy link
Owner

kien commented Nov 28, 2011

I was able to reproduce this by setting path_mode to 0. However, it should
still work with absolute path like
/tmp/.graudeejs/.vim/easytags/vim but somehow doesn't in your case.

I'll investigate further and try to find a fix soon.

On Tue, Nov 29, 2011 at 2:14 AM, Aldis Berjoza <
reply@reply.github.com

wrote:

On Mon, 28 Nov 2011 10:42:27 -0800
kien
reply@reply.github.com
wrote:

Do :echo tagfiles() and :echo taglist('.*') return anything
before and after running :CtrlPTag? What's the output of :echo tagfiles()?


Reply to this email directly or view it on GitHub:
#27 (comment)

:echo tagfiles() returns ['/tmp/.graudeejs/.vim/easytags/vim']
Which is correct. After running :CtrlPTag output is the same.

:echo taglist('.*') before and after return massive array of
dictionaries with tags

[{'cmd': '/^map ,$ <plug>NERDCommenterToEOL$/', 'static': 0, 'name':
',$', 'language': 'Vim', 'kind': 'm', 'filename': '/home/graudeejs/
.vim/vimrc'},...

Aldis Berjoza
http://www.bsdroot.lv/


Reply to this email directly or view it on GitHub:
#27 (comment)

@graudeejs
Copy link

I disabled EasyTags (removed plugin) and manyally set tags path to /tmp/.graudeejs/.vim/easytags/vim with

:set tags+=/tmp/.graudeejs/.vim/easytags/vim

and CtrlPTag works.

Btw, I have suggestion:
tagfile might contain duplicates, so you should (somehow) filter these out

kien added a commit that referenced this issue Nov 29, 2011
* Pass s:tagfiles and path of the current buffer to tag.vim
  to properly expand '.' in the 'tags' option. Continue #27.
@kien
Copy link
Owner

kien commented Nov 29, 2011

Let me know how the new commit works. Thanks!

As for filtering duplicates, the :tag command already kind of does this, it
jumps to the first matching tag if there are several ones. Manually
filtering the tags list can be costly, and probably too much for the few
times it actually catches something.

Kien

On Tue, Nov 29, 2011 at 2:35 AM, Aldis Berjoza <
reply@reply.github.com

wrote:

I disabled EasyTags (removed plugin) and manyally set tags path to
/tmp/.graudeejs/.vim/easytags/vim with

:set tags+=/tmp/.graudeejs/.vim/easytags/vim

and CtrlPTag works.

Btw, I have suggestion:
tagfile might contain duplicates, so you should (somehow) filter these out


Reply to this email directly or view it on GitHub:
#27 (comment)

@graudeejs
Copy link

Yey, it works.

Now one more thing:
There should be 2 modes:

  1. search tags in current buffer
  2. search tags in all buffers (or in entire tagfile)

For second, perhaps it would be good to enter tag name, and then search for file where this tag is. perhaps tag@file format (or should I make new Feature request?)

@kien
Copy link
Owner

kien commented Nov 29, 2011

That'll require some non-trivial changes in how ctrlp does the whole pattern matching. Sounds really cool though, so I'll definitely look into it. As for seaching tags in current buffer, it's much more complicated, and I think tagbar and taglist already do it and do it better, so I probably won't make this.

@claytron: Can you let me know how it works for you now?

Thanks!

@travisjeffery
Copy link

Pretty sweet stuff going on in here! :D

@graudeejs
Copy link

I just came to work. I'll work with it for few hours, then I'll let you know...

@graudeejs
Copy link

Ok, found a minor problem.

When you work with multiple files, ctrlp caches tags for first file.
When you switch to another file you need to Hit F5 for tags to be updated.

I suggest doing that automatically when CtrlPTag is opened, because it will be annoying as hell to update tags every time I open ctrlp. Also that could prevent CtrlPTag from jumping to wrong line of code, if file was updated (I haven't tested, but I suppose it would jump to wrong line)

I hit a bug..... CtrlPTag can't find tag... when I select any tag and hit Enter it opens Empty buffer saying: "CtrlP: Tag not found."

@graudeejs
Copy link

Wow... this happens even if I delete tags file and EasyTags creates new (fresh) one

@kien
Copy link
Owner

kien commented Nov 29, 2011

Can you provide steps to reproduce the "Tag not found" error?

For the caching, I'll use something other than just checking for filenames.

@graudeejs
Copy link

For sake of environment differences I suggest you take my vim config

git clone https://github.com/graudeejs/dot.vim
cd ~/.vim
make
rm -f ~/tmp/.vim/eazytags/*
vim vimrc

Wait 4-5 seconds for EasyTags to generate tags
now when you open CtrlPTag select tag and press Enter it will show "Tag not found" error.

@kien
Copy link
Owner

kien commented Nov 29, 2011

Good idea, I'll try that.

My guess is that easytags changes the results returned by tagfiles() when
switching to a new buffer, hence the tags files are not found when CtrlPTag
trying to run :tag. So there's an option to not create a new buffer/split
or tab (i.e how fuzzyfinder does it).

Anyway, thanks for your time!

On Tue, Nov 29, 2011 at 2:42 PM, Aldis Berjoza <
reply@reply.github.com

wrote:

For sake of environment differences I suggest you take my vim config
(clone, cd ~/.vim && make)

rm -f ~/tmp/.vim/eazytags/*
 cd ~/.vim
vim vimrc

Wait 4-5 seconds for EasyTags to generate tags
now when you open CtrlPTag select tag and press Enter it will show "Tag
not found" error.


Reply to this email directly or view it on GitHub:
#27 (comment)

kien added a commit that referenced this issue Nov 29, 2011
* Save and restore &l:tags when creating a new buffer,
  workaround for easytags.vim changing the buffer's &l:tags
  and allow using <c-x> <c-t> <c-v> and <cr> to open file.
* New caching method, remove the need for <F5>.
* Continue #27.
@graudeejs
Copy link

It works after last commit

Will do more testing...

@claytron
Copy link
Author

@kien I don't think it can handle the size of my tags file:

$ wc -l tags 
  144321 tags

I can let it run for a while to see how long it takes to complete. But right now it isn't usable for that many tags.

@kien
Copy link
Owner

kien commented Nov 29, 2011

I see. Well, give me a couple of days I'll try adding persistent caching to
this and see if it helps, since the taglist() function seems to be much
slower than readfile().

On Tue, Nov 29, 2011 at 8:00 PM, Clayton Parker <
reply@reply.github.com

wrote:

@kien I don't think it can handle the size of my tags file:

$ wc -l tags
144321 tags

I can let it run for a while to see how long it takes to complete. But
right now it isn't usable for that many tags.


Reply to this email directly or view it on GitHub:
#27 (comment)

@graudeejs
Copy link

@kied..... CtrlPTag really needs to show tags of current file by default.

I don't think it would be hard to implement (Need an idea on this?)

@kien
Copy link
Owner

kien commented Nov 29, 2011

Sure, I'm listening!

On Tue, Nov 29, 2011 at 9:09 PM, Aldis Berjoza <
reply@reply.github.com

wrote:

@kied..... CtrlPTag really needs to show tags of current file by default.

I don't think it would be hard to implement (want me to give some ideas?)


Reply to this email directly or view it on GitHub:
#27 (comment)

@graudeejs
Copy link

taglist('.*') return list of hashes.
Simple algorithm would be check each element in list.
All you need to check is if filename keys value of each element (hash) match current files name

The result should probably be stored in other list. This would allow to implement quick switching to all tags mode and back to current buffers tags.

I don't think it would be slow, but I'm VimL noob. Anyway, I think user will work with current buffers tags most of the time (also would be good to sort tags by weight according to filename path, similar to how file fuzzy searching is implemented now)

@graudeejs
Copy link

Another bug: Currently when you search for tag it show all tags. Now if there are multiple tags with same name but in different files, CtrlPTag can jump to wrong file (even if you manually [with arrow keys] select which tag you want to jump to)

kien added a commit that referenced this issue Nov 30, 2011
* Change the opening commands to the tag-matchlist commands.
* Stop using taglist() so we don't have to worry about &l:tags.
* Persistent caching for tags.
* Continue #27.
@kien
Copy link
Owner

kien commented Nov 30, 2011

@claytron: How does it work for you now? In addition to adding persistent caching, I also remove taglist() altogether and use readfile() for everything.

@graudeejs: That could potentially lead to listing the wrong tags from the wrong file, and would be much slower than using ctags, for example. As for the problem with multiple tags with the same name, tag.vim now uses the tag-matchlist commands as a workaround.

@graudeejs
Copy link

It is now showing list of tags and from where they are, and asks me to enter number of tag that I want to open. No good.
http://failiem.lv/thumb_show.php?i=svvoeax&n=not_so_good.jpg

@kien
Copy link
Owner

kien commented Nov 30, 2011

It only does that if there's at least one other tag with the same name (there are 2 'index' in your case).

This should be good enough for now, as using the filename to identify the tag isn't reliable.

@graudeejs
Copy link

Why not?

Most of time while I work (as Rails programmer) I'll have more >1 tags with same name

@kien
Copy link
Owner

kien commented Nov 30, 2011

For people who don't use easytags and have more than one tag file, the filenames can also be the same, as their locations are relative to the tags files.

It's like this:

dir_a
|- file.ext
`- tags (path to file is 'file.ext')

dir_b
|- file.ext
`- tags (path to file is also 'file.ext')

And the tags option:

set tags+=./dir_a/tags,./dir_b/tags

The listing would look like this:

'mytag'    file.ext
'mytag'    file.ext

So unless I'm missing something, there's no easy way out but using tag-matchlist.

@graudeejs
Copy link

I see

kien added a commit that referenced this issue Nov 30, 2011
* Add a simple tag count finder. Continue #27.
kien added a commit that referenced this issue Dec 1, 2011
* Discard all time consuming tasks when initializing tag.vim - #27.
@kien
Copy link
Owner

kien commented Dec 1, 2011

It should be much faster now. I did a few tests with a tags file that has 200000 tags and it seemed to work reasonably well. There are probably a few ugly trade-offs, but at least it loads up in this extreme case.

I also added a tag-count finder, with it you only get the matchlist prompt when the tags are actually identical.

@kien
Copy link
Owner

kien commented Dec 2, 2011

Closing this as it's gotten really long and the main issues have been resolved.

Thanks everyone for the feedbacks!

Lastly, just to clarify, you also get the matchlist prompt (see in @graudeejs' screenshot) with :FufTag when jumping to a tag that has duplications. This is the default behavior of :tjump and :stjump. :FufTag just hides the duplications so that you don't know they are there, but if you select one, it'll show that prompt.

So what the tag-count finder does here is it helps switching to the :tag command when possible (differences in path/filename), since the :tag command accepts a count argument. And with this, the prompt only shows up in the rare cases where the duplicate tags have the same filename.

@kien kien closed this as completed Dec 2, 2011
@ih4cku ih4cku mentioned this issue Apr 17, 2016
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants