xvzc / chezmoi.nvim

Chezmoi plugin for neovim
MIT License
73 stars 3 forks source link

find_files picker is incompatible with select_tab_drop #6

Closed hejops closed 6 months ago

hejops commented 6 months ago

It seems like find_files only calls chezmoi edit if the telescope select action is the default (open in current window). If select_tab_drop is set as the default, select_tab_drop will still be called correctly, but chezmoi edit will not.

Minimal config

vim.fn.system({ "rm", "-rf", "/tmp/nvim/site" })
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            "nvim-telescope/telescope.nvim",
            {
                "xvzc/chezmoi.nvim",
                requires = { "nvim-lua/plenary.nvim" },
            },
        },

        config = {
            package_root = package_root,
            compile_path = install_path .. "/plugin/packer_compiled.lua",
            display = { non_interactive = true },
        },
    })
end
_G.load_config = function()
    local telescope_actions = require("telescope.actions")
    require("telescope").setup({
        defaults = {
            mappings = {
                -- enabling these will disable chezmoi edit
                i = { ["<cr>"] = telescope_actions.select_tab_drop },
                n = { ["<cr>"] = telescope_actions.select_tab_drop },
            },
        },
    })
    require("telescope").load_extension("chezmoi")

    vim.keymap.set("n", "<space>c", require("telescope").extensions.chezmoi.find_files)
end
if vim.fn.isdirectory(install_path) == 0 then
    print("Installing Telescope and dependencies.")
    vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()

vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]])
xvzc commented 6 months ago

Fixed in the latest release

hejops commented 6 months ago

Great, thanks!

azinsharaf commented 6 months ago

i am using b62a4ad commit and still have this issue. please advice.

xvzc commented 6 months ago

@azinsharaf Could you kindly share your configs for Telescope and chezmoi.nvim?

azinsharaf commented 6 months ago

chezmoi.lua

return {
    "xvzc/chezmoi.nvim",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function()
        require("chezmoi").setup({
            -- your configurations
            edit = {
                watch = true, -- Set true to automatically apply on save.
                force = true, -- Set true to force apply. Works only when watch = true.
            },
            notification = {
                on_open = true, -- vim.notify when start editing chezmoi-managed file.
                on_apply = true, -- vim.notify on apply.
            },
        })
    end,
}

telescope.lua:

return {
    "nvim-telescope/telescope.nvim",
    branch = "0.1.x",
    dependencies = {
        "nvim-lua/plenary.nvim",
        -- Fuzzy Finder Algorithm which requires local dependencies to be built.
        -- Only load if `make` is available. Make sure you have the system
        -- requirements installed.
        {
            "nvim-telescope/telescope-fzf-native.nvim",
            -- NOTE: If you are having trouble with this installation,
            --       refer to the README for telescope-fzf-native for more instructions.
            build = "make",
            cond = function()
                return vim.fn.executable("make") == 1
            end,
        },
        {
            "nvim-tree/nvim-web-devicons",
        },
    },
    config = function()
        local telescope = require("telescope")
        local actions = require("telescope.actions")

        telescope.setup({
            defaults = {
                mappings = {
                    i = {
                        ["<C-k>"] = actions.move_selection_previous, --move to prev result
                        ["<C-j>"] = actions.move_selection_next, --move to next result
                    },
                },
            },
            extensions = {
                file_browser = {
                    hidden = { file_browser = true, folder_browser = true },
                    display_stat = { date = true, size = true, mode = true },
                },

                fzf = {
                    fuzzy = true, -- false will only do exact matching
                    override_generic_sorter = true, -- override the generic sorter
                    override_file_sorter = true, -- override the file sorter
                    case_mode = "smart_case", -- or "ignore_case" or "respect_case"
                    -- the default case_mode is "smart_case"
                },
            },
        })

        require("telescope").load_extension("fzf")
        require("telescope").load_extension("chezmoi")
        vim.keymap.set('n', '<leader>cz', telescope.extensions.chezmoi.find_files, {})

    end,
}

nvim error:


E5108: Error executing lua: ...-data/lazy/telescope.nvim/lua/telescope/actions/init.lua:74:
 Key does not exist for 'telescope.actions': select_tab_drop
stack traceback:
        [C]: in function 'error'
        ...-data/lazy/telescope.nvim/lua/telescope/actions/init.lua:74: in function '__inde
x'
        ...zy/chezmoi.nvim/lua/telescope/_extensions/find_files.lua:67: in function 'attach
_mappings'
        ...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:287: in function 'apply
_keymap'
        .../nvim-data/lazy/telescope.nvim/lua/telescope/pickers.lua:569: in function 'find'

        ...zy/chezmoi.nvim/lua/telescope/_extensions/find_files.lua:74: in function <...zy/
chezmoi.nvim/lua/telescope/_extensions/find_files.lua:37>
xvzc commented 6 months ago

@azinsharaf Are you using the latest version of telescope?

azinsharaf commented 6 months ago

yes, 0.1.5

xvzc commented 6 months ago

@azinsharaf Sorry to bother you. Please try with the latest release again, and check out that we can now set the select keymap through your config

local default_config = {
  edit = {
    watch = false,
    force = false,
  },
  notification = {
    on_open = true,
    on_apply = true,
    on_watch = false,
  },
  telescope = {
    select = { "<CR>" },
  },
}
azinsharaf commented 6 months ago

you did it! thanks for the quick turnaround!

xvzc commented 6 months ago

No problems!