cbochs / grapple.nvim

Neovim plugin for tagging important files
MIT License
535 stars 21 forks source link

feature: Support for worktrees, customize how file paths are stored #175

Open jugarpeupv opened 1 week ago

jugarpeupv commented 1 week ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

When working with gitworktrees you have folder for the branches, in harpoon you could use 1 to jump to the first marked file, whether you were on main folder or in develop folder

You could do it by customizing how keys are stored

      key = function()
        local wt_utils = require("jg.custom.worktree-utils")
        local wt_switch_info = wt_utils.get_wt_info(vim.loop.cwd())
        if wt_switch_info == nil then
          return
        end
        if next(wt_switch_info) == nil then
          return vim.loop.cwd()
        end
        return wt_switch_info.wt_dir
      end,
    },

I tried to replicate the same behavior on grapple by defining a custom scope, but the path is stored with the folder path inside

Like this: "develop/src/index.ts"

Then if i am in main folder i cant use 1 to load "main/src/index.ts"

I hope i explained myself well enough :)

I tried to replicate this behaviour with this code for grapple

return { { "cbochs/grapple.nvim", opts = { scope = "git", -- also try out "git_branch" }, event = { "BufReadPost", "BufNewFile" }, cmd = "Grapple", keys = { { "aa", "Grapple toggle", desc = "Grapple toggle tag" }, { "S", "Grapple toggle_scopes", desc = "Grappel toggle scopes" }, { "M", "Grapple toggle_tags", desc = "Grapple open tags window" }, { "N", "Grapple cycle_tags next", desc = "Grapple cycle next tag" }, { "P", "Grapple cycle_tags prev", desc = "Grapple cycle previous tag" },

  { "<leader>1",  "<cmd>Grapple select index=1<cr>",  desc = "Select first tag" },
  { "<leader>2",  "<cmd>Grapple select index=2<cr>",  desc = "Select second tag" },
  { "<leader>3",  "<cmd>Grapple select index=3<cr>",  desc = "Select third tag" },
  { "<leader>4",  "<cmd>Grapple select index=4<cr>",  desc = "Select fourth tag" },
  { "<leader>5",  "<cmd>Grapple select index=5<cr>",  desc = "Select fifth tag" },
},

config = function()
  require("grapple").setup({
    scope = "worktree",
    scopes = {
      {
        name = "worktree",
        desc = "worktree scope",
        fallback = "git_branch",
        -- cache = {
        --   event = { "DirChanged" },
        -- },
        resolver = function()
          local wt_utils = require("jg.custom.worktree-utils")
          local wt_info = wt_utils.get_wt_info(vim.loop.cwd())

          if next(wt_info) == nil then
            return
          end
          -- local root = vim.loop.cwd()

          -- local result = vim.fn.system({ "git", "symbolic-ref", "--short", "HEAD" })
          -- local branch = vim.trim(string.gsub(result, "\n", ""))
          --
          -- local id = string.format("%s:%s", wt, branch)
          local id = wt_info.wt_root_dir
          local path = wt_info.wt_root_dir

          return id, path
        end,
      },
    },
  })
end,

}, }

Here for example i would like to jump to the src/index.ts of the main branch, cursor position should be stored with a different value from main/src/index.ts to develop/src/index.ts but the jump should be performed to the corresponding file int he worktree

image

Describe the solution you'd like

Customize how file paths are stored, maybe it is already possible but could not figure out how at the moment

Describe alternatives you've considered

Maybe implement a custom way to define how path is stored

Additional context

No response

jugarpeupv commented 1 week ago

I just noticed that in harpoon there is a separate list for marked files for main folder than for develop folder, i guess what i am thinking is too complex. Close this issue is you think this is not worth the effort