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

[Question] How to open entry of the file panel via lua/command? #464

Closed
Otterpatsch opened this issue Feb 18, 2024 · 2 comments
Closed

[Question] How to open entry of the file panel via lua/command? #464

Otterpatsch opened this issue Feb 18, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Otterpatsch
Copy link

Hello there,
First of all i very much like your plugin. So much that im trying to use it within the plugin im trying to create (bitbucket.nvim basically just to review PRs of bitbuckets repos).

So i want to jump to a file of the file panel given its relative(or absolut if needed) file path
image

For example i would like to jump to the file to which a comment is connected
image

I tried to dig into your code but as im just picked up lua like 4 days ago im struggle a bit.
select_entry = function()
So how to i "fake" a item for the linked function? Or is there maybe another function which does that?

@jakubbortlik
Copy link

Hi @Otterpatsch, not sure if this is still relevant, but you can take inspiration from how gitlab.nvim does this: You can focus the file panel and then use the diffview.lib.get_current_view() to get the current view and then you should be able to view:set_file(file).

@sindrets
Copy link
Owner

You would be reaching into the internal API for this, which could change at any point. But I believe you could do this (untested):

local DiffView = require("diffview.scene.views.diff.DiffView").DiffView
local async = require("diffview.async")

async.void(function()
  local view = require("diffview.lib").get_current_view()

  if view and DiffView:ancestorof(view) then
    --- @cast view DiffView
    async.await(view:set_file_by_path("some/file/path"))
  end
end)()

The file path here would be relative to the repository top-level. That can be found from view.adapter.ctx.toplevel.

@sindrets sindrets added the question Further information is requested label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants