Skip to content

Telescope find_files Fails update_focused_file #1815

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

Closed
alex-courtis opened this issue Dec 9, 2022 · 6 comments · Fixed by #1820
Closed

Telescope find_files Fails update_focused_file #1815

alex-courtis opened this issue Dec 9, 2022 · 6 comments · Fixed by #1820
Labels
bug Something isn't working regression Existing functionality broken

Comments

@alex-courtis
Copy link
Member

Description

Focused file is not updated following telescope find file when git is enabled.

Neovim version

NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Linux 6.0.11-arch1-1

nvim-tree version

f8489c9

Minimal config

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-dev/site]]
local package_root = "/tmp/nvt-dev/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "/home/alex/.local/share/nvim/vundle/nvim-tree.lua.dev",
      "nvim-tree/nvim-web-devicons",
      'nvim-lua/plenary.nvim',
      'nvim-telescope/telescope-fzf-native.nvim',
      'nvim-telescope/telescope.nvim',
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree 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 setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup({
    auto_reload_on_write = true,
    create_in_closed_folder = false,
    disable_netrw = false,
    hijack_cursor = false,
    hijack_netrw = true,
    hijack_unnamed_buffer_when_opening = false,
    ignore_buffer_on_setup = false,
    open_on_setup = false,
    open_on_setup_file = false,
    sort_by = "name",
    root_dirs = {},
    prefer_startup_root = false,
    sync_root_with_cwd = false,
    reload_on_bufenter = false,
    respect_buf_cwd = false,
    on_attach = "disable",
    remove_keymaps = false,
    select_prompts = false,
    view = {
      adaptive_size = false,
      centralize_selection = false,
      width = 30,
      hide_root_folder = false,
      side = "left",
      preserve_window_proportions = false,
      number = false,
      relativenumber = false,
      signcolumn = "yes",
      mappings = {
        custom_only = false,
        list = {
          -- user mappings go here
        },
      },
      float = {
        enable = false,
        quit_on_focus_loss = true,
        open_win_config = {
          relative = "editor",
          border = "rounded",
          width = 30,
          height = 30,
          row = 1,
          col = 1,
        },
      },
    },
    renderer = {
      add_trailing = false,
      group_empty = false,
      highlight_git = false,
      full_name = false,
      highlight_opened_files = "none",
      root_folder_label = ":~:s?$?/..?",
      indent_width = 2,
      indent_markers = {
        enable = false,
        inline_arrows = true,
        icons = {
          corner = "",
          edge = "",
          item = "",
          bottom = "",
          none = " ",
        },
      },
      icons = {
        webdev_colors = true,
        git_placement = "before",
        padding = " ",
        symlink_arrow = "",
        show = {
          file = true,
          folder = true,
          folder_arrow = true,
          git = true,
        },
        glyphs = {
          default = "",
          symlink = "",
          bookmark = "",
          folder = {
            arrow_closed = "",
            arrow_open = "",
            default = "",
            open = "",
            empty = "",
            empty_open = "",
            symlink = "",
            symlink_open = "",
          },
          git = {
            unstaged = "",
            staged = "",
            unmerged = "",
            renamed = "",
            untracked = "",
            deleted = "",
            ignored = "",
          },
        },
      },
      special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
      symlink_destination = true,
    },
    hijack_directories = {
      enable = true,
      auto_open = true,
    },
    update_focused_file = {
      enable = true,
      update_root = false,
      ignore_list = {},
    },
    ignore_ft_on_setup = {},
    system_open = {
      cmd = "",
      args = {},
    },
    diagnostics = {
      enable = false,
      show_on_dirs = false,
      show_on_open_dirs = true,
      debounce_delay = 50,
      severity = {
        min = vim.diagnostic.severity.HINT,
        max = vim.diagnostic.severity.ERROR,
      },
      icons = {
        hint = "",
        info = "",
        warning = "",
        error = "",
      },
    },
    filters = {
      dotfiles = false,
      custom = {},
      exclude = {},
    },
    filesystem_watchers = {
      enable = true,
      debounce_delay = 50,
      ignore_dirs = {},
    },
    git = {
      enable = true,
      ignore = true,
      show_on_dirs = true,
      show_on_open_dirs = true,
      timeout = 400,
    },
    actions = {
      use_system_clipboard = true,
      change_dir = {
        enable = true,
        global = false,
        restrict_above_cwd = false,
      },
      expand_all = {
        max_folder_discovery = 300,
        exclude = {},
      },
      file_popup = {
        open_win_config = {
          col = 1,
          row = 1,
          relative = "cursor",
          border = "shadow",
          style = "minimal",
        },
      },
      open_file = {
        quit_on_open = false,
        resize_window = true,
        window_picker = {
          enable = true,
          chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
          exclude = {
            filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
            buftype = { "nofile", "terminal", "help" },
          },
        },
      },
      remove_file = {
        close_window = true,
      },
    },
    trash = {
      cmd = "gio trash",
      require_confirm = true,
    },
    live_filter = {
      prefix = "[FILTER]: ",
      always_show_folders = true,
    },
    tab = {
      sync = {
        open = false,
        close = false,
        ignore = {},
      },
    },
    notify = {
      threshold = vim.log.levels.INFO,
    },
    log = {
      enable = true,
      truncate = true,
      types = {
        all = false,
        config = false,
        copy_paste = false,
        dev = true,
        diagnostics = false,
        git = false,
        profile = false,
        watcher = false,
      },
    },
  })

  local nt_api = require("nvim-tree.api")

  vim.keymap.set("n", ";", ":", { noremap = true })
  vim.keymap.set("n", "<space>a", nt_api.tree.open, { noremap = true })
  vim.keymap.set("n", "<space>o", [[ :wincmd p<CR> ]], { noremap = true })
  vim.keymap.set("n", "<space>i", require('telescope.builtin').buffers, { noremap = true })
  vim.keymap.set("n", "<bs>f", require('telescope.builtin').find_files, { noremap = true })
end

Steps to reproduce

touch a b
git init
:NvimTreeOpen
:wincmd p
:find a
:find b
:ls!
  1 #h   "a"                            line 1
  2u a-  "NvimTree_1"                   line 0
  3 %a   "b"                            line 1
:NvimTreeOpen
:lua require('telescope.builtin').find_files (a)
:lua require('telescope.builtin').find_files (b)
:ls!
  1 #h   "a"                            line 1
  2u a-  "NvimTree_1"                   line 0
 18 %a   "b"                            line 1

Expected behavior

b focused

Actual behavior

a focused for telescope case

@alex-courtis alex-courtis added bug Something isn't working regression Existing functionality broken labels Dec 9, 2022
@alex-courtis
Copy link
Member Author

broken at b17358f

@alex-courtis
Copy link
Member Author

alex-courtis commented Dec 11, 2022

We have a race condition with two (valid) calls to find-file.fn a and b. It's scheduled:

-- if we don't schedule, it will search for NvimTree

The schedule was added here: 64c098d

@kyazdani42 can you remember the case that required that schedule? #988

Possible solutions:

  1. lock find_file so that it is sequentially executed (very problematic)
  2. resolve "if we don't schedule, it will search for NvimTree" via a means other than a scheduled call
  3. don't schedule at all

Edit:
4. Debounce all find_file operations, executing the last

@kyazdani42
Copy link
Member

I don't think i remember the exact purpose of the schedule to be honest, this change was added last february and i believe back then the code had asynchronous parts that forced me to use schedules here and there. Not sure this is needed anymore.

@kyazdani42
Copy link
Member

Note that after removing the schedule on my end, this feature seems to behave as expected.

@alex-courtis
Copy link
Member Author

Many thanks @kyazdani42

nvim events and ordering are always tricky ;)

alex-courtis added a commit that referenced this issue Dec 16, 2022
…ile with 15ms default (#1820)

* fix(#1815): don't schedule find file calls

* fix(#1815): debounce BufEnter find_file

* fix(#1815): deprecate nvim-tree.find_file

* fix(#1815): debounce BufEnter find_file

* fix(#1815): debounce BufEnter find_file
alex-courtis added a commit that referenced this issue Dec 16, 2022
@alex-courtis
Copy link
Member Author

@alex-courtis alex-courtis reopened this Dec 16, 2022
alex-courtis added a commit that referenced this issue Dec 16, 2022
…ocused_file with 15ms default (#1820)"

This reverts commit 623cecb.
alex-courtis added a commit that referenced this issue Dec 16, 2022
…update_focused_file with 15ms default (#1820)""

This reverts commit a8d26bb.
alex-courtis added a commit that referenced this issue Dec 16, 2022
…ile with 15ms default (#1828)

* Revert "Revert "fix(#1815): don't schedule find_file calls, debounce update_focused_file with 15ms default (#1820)""

This reverts commit a8d26bb.

* fix(#1723): find_file for externally created new file results in folder unable to be opened

* fix(#1723): find_file for externally created new file results in folder unable to be opened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Existing functionality broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants