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 tags builtin #219

Merged
merged 1 commit into from Nov 16, 2020
Merged

Add tags builtin #219

merged 1 commit into from Nov 16, 2020

Conversation

Conni2461
Copy link
Member

@Conni2461 Conni2461 commented Nov 3, 2020

Close #209

Written in a coffee break, so WIP.
Currently has to be generated with --fields=n to get the line numbers. So ctags -R --fields=+n

  • Create ctags for user if file does not exists
  • Jump does not work
  • Write make_entry
  • Create display with new table create
  • Take another look at how lines numbers get retrieved in fzf, so we don't have to use --fields=+n. I decided to just force having --fields=+n. We could search for the lines but it is kinda unnecessary.
  • Only --fields=n will not generate the other fields like type but using --fields=+n includes these fields aswell but does not work this current version
  • Some lines are not displayed. Happens in a file with tabs. has to be fixed by not only splitting with \t and don't split if the line has \^\t
default hide_filename show_line hide_previewer
default hide_filename show_line hide_previewer

Available options:

only_current_file = true -- default is false, setting this to true will only show tags for the current file
hide_filename = true     -- default is false
show_line = true           -- default is false

lua/telescope/builtin.lua Outdated Show resolved Hide resolved
@Conni2461 Conni2461 marked this pull request as ready for review November 3, 2020 18:31
@Conni2461
Copy link
Member Author

@yujinyuz would be great if you could test this one.

@Conni2461 Conni2461 changed the title WIP: Add tags builtin Add tags builtin Nov 4, 2020
@yujinyuz
Copy link
Contributor

yujinyuz commented Nov 9, 2020

@Conni2461 do you mind guiding me how can I test this in my local?

@Conni2461
Copy link
Member Author

Conni2461 commented Nov 9, 2020

@yujinyuz i don't know where you need help exactly so i give you an full instruction. Feel free to ask questions if something does not work.
0. You have telescope.nvim installed, with all requirements mentioned in the readme

  1. You have to fetch my pr with git fetch origin pull/219/head:tags
  2. Than checkout this branch with git checkout tags
  3. Now you are good to go checkout the new tags feature with running lua require'telescope.builtin'.tags{}
  4. Available options are:
only_current_file = true -- default is false, setting this to true will only show tags for the current file
hide_filename = true -- default is false
show_line = true -- default is false
shorten_path = true
previewer = false -- default is true

these options can be combines freely. I would suggest checking out these ones:

  • lua require'telescope.builtin'.tags{ shorten_path = true }
    • This will the the line found in the tags file because the same line will be displayed in the previewer
  • lua require'telescope.builtin'.tags{ shorten_path = true, previewer = false, show_line = true }
    • This will hide the previewer and show the line found in the tags file, most similar to fzf. If shorten_path = false this would be identical.
  • lua require'telescope.builtin'.tags{ hide_filename = true, only_current_file = true }
    • Will only show the tags for the current file, without showing the filename. Like before you can switch between show_line and previewer

@Conni2461
Copy link
Member Author

Conni2461 commented Nov 10, 2020

@tjdevries Should be good to review. If you find some time.
Currently I force ctags -R --fields+=n but i'm not sure if we should do this.
An alternative would be to grep for the line in previewer and when confirming a selection. I tried this but it wasn't as precise and elegant as just having the line number in the tags file.
I also would appreciate some testers. I tested this with one c and one cpp project but i'm not sure if i parse the tags file 100% correctly.

@tjdevries
Copy link
Member

OH!

The other thing is that if it has a command / search thing, we could use that to find the tag in the file, without the line numbers.

Isn't that what FZF does as well? I think we do it for helptags as well btw

@Conni2461
Copy link
Member Author

Yeah i mentioned this in a previous comment but i had problems with tags in Makefiles when it was a multiline tag. I will take another look at was FZF exactly does and ping you if i have a new version up and running

@Conni2461
Copy link
Member Author

Conni2461 commented Nov 13, 2020

@tjdevries I don't know if this is good, but with my testing i have not encountered a line where i could not find the lnum.

Edit: Okay navigating i huge projects is super slow. I need to find a different solution.
Edit 2: Navigating is fine now, i fixed that but typing is slow (30000 tag entries).
Edit 3: Kinda fixed it by not adding scode to ordinal. But i think we want it there

I don't actually get what the guys in FZF do, because they use perl and a shellescape method to modify the tag file and than they can just spit the line with '\t\zs' and use matchstr to jump to the line and the get the line with line('.'). In the end i think they jump back at the original start point.
My viml skills are not good enough for this. 😆

https://github.com/junegunn/fzf.vim/blob/53b3aea0da5e3581e224c958dbc13558cbe5daee/autoload/fzf/vim.vim#L867-L938

@tjdevries
Copy link
Member

Implementation is so much cleaner now!

Also, implementation of action is very good. Thanks!

@Conni2461 Conni2461 deleted the tags branch November 16, 2020 20:20
@yujinyuz
Copy link
Contributor

yujinyuz commented Nov 22, 2020

Why is it that it's not able to find my tags file?

❯ tree
.
├── bin
├── cron
│  ├── cleanbackup.crontab
│  └── README.md
├── emacs
├── fish
├── git
├── karabiner
├── README.md
├── ruby
├── syncdots
├── tags
├── tmux
└── vim

Running :Telescope tags I get

Tags file does not exists. Create one with ctags -R

When using FZF, it works just fine

@kkharji
Copy link
Member

kkharji commented Nov 22, 2020

@yujinyuz sadly it needs to be generated via ctags -R it would be cool to havr auto generated and added to special place where they get manages by telephone "cache" . What do u think @Conni2461

@yujinyuz
Copy link
Contributor

@tami5 Im using universal ctags and a tags file already exists in my project root. What am I missing here?

@kkharji
Copy link
Member

kkharji commented Nov 22, 2020

@yujinyuz ohh just make sure vim cwd matches that root directory

@yujinyuz
Copy link
Contributor

@tami5 If you have time, could you take a look at this:

asciicast

My nvim version is

❯ nvim --version
NVIM v0.5.0-185732a1f
Build type: Release
LuaJIT 2.0.5

Also I'm running the latest telescope.nvim

@kkharji
Copy link
Member

kkharji commented Nov 22, 2020

@tami5 If you have time, could you take a look at this:

asciicast

My nvim version is


❯ nvim --version

NVIM v0.5.0-185732a1f

Build type: Release

LuaJIT 2.0.5

Also I'm running the latest telescope.nvim

This might a potential bug🧐, please open a bug report and I will try to reproduce and fix it after my morning coffee 😬

@yujinyuz
Copy link
Contributor

@tami5 I can't reproduce it with minimal settings. Might be because of my config. I'll try to debug this.

Anyway, thanks!

@kkharji
Copy link
Member

kkharji commented Nov 22, 2020

@yujinyuz oh I hate when that happens, check you telescope settings then test if any plugin is intervening in some way

@Conni2461
Copy link
Member Author

@yujinyuz to be honest i'm really confused right now 😆
We load the file a little different than fzf. We use vim.loop.fs_open.
Can you just run lua print(vim.loop.fs_open(ctags, 'r', 438)) it should give you any value. If you get nil than something is wrong here.
Could you also run lua print(vim.fn.filereadable('tags')).

@tami5 We don't wanna cache tags because ctags basically are a pregenerated cache. Does that make sense. All we do is read the file. But we could load that file async with a plenary job.

@yujinyuz
Copy link
Contributor

yujinyuz commented Nov 22, 2020

@Conni2461

I just ran :lua print(vim.loop.fs_open('tags', 'r', 438)) and I got 32 and I ran it again it became 36 and keeps increasing if I keep running it.

:lua print(vim.fn.filereadable('tags')) outputs 1

@yujinyuz
Copy link
Contributor

But this might be one of the plugins I'm using that causes the conflict

@Conni2461
Copy link
Member Author

Okay so i don't get it. It is fine that it keeps increasing because we get a filehandle as result.

But i don't get why another plugin might cause a conflict here. All i do is check if that handle isn't nil and if it is i will return that message 😕

@kkharji
Copy link
Member

kkharji commented Nov 22, 2020

@tami5 We don't wanna cache tags because ctags basically are a pregenerated cache. Does that make sense. All we do is read the file. But we could load that file async with a plenary job.

I see what you mean @Conni2461, here's my thoughts

while some users and some use cases will rather have tags files pregenerated and maintained. There are some cases where you have a code base that doesn't have tags generated and you want to tun Telescope tags and get back results without having to generate it and then reeeerun the command.

I suggest having vim.loop.fs_stat that check if tag file is valid in vim.loop.cwd and if not, ensure that there is one in .cache/...../tags-dirname and use it.

What do you think? for the async part, :D i'm still in stages of not knowing how it works but see huge amount of value in it

@yujinyuz
Copy link
Contributor

Btw, I just tried commenting out all my plugins and it seems that it's not the case

@Conni2461
Copy link
Member Author

But you could also not reproduce it with a sami5 minimal rc? Could you remove the fs_ check?

if not vim.loop.fs_open(vim.fn.expand(ctags_file), "r", 438) then
print('Tags file does not exists. Create one with ctags -R')
return
end
. Just comment it out for a second. Maybe we have to check differently here. I'm will look into this in a sec, as well as what tami5 said. need to update that other pr first.

@yujinyuz
Copy link
Contributor

@Conni2461

I finally found the cause of the error. I had this line in my .vimrc

 set wildignore+=tags,.*.un~,*.pyc

Idk why it can't find because I added tags to wildignore

@Conni2461
Copy link
Member Author

Okay. Hmm i think that should be fixed by me. Will provide a fix asap.
How do you our tags builtin besides that 😆 ? You never reported back

@yujinyuz
Copy link
Contributor

yujinyuz commented Nov 22, 2020

Oh, yeah I forgot to give feedback as I've only tested it today.

My only concern is that it doesn't exactly match what I want? For example in FZF, it matches correctly if I type Badge

Screen Shot 2020-11-22 at 5 46 33 PM

But when using telescope I get xp as the first match

Screen Shot 2020-11-22 at 5 47 05 PM


I'm also not sure why it was not found because of wildignore.. do you have any ideas why?

@Conni2461
Copy link
Member Author

I will look at that in a sec. Our default sorter is not as good as fzf. But you can change that to fzy

require('telescope').setup {
  defaults = {
    generic_sorter = require'telescope.sorters'.get_fzy_sorter,
    file_sorter = require'telescope.sorters'.get_fzy_sorter,
  }
}

Our idea is that we have a modular design and you basically can change everything.

@Conni2461
Copy link
Member Author

A list of file patterns.  A file that matches with one of these
patterns is ignored when expanding |wildcards|, completing file or
directory names, and influences the result of |expand()|, |glob()| and
|globpath()| unless a flag is passed to disable this.

It is f****** expand which will expand tags into nothing and i can't check for a file ''. 😆 That is a super funny bug. Thanks for investigating

@yujinyuz
Copy link
Contributor

yujinyuz commented Nov 22, 2020

@Conni2461 welcome!

Btw, I just added this to my config

require('telescope').setup {
  defaults = {
    generic_sorter = require'telescope.sorters'.get_fzy_sorter,
    file_sorter = require'telescope.sorters'.get_fzy_sorter,
  }
}

But I'm still getting the same output as the one above. It seems that it matches the filename first rather than the content of the tags file. Is it possible to sort via content and not the filename?

@Conni2461
Copy link
Member Author

Conni2461 commented Nov 22, 2020

I might need to change the ordinal. Will do it in #273. We should move the discussion over there

@yujinyuz
Copy link
Contributor

No problem. Thanks @Conni2461

@Conni2461
Copy link
Member Author

@tami5 I think that is too much we have to handle. We then basically become a ctags plugin. I think tj just wants builtin suff simple and clean. I am also not that familiar with plenary jobs. I am working with them since yesterday. I will try to implement that now. You should join the discussion over at #273.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

:Tags command similar to Fzf
4 participants