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

(Help request) How to add custom integrations? (agitator) #297

Open
murtaza64 opened this issue Feb 3, 2024 · 3 comments
Open

(Help request) How to add custom integrations? (agitator) #297

murtaza64 opened this issue Feb 3, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@murtaza64
Copy link

murtaza64 commented Feb 3, 2024

I use agitator to view git blame. It opens a sidebar when you toggle it, much like nvim-tree and such. I would like to set up a custom integration for it and hopefully contribute it, but I was wondering if you have any instructions/explanation/documentation already for how to do that.

@shortcuts
Copy link
Owner

Hey, thanks for using the plugin, hope you like it!

It opens a sidebar when you toggle it, much like nvim-tree and such. I would like to set up a custom integration for it and hopefully contribute it, but I was wondering if you have any instructions/explanation/documentation already for how to do that.

You should be able to have a pretty easy setup by adding an entry here https://github.com/shortcuts/no-neck-pain.nvim/blob/main/lua/no-neck-pain/util/constants.lua#L36

If you want to add tests, they can be added here https://github.com/shortcuts/no-neck-pain.nvim/blob/main/tests/test_integrations.lua

@murtaza64
Copy link
Author

Hey, I gave it a shot with the following:

C.integrations = {
    agitator = {
        fileTypePattern = "agitator",
        close = "lua require('agitator').git_blame_toggle()",
        open = "lua require('agitator').git_blame_toggle()",
    },
        agitator = {
            -- The position of the tree.
            --- @type "left"|"right"
            position = "left",
            -- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
            --- @type boolean
            -- reopen = true,
        },

It kind of works, but for some reason it's super buggy: sometimes the sidebar doesn't open, sometimes instead of closing it when I toggle it it opens another, etc... I'm guessing the problems are in both projects so probably not gonna investigate further. But thanks for the help!

@murtaza64 murtaza64 changed the title (Help request) How to add custom integrations? (Help request) How to add custom integrations? (agitator) Feb 5, 2024
@murtaza64
Copy link
Author

murtaza64 commented Mar 23, 2024

So I was unsatisfied with the way agitator was behaving with NNP, and I read through your code and figured out that it's because fundamentally all of your integrations are expected to stay pinned to the far edge, whereas a git blame is supposed to be next to the file it's about. For that reason, when I was opening a git blame window, the NNP left buffer would close (due to not enough space), and since the git blame window was to the right of the left NNP padding window, it would expand to the left, being way wider than it needs to be (and therefore also shrinking the main window). There's no easy way to fix this without breaking either agitator (forcing it to always be at the far left/right) or adding custom logic to NNP for agitator.

Here's a workaround I threw in my init.lua. This snippet is in the config for agitator, but could live anywhere:

    init = function()
      local gb_open = false
      vim.keymap.set({"n", "v"}, "<leader>gb", function()
        if _G.NoNeckPain.state.enabled then
          if gb_open then
            require("agitator").git_blame_toggle()
            vim.cmd("NoNeckPainToggleLeftSide")
            gb_open = false
          else
            vim.cmd("NoNeckPainToggleLeftSide")
            require("agitator").git_blame_toggle()
            gb_open = true
          end
        else
          require("agitator").git_blame_toggle()
        end
      end, {
        silent = true,
        desc = "Git [B]lame"
      })
      -- ...
    end

This works pretty well for my workflow because I usually only have one window open at a time, but probably won't be ideal if you often like using vsplits

@shortcuts shortcuts added this to the next milestone Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants