weirongxu / coc-explorer

📁 Explorer for coc.nvim
MIT License
1.14k stars 45 forks source link

Bug: explorer freezes on expanding a subdirectory in an empty directory #417

Closed svanharmelen closed 1 year ago

svanharmelen commented 3 years ago

Take this folder structure (these are all empty directories without any files):

test
└── some
   └── thing

When I change my directory to test, open nvim and CocExplorer, navigate to the directory some and then press l to expand the directory, everything freezes and I need to open another terminal and kill the hanging instance.

Another way to trigger the bug is to open nvim and CocExplorer and then in the explorer type A to create a new directory and then type some/thing as the directory. It will create the directories and then freeze as well.

weirongxu commented 3 years ago

I tried the default setting of explorer.autoExpandOptions and recursiveSingle, but the issue still can't be reproduced. Can you provide a minimal reproduce configuration?

svanharmelen commented 3 years ago

I tested and debugged things a bit more and found this code in my init.nvim to be the problem:

function! s:ShowFilename()
    let s:node_info = CocAction('runCommand', 'explorer.getNodeInfo', 0)
    redraw | echohl Debug | echom exists('s:node_info.fullpath') ?
    \ 'Explorer: ' . s:node_info.fullpath : '' | echohl None
endfunction
autocmd CursorMoved \[coc-explorer\]* :call <SID>ShowFilename()

If I comment out the line let s:node_info = CocAction('runCommand', 'explorer.getNodeInfo', 0) everything works as expected, so it seems CocAction('runCommand', 'explorer.getNodeInfo', 0) is causing the freeze.

weirongxu commented 3 years ago

It may be some problems with CocAction, because CocAction cannot be executed concurrently, you can consider using CocActionAsync(..., s:callbackFunction) ...

weirongxu commented 3 years ago
function! s:PrintFileName(err, node_info)
  redraw | echohl Debug | echom exists('a:node_info.fullpath') ?
        \ 'Explorer: ' . a:node_info.fullpath : '' | echohl None
endfunction
function! s:ShowFilename()
  call CocActionAsync('runCommand', 'explorer.getNodeInfo', 0, function('s:PrintFileName'))
endfunction
autocmd CursorMoved \[coc-explorer\]* :call <SID>ShowFilename()
svanharmelen commented 3 years ago

That seems to work perfectly! Thanks 👍🏻

svanharmelen commented 3 years ago

Still a bit funny through, that explorer.getNodeInfo only freezes when there isn't a node (file) to fetch but only directories which it doesn't seem to fetch. Is that expected and not possibly part of the problem?

weirongxu commented 3 years ago

OK, keep this issue open first, I will look into CocAction in the future.

svanharmelen commented 1 year ago

Closing this as I no longer (for a while now) use coc-explorer so I'm not able to tell if this is changed or fixed.