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

Jumplist picker and jump to row/col on existing buffers. #813

Merged
merged 5 commits into from
May 9, 2021

Conversation

caojoshua
Copy link
Contributor

First time developer for lua, neovim plugin, and open source. Please help me in this learning experience.

Partially address #715

  1. Create a jumplist picker
  2. Jump to row/col on existing buffers (helps for jumplist and also some existing pickers ie. quickfix)

The major limitation right now is that vim getjumplist() does not include file text. vim.api.nvim_buf_get_lines() does not work because some jump targets are in unloaded buffers. I decided to only include the filename and row/col in the entries, and rely on the previewer to view contents. Open to any suggestions here.

Copy link
Contributor

@smithbm2316 smithbm2316 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this! You've done a great job for this being your first experience writing lua for a neovim plugin 😄. Thanks for the contribution and for taking an interest! I've left a few comments of minor suggestions and clarifications, but this looks pretty nice to me. I'm a pretty new maintainer here and am still learning the codebase myself, so I'll wait for feedback from one of the other maintainers before considering merging this.

You mentioned that getjumplist() doesn't include the file text, can you describe why this is an issue for what you built here? I noticed you can see the location in the jumplist in the preview window, what did you have in mind to implement if you were able to get access to the file text?

@caojoshua
Copy link
Contributor Author

caojoshua commented May 2, 2021

Thanks for the review!

Let me clarify. For example, quickfix list does:

    return displayer {
      line_info,
      entry.text:gsub(".* | ", ""),
      filename,
    }

Where entry.text holds the actual line of code/text in the file. This works because the items returned from vim.fn.getqflist() have an item field. vim.fn.getjumplist() does not do the same.

Instead, I've implemented

    return displayer {
      line_info,
      filename,
    }

I would prefer it to also include the text, but there does not seem to be an easy way to do it.

Otherwise, I'll implement the suggestions I'm not responding to.

@smithbm2316
Copy link
Contributor

Where entry.text holds the actual line of code/text in the file. This works because the items returned from vim.fn.getqflist() have an item field. vim.fn.getjumplist() does not do the same.

I would prefer it to also include the text, but there does not seem to be an easy way to do it.

Oh I see! Unfortunately I don't know of any other vimscript functions that might make that possible. I'm relatively new to Lua and Neovim plugin development myself, so I'm still learning the APIs. With the new changes this LGTM, as I mentioned before I'll wait for another maintainer to give this the green light before merging.

@smithbm2316
Copy link
Contributor

@tami5 @elianiva any chance one of you could take a peek at this PR? If you think it looks good I can merge, I'm still not too familiar with the make_entry.lua section of the codebase yet.

@smithbm2316
Copy link
Contributor

@caojoshua thanks for all the hard work on this! I'll merge this once #821 is resolved (that is what is causing the two tests to fail atm)

Copy link
Member

@Conni2461 Conni2461 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can we get a mention of that picker in the README?

@caojoshua
Copy link
Contributor Author

Thanks everyone. Left another commit for adding things to README

end

return function(entry)
local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested it. I am getting: Invalid buffer id: 1 here if i had startify open before.
So: nvim -> :Telescope find_files -> open file -> :Telescope jumplist (error)
If i do: nvim file -> :Telescope jumplist works great

We should do

if not vim.api.nvim_buf_is_valid(entry.bufnr) then
  return
end

before this line. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise works great :) thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to the commit.

I personally don't use startify, and haven't been able to reproduce a scenario where this makes/breaks anything. I think its OK, unless there is some other sort of verification we can do.

@Conni2461
Copy link
Member

Thanks all the work. Let's get this merged :)

@Conni2461 Conni2461 merged commit e2907fc into nvim-telescope:master May 9, 2021
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.

4 participants