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

Possible to use with Lazy.nvim? #20

Open
jondkinney opened this issue Aug 24, 2024 · 9 comments
Open

Possible to use with Lazy.nvim? #20

jondkinney opened this issue Aug 24, 2024 · 9 comments

Comments

@jondkinney
Copy link

jondkinney commented Aug 24, 2024

I can't figure out the right config to get the plugin to load properly within the context of my AstroNvim setup using the Lazy.nvim plugin manager.

Lazy shows that easypick is loaded, but :Easypick isn't an available user command to run.

Here's the current config I'm trying to use:

return {
  "nvim-telescope/telescope.nvim",
  dependencies = {
    "axkirillov/easypick.nvim",
    lazy = false,
  },
  config = function(plugin, opts)
    local easypick = require "easypick"

    require "astronvim.plugins.configs.telescope"(plugin, opts)
    require("telescope").load_extension "easypick"

    -- only required for the example to work
    local get_default_branch = "git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'"
    local base_branch = vim.fn.system(get_default_branch):gsub("\n", "") or "main"

    easypick.setup {
      pickers = {
        -- add your custom pickers here
        -- below you can find some examples of what those can look like

        -- list files inside current folder with default previewer
        {
          -- name for your custom picker, that can be invoked using :Easypick <name> (supports tab completion)
          name = "ls",
          -- the command to execute, output has to be a list of plain text entries
          command = "ls",
          -- specify your custom previwer, or use one of the easypick.previewers
          previewer = easypick.previewers.default(),
        },

        -- diff current branch with base_branch and show files that changed with respective diffs in preview
        {
          name = "changed_files",
          command = "git diff --name-only $(git merge-base HEAD " .. base_branch .. " )",
          previewer = easypick.previewers.branch_diff { base_branch = base_branch },
        },

        -- list files that have conflicts with diffs in preview
        {
          name = "conflicts",
          command = "git diff --name-only --diff-filter=U --relative",
          previewer = easypick.previewers.file_diff(),
        },
      },
    }
  end,
}

Any pointers would be greatly appreciated!

@jaydorsey
Copy link

}

end,
}

There might be a better way to do this, but adding lazy = false after your last end might work. That's how I have mine setup. There might be a better way to get it to load (trigger or something) but I think that's at least worth a try.

@axkirillov
Copy link
Owner

axkirillov commented Oct 14, 2024

Hi John, did you solve this problem? I don't use easypick anymore, but I had no problems with Lazy, when I did
@jondkinney

@russell-knight
Copy link

russell-knight commented Nov 8, 2024

I'm having trouble getting this working with Lazy as well. My config is below. I'm able to invoke the EasyPicker command, but any of the options I select (e.g changed_files) just opens Telescope, but doesn't populate it with anything.

return {
	"axkirillov/easypick.nvim",
	dependencies = "nvim-telescope/telescope.nvim",
	config = function()
		local easypick = require("easypick")

		-- required for git pickers
		local get_default_branch = "git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'"
		local base_branch = vim.fn.system(get_default_branch) or "main"

		easypick.setup({
			pickers = {
				-- add your custom pickers here
				-- below you can find some examples of what those can look like

				-- list files inside current folder with default previewer
				{
					-- name for your custom picker, that can be invoked using :Easypick <name> (supports tab completion)
					name = "ls",
					-- the command to execute, output has to be a list of plain text entries
					command = "ls",
					-- specify your custom previwer, or use one of the easypick.previewers
					previewer = easypick.previewers.default(),
				},

				-- diff current branch with base_branch and show files that changed with respective diffs in preview
				{
					name = "changed_files",
					command = "git diff --name-only $(git merge-base HEAD " .. base_branch .. " )",
					previewer = easypick.previewers.branch_diff({ base_branch = base_branch }),
				},

				-- list files that have conflicts with diffs in preview
				{
					name = "conflicts",
					command = "git diff --name-only --diff-filter=U --relative",
					previewer = easypick.previewers.file_diff(),
				},
			},
		})
	end,
}

@axkirillov
Copy link
Owner

Hello. I will paste my full easypick config here.

-- get default branch
local default_branch = vim.fn.system("git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'") or
"main"

return {
	'axkirillov/easypick.nvim',
	branch = 'develop',
	dependencies = 'nvim-telescope/telescope.nvim',
	config = function()
		local easypick = require("easypick")
		easypick.setup({
			pickers = {
				{
					name = "changed files",
					command = "git diff --name-only $(git merge-base HEAD " .. default_branch .. " )",
					previewer = easypick.previewers.branch_diff({ base_branch = default_branch })
				},
				{
					name = "conflicts",
					command = "git diff --name-only --diff-filter=U --relative",
					previewer = easypick.previewers.file_diff(),
				},
			}
		})

		local ns = { noremap = true, silent = true }
		vim.keymap.set("n", "<C-p>", ":Easypick<CR>", ns)
	end
}

@axkirillov
Copy link
Owner

axkirillov commented Nov 8, 2024

For me it works. The only problem I sometimes have, is that in some repos
git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!' fails with an error message, so, you can check that, and act accordingly @russell-knight

@axkirillov
Copy link
Owner

Actually, this command works reliably for me git remote show origin | grep 'HEAD branch' | cut -d' ' -f5. I will update the docs with it.

@axkirillov
Copy link
Owner

@jondkinney easypick is not a telescope extension, so you don't need this line

    require("telescope").load_extension "easypick"

@russell-knight
Copy link

Hi @axkirillov thanks for your reply. I've tried both your original suggestion and replacing the git rev... line with git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 but I'm still facing the same issue. It's worth mentioning that I get the same outcome when I run any of the custom pickers I have set up (ls, changed_files etc.).

Is there any more information I can provide to help debug this? I am on Windows using Neovim v0.10.2.

@axkirillov
Copy link
Owner

@russell-knight what happens, when you do :! git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 ?

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

No branches or pull requests

4 participants