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

Incompatible with dressing.nvim #66

Closed
AckslD opened this issue Jan 14, 2022 · 4 comments
Closed

Incompatible with dressing.nvim #66

AckslD opened this issue Jan 14, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@AckslD
Copy link

AckslD commented Jan 14, 2022

Description

Not sure if this issue should be raised here or at https://github.com/stevearc/dressing.nvim but these plugins don't work well together when for example creating new files. See below.

Neovim version

NVIM v0.7.0-dev+890-g574a582202
Build type: RelWithDebInfo
LuaJIT 2.0.5

Operating system and version

arch linux 5.15.12-arch1-1

Steps to reproduce

  1. have telescope-file-browser.nvim and dressing.nvim installed.
  2. create a new file using the browser
  3. enter the file name and click enter

Expected behavior

The telescope prompt to stay open and no error being raised.

Actual behavior

You get the error:

Error executing vim.schedule lua callback: ...pack/packer/opt/telescope.nvim/lua/telescope/pickers.lua:851: Invalid buffer id: 7
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ...pack/packer/opt/telescope.nvim/lua/telescope/pickers.lua:851: in function 'reset_prompt'
        ...pack/packer/opt/telescope.nvim/lua/telescope/pickers.lua:874: in function 'refresh'
        ....nvim/lua/telescope/_extensions/file_browser/actions.lua:82: in function 'on_confirm'
        ...e/pack/packer/start/dressing.nvim/lua/dressing/input.lua:72: in function ''
        vim.lua: in function ''
        vim.lua: in function <vim.lua:0>

Minimal config

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',
        requires = {
          'nvim-lua/plenary.nvim',
          'nvim-telescope/telescope-file-browser.nvim',
        },
      },
      'stevearc/dressing.nvim',
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('file_browser')
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()]]
@AckslD AckslD added the bug Something isn't working label Jan 14, 2022
@fdschmidt93
Copy link
Member

fdschmidt93 commented Jan 15, 2022

I guess the problem here is that a vim.ui.input float with dressing.nvim triggers a BufLeave autocmd which closes the picker.

While telescope-file-browser could wrap vim.ui.input into noautocmd or eventignore = "all", I think vim.ui overrides should take care of that, assuming of course there's no need for autocmd during vim.ui.input (not sure what the use case would be). I guess you could also make the case that telescope should maybe try to avoid using autocommands for closing the picker to begin with.

As a band aid fix, manually mapping the below should circumvent the issue for you for the time being.

["<A-c>"] = function(prompt_bufnr)
  vim.cmd(string.format([[noautocmd require "telescope".extensions.file_browser.actions.create(%)]], prompt_bufnr)
end

(haven't tried it, if no syntax error I think it should work)

@AckslD
Copy link
Author

AckslD commented Jan 16, 2022

Thanks @fdschmidt93, so would you say that this is something that should be fixed in dressing.nvim?

Fixing some small typos the above fix works:

["<A-c>"] = function(prompt_bufnr)
  vim.cmd(string.format([[noautocmd lua require("telescope").extensions.file_browser.actions.create(%d)]], prompt_bufnr))
end

however there are other things such as confirming deleting files etc which doesn't work so well. I think the best for now would be to have an ability to disable dressing for certain buffers. I'll check if this is possible or add this as a feature request.

Anyway closing this since it's not really a telescope-file-browser issue.

Thanks for the help! :)

@AckslD AckslD closed this as completed Jan 16, 2022
@fdschmidt93
Copy link
Member

Confirmation of deletion of files also now uses vim.ui.input, so the same fix should also work just as well.

Maybe with lua autocmds there will also be api for noautocmd, then we could factor that in from within telescope file browser more smoothly I suppose.

@AckslD
Copy link
Author

AckslD commented Jan 16, 2022

Thanks @fdschmidt93 that seems to also work, in then end I did:

local actions = {
    ["i"] = {
        ["<A-c>"] = 'create',
        ["<A-r>"] = 'rename',
        ["<A-m>"] = 'move',
        ["<A-y>"] = 'copy',
        ["<A-d>"] = 'remove',
        ["<C-o>"] = 'open',
        ["<C-g>"] = 'goto_parent_dir',
        ["<C-e>"] = 'goto_home_dir',
        ["<C-w>"] = 'goto_cwd',
        ["<C-t>"] = 'change_cwd',
        ["<C-f>"] = 'toggle_browser',
        ["<C-h>"] = 'toggle_hidden',
        ["<C-s>"] = 'toggle_all',
    },
    ["n"] = {
        ["c"] = 'create',
        ["r"] = 'rename',
        ["m"] = 'move',
        ["y"] = 'copy',
        ["d"] = 'remove',
        ["o"] = 'open',
        ["g"] = 'goto_parent_dir',
        ["e"] = 'goto_home_dir',
        ["w"] = 'goto_cwd',
        ["t"] = 'change_cwd',
        ["f"] = 'toggle_browser',
        ["h"] = 'toggle_hidden',
        ["s"] = 'toggle_all',
    },
}

local function get_action(action)
    return function(prompt_bufnr)
        vim.cmd(string.format([[noautocmd lua require("telescope").extensions.file_browser.actions.%s(%d)]], action, prompt_bufnr))
    end
end

local mappings = {}
for _, mode in ipairs({'i', 'n'}) do
    local keys = {}
    for key, action in pairs(actions[mode]) do
        keys[key] = get_action(action)
    end
    mappings[mode] = keys
end

require("telescope").setup({
    extensions = {
        file_browser = {
            mappings = mappings,
        },
    },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants