nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.13k stars 609 forks source link

:NvimTreeFindFile not working #783

Closed AgentCosmic closed 2 years ago

AgentCosmic commented 2 years ago

nvim-tree only opens the window but does not go to the file when I run :NvimTreeFindFile. I remember it working before. But it stopped working quite some time ago.

waseidel commented 2 years ago

I have just installed and that command isn't working

kyazdani42 commented 2 years ago

works just fine for me, i cannot reproduce if you don't provide more informations.

kuznetsss commented 2 years ago

I updated today and it doesn't find file in tree in some cases. What information would be helpful to find out what's wrong? I use nvim 0.5.1 on Linux and nvim-tree with default options.

For example, if I open some file in nvim from my home directory

~ $ nvim Documents/vimwiki/Vim.md

and then use the command

:NvimTreeFindFile

it opens nvim-tree just in my home directory

xeluxee commented 2 years ago

I'm experiencing the same problem I think this issue is related to some LSP servers running in single file mode (e.g. clangd on a single file) When I disable LSP (:LspStop) NvimTreeFindFile works correctly. Maybe that happens because NvimTree tries to find LSP root directory, but since LSP is running in single file mode it goes to home directory

Screenshot from :LspInfo: clangd-singlefile

Edit: my bad, this doesn't happen every time so maybe it isn't related to LSP

Edit2: if I press R (to reload files in NvimTree) after :NvimTreeFindFile it works well

xeluxee commented 2 years ago

So this shouldn't be LSP-related, but it's a matter of reloading If you press R after finding file NvimTree displays files well

Dornat commented 2 years ago

If you press R after finding file NvimTree displays files well

I can confirm this. When I use NvimTreeFindFile it doesn't work properly. Then I press R and it works like a charm.

kyazdani42 commented 2 years ago

still cannot reproduce even with provided steps... Maybe someone could provide a minimal sample config file to reproduce this issue consistently.

kuznetsss commented 2 years ago

NvimTreeFindFile still doesn't work correctly for me after the fix

AgentCosmic commented 2 years ago

Fix didn't work for me either. Even after pressing R.

xeluxee commented 2 years ago

Just out of curiosity, are you LunarVim users?

AgentCosmic commented 2 years ago

Nope, custom config https://github.com/AgentCosmic/neovim

kuznetsss commented 2 years ago

I also use custom config https://github.com/kuznetsss/nvim_lua_config

kuznetsss commented 2 years ago

I have debugged the issue a little and find that here https://github.com/kyazdani42/nvim-tree.lua/blob/2e33b1654384921ec1cc9656a2018744f3f1ce81/lua/nvim-tree/view.lua#L227

pcall returns error Cursor position outside buffer

Also if you put here https://github.com/kyazdani42/nvim-tree.lua/blob/2e33b1654384921ec1cc9656a2018744f3f1ce81/lua/nvim-tree/lib.lua#L221-L226 just M.redraw() instead of calling git.load_project_status() everything works fine for me.

So maybe to reproduce the issue you just need to be not in git repo.

Update: The problematic call of git.load_project_status() mentioned above ends with the line https://github.com/kyazdani42/nvim-tree.lua/blob/2e33b1654384921ec1cc9656a2018744f3f1ce81/lua/nvim-tree/git/init.lua#L59

So it seems the problem in the lambda https://github.com/kyazdani42/nvim-tree.lua/blob/2e33b1654384921ec1cc9656a2018744f3f1ce81/lua/nvim-tree/lib.lua#L222-L225

I'll make PR fixing this