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

Bug: file_tabedit opens file in the wrong directory #1854

Open
4 of 6 tasks
kheaactua opened this issue Feb 25, 2025 · 4 comments
Open
4 of 6 tasks

Bug: file_tabedit opens file in the wrong directory #1854

kheaactua opened this issue Feb 25, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@kheaactua
Copy link

kheaactua commented Feb 25, 2025

RTFM Checklist

  • I have searched exisiting issues / discussions
  • I have read the Wiki including the Advanced section
  • I have read man fzf / I am well versed in shell fzf

Operating system

Linux

Shell

zsh

Neovim version (nvim --version)

v0.11.0-dev-1649+gc47496791a

Fzf version (fzf --version)

0.60.2 (c0d407f7)

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

  • My issue is reproducible with mini.sh
  • My issue IS NOT reproducible with mini.sh
  • I have not tested with mini.sh (not relevant, requires LSP, Windows, etc)

Fzf-lua configuration

require("fzf-lua").setup({
        actions = {
          files = {
            ["default"]     = actions.file_edit_or_qf,
            ["ctrl-x"]      = actions.file_split,
            ["ctrl-v"]      = actions.file_vsplit,
            ["ctrl-t"]      = actions.file_tabedit,
            -- ["ctrl-t"]      = file_tabedit_with_cwd,
            -- ["alt-q"]       = actions.file_sel_to_qf, -- dunno what this does
            -- ["alt-l"]       = actions.file_sel_to_ll, -- dunno what this does
            ["ctrl-l"]      = require'fzf-lua.actions'.arg_add, -- dunno what this does
          },
          buffers = {
            ["default"]     = actions.buf_edit,
            ["ctrl-x"]      = actions.buf_split,
            ["ctrl-v"]      = actions.buf_vsplit,
            ["ctrl-t"]      = actions.buf_tabedit,
          }
        },
        buffers = {
          actions = {
            ["ctrl-x"] = actions.buf_split,
            ["ctrl-d"] = actions.buf_del,
          }
        },
        tabs = {
          actions = {
            ["ctrl-x"] = actions.buf_split,
            ["ctrl-d"] = actions.buf_del,
          }
        },
        -- See https://github.com/ibhagwan/fzf-lua/wiki#can-i-use-ripgreps---globiglob-option-with-live_grep
        grep = {
          rg_glob = true
        }
      })

      -- Set up keyboard shortbuts for fzf, the fuzzy finder
      -- This one searches all the files in the current git repo:
      map('n', '<c-k>', '<cmd>lua require("fzf-lua").git_files()<CR>', { silent = true })
      map('n', '<leader>h', '<cmd>lua require("fzf-lua").oldfiles()<CR>', { silent = true })
      map('n', '<leader>t', '<cmd>lua require("fzf-lua").tabs()<CR>', { silent = true })
      map('n', '<leader><Tab>', '<cmd>lua require("fzf-lua").buffers()<CR>', { silent = true })

      -- Unmap center/<CR> from launching fzf which appears to be mapped by default.
      -- unmap <CR>

      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").grep_project()<CR>', { silent = true, debug = true })
      map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep()<CR>', { silent = true })
      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").grep_project({ rg_opts = "--glob \'!**/unittest*/**\'", debug = True })<CR>', { silent = true })
      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep({ rg_opts = "--glob \'!**/unittest*/**\'", debug = True })<CR>', { silent = true })

      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep()<CR>', { silent = true })

      vim.keymap.set("n", "gsiw",
        function()
          local fzf_lua = require("fzf-lua")
          local current_word = vim.api.nvim_command_output([[ echo expand('<cword>') ]])
          fzf_lua.live_grep({
            cmd = grep_cmd,
            query = current_word,
            cwd = fzf_lua.path.git_root(),
          })
        end,
        { silent = true }
      )

      map('n', '<leader>l', '<cmd>lua require("fzf-lua").lines()<CR>', { silent = true })
      -- map('n', '<leader>w', '<cmd>lua require("fzf-lua").Windows()<CR>', { silent = true })

   end,

Describe the bug / steps to reproduce

Sometime in the last few weeks, actions.file_tabedit has stopped working. Now when I hit ctrl-tab, it opens a new tab for the file but at the wrong directory.

e.g. If I'm editing a file, I can see with echo getcwd() that I'm at /path/to/base/path/to/project. Say I attempt to open include/file.hpp with ctrl-t (file_tabedit), it SHOULD open:

/path/to/base/path/to/project/include/file.hpp

But instead it opens:

/path/to/base/include/file.hpp

which doesn't exist.

file_split and file_vsplit and work as expected, it's only file_tabedit that stopped working.

Steps to reproduce

  1. Use fzf-lua at a commit that includes 9dd089f
  2. Open nvim in /path/to/base
  3. Somehow open a file deeper in the path, i.e. /path/to/base/path/to/project/include/file.hpp. Use tcd to set your current directory to to /path/to/base/path/to/project. - I think tcd is correct, in my case I use nvim-rooter to handle this, as in this example /path/to/base/path/to/project would be a git repo
  4. Attempt to open another file in this git repo using fzf-lua using the file_tabedit actions

Speculation

I assume it's related to 9dd089f changing from tab split to tabnew. When I jump back to 562593a the function works as expected.

I use nvim-rooter as well to set my path as my work is spread through many different git repos. Perhaps it's only setting the tab's cwd, and tabnew creates a tab with the original cwd? Just speculating.

@kheaactua kheaactua added the bug Something isn't working label Feb 25, 2025
@ibhagwan
Copy link
Owner

I assume it's related to 9dd089f changing from tab split to tabnew. When I jump back to 562593a the function works as expected.

I use nvim-rooter as well to set my path as my work is spread through many different git repos. Perhaps it's only setting the tab's cwd, and tabnew creates a tab with the original cwd? Just speculating.

Your analysis is correct, this is due to #1785.

@phanen, @Yarovski, any ideas before I revert this change for file_tabedit?

@Yarovski, maybe you can have your own version of file_tabedit with tabnew as I’m only going to revert these lines, the other changes remain:

-- local vimcmd = "tab split | <auto>"
local vimcmd = "tabnew | setlocal bufhidden=wipe | <auto>"

@phanen
Copy link
Contributor

phanen commented Feb 25, 2025

No objection. But I cannot reproduce the issue as the description.

However I find a new issue: change directory after launch a picker (without a opts.cwd pass in) will make all edit action fail to work.

So I can reproduce in this way

  • (use tcd) to make two tabs have different directory
  • launch picker in tab1
  • navigate to tab2
  • do any edit actions -> fail

But this is irrelevant to 9dd089f

@ibhagwan
Copy link
Owner

However I find a new issue: change directory after launch a picker (without a opts.cwd pass in) will make all edit action fail to work.

Maybe because you’re using hide profile and the edit “resumes” from the previous tab? Does this still happen if you relaunch the files picker?

@phanen
Copy link
Contributor

phanen commented Feb 28, 2025

Does this still happen if you relaunch the files picker?

It work fine. Technically I can still <c-\><c-p>:cd /another/path...

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

3 participants