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

Incorrect cwd when call vim with '-c cd xxx' #5037

Closed
aispeaking opened this issue Jun 11, 2024 · 6 comments
Closed

Incorrect cwd when call vim with '-c cd xxx' #5037

aispeaking opened this issue Jun 11, 2024 · 6 comments

Comments

@aispeaking
Copy link
Contributor

aispeaking commented Jun 11, 2024

Result from CocInfo

versions

vim version: VIM - Vi IMproved 9.0 9001563
node version: v20.12.0
coc.nvim version: 0.0.82-c3ae5c3 2024-05-23 20:39:40 +0800
coc.nvim directory: /home/liyt/code/extern/vim-runtime/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

2024-06-11T16:20:08.984 INFO (pid:852781) [extension:coc-git] - Looking for git in: git
2024-06-11T16:20:09.017 WARN (pid:852781) [workspace] - Extension "undefined" registered synchronized autocmd "VimLeavePre", which could be slow.
2024-06-11T16:20:10.176 INFO (pid:852781) [plugin] - coc.nvim initialized with node: v20.12.0 after 1423
2024-06-11T16:20:10.297 INFO (pid:852781) [extension:@yaegassy/coc-marksman] - marksman binary is already downloaded
2024-06-11T16:20:10.302 INFO (pid:852781) [language-client-index] - Language server "marksman" started with 852834
2024-06-11T16:20:10.343 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:11.911 INFO (pid:852781) [extension:@yaegassy/coc-marksman] - Client onReady
2024-06-11T16:20:11.943 INFO (pid:852781) [extension:@yaegassy/coc-marksman] - Got marksman/status notification
2024-06-11T16:20:15.053 INFO (pid:852781) [attach] - receive notification: openList [ 'mru' ]
2024-06-11T16:20:15.054 INFO (pid:852781) [extension:coc-lists] - cwd: /home/liyt/.config/coc/extensions/node_modules/coc-lists/lib
2024-06-11T16:20:15.088 INFO (pid:852781) [extension:coc-lists] - files: /share/note/notebook.md
2024-06-11T16:20:15.095 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 2, 2 ]
2024-06-11T16:20:15.114 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:16.677 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:16.727 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:22.525 INFO (pid:852781) [attach] - receive notification: openList [ 'mru' ]
2024-06-11T16:20:22.526 INFO (pid:852781) [extension:coc-lists] - cwd: /share/note
2024-06-11T16:20:22.556 INFO (pid:852781) [extension:coc-lists] - files: /share/note/notebook.md
2024-06-11T16:20:22.567 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 2, 3 ]
2024-06-11T16:20:22.584 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:23.560 INFO (pid:852781) [attach] - receive notification: doAutocmd [ 7 ]
2024-06-11T16:20:26.440 INFO (pid:852781) [attach] - receive notification: showInfo []

Describe the bug

When using vim /share/note/notebook.md -c 'cd /share/note and then open mru list, no recent files in /share/note exist.

I add some log to print the cwd in mru list and found it is not the expected one as :pwd.

Reproduce the bug

  1. Open terminial and cd to any directory A.
  2. Open file in another directory B and cd to B in vim arguments: vim /B/test.txt -c 'cd /B'. Make sure B is not a sub dir of A.
  3. Call CocList mru in vim. /B/test.txt is not there.
  4. Call cd /B in vim.
  5. Call CocList mrc again. /B/test.txt is in the list.

Screenshots (optional)

If applicable, add screenshots to help explain your problem.

@fannheyward
Copy link
Member

Can't reproduce with vim 9.1 and nvim. Here's my steps:

  1. mkdir -p ~/A and mkdir -p ~/B
  2. cd ~/A
  3. vim B/test4.txt -c "cd ~/B"
  4. CocList mru, B/test4.txt exists

@aispeaking
Copy link
Contributor Author

@fannheyward

  1. vim B/test4.txt -c "cd ~/B"

Missing the ~/ before B, which create a folder under current folder A. C-g will print ~/A/B/test4.txt.
Using vim ~/B/test4.txt -c "cd ~/B" instead.

@fannheyward
Copy link
Member

fannheyward commented Jul 23, 2024

Reproduced. The core issue is workspace root detecting.

vim ~/B/test4.txt -c "cd ~/B" still uses ~/A as cwd, by default, mru only lists files that under current cwd, that's why test4 is missing. You can use :CocList mru -A to list all.

https://github.com/neoclide/coc-lists/blob/720f8713860a6c45be6aac6b042416c9de680173/src/mru.ts#L95

coc.nvim didn't change the root at cmd -c "cd ~/B". Looks like vim didn't fire DirChanged on the cmd.

events.on('DirChanged', cwd => {
this._cwd = normalizeFilePath(cwd)
}, null, this.disposables)

@aispeaking
Copy link
Contributor Author

@fannheyward How about init this._cwd with getcwd()?

@fannheyward
Copy link
Member

Yes, the _cwd already inited with cwd.

@fannheyward
Copy link
Member

This issue only occurs in vim, nvim will fire DirChanged as expected. Closing this as it's upstream issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants