nvim-telescope / telescope-file-browser.nvim

File Browser extension for telescope.nvim
MIT License
1.68k stars 92 forks source link

[question] How to keep `cwd` at project root? #385

Closed fmorroni closed 5 months ago

fmorroni commented 5 months ago

I'm working on a C project with multiple Makefiles. Something like:

- rootDir/
  - Makefile
  - file1.c
  - A/
    - Makefile
    - file2.c
  - B/
    - Makefile
    - file3.c
  - C/
    - file4.c

Of course the root of the project should be rootDir where the outermost Makefile is located. And I'd expect the filebrowser's cwd to remain at rootDir no matter which file in the project I open. For example if I open C/file4.c it works as expected because there is no Makefile in C/. But if I open A/file2.c the cwd is changed to A/. This is annoying because now when I try to do a file search or live grep, only results from files inside A/ appear. So how can I make sure the cwd remains at the root project?

jamestrew commented 5 months ago

There's nothing inside telescope core or this extension that will change the cwd without explicitly doing so (such as the change_cwd action).

I suspect there's something in your personal config that is managing this. Maybe some personal autocmd or some sort of project management type plugin that's using Makefile existence for a reason to change the cwd.

fmorroni commented 5 months ago

There's nothing inside telescope core or this extension that will change the cwd without explicitly doing so (such as the change_cwd action).

I suspect there's something in your personal config that is managing this. Maybe some personal autocmd or some sort of project management type plugin that's using Makefile existence for a reason to change the cwd.

Hmm yeah that's what I assumed at first. But the only thing I think could be responsible is the language server (clangd). But I checked the ls client's root on files inside folders with a Makefile and it seemed to be set correctly to the project's root.

I'll have to check that again.

In any case I did side step the issue by renaming all inner Makefiles to something else and now it's working as expected.

jamestrew commented 5 months ago

I don't think it's the language server. There's nothing in the LSP spec for automatically changing cwd. Just to make sure, I tried replicating this and I can't (with or without clangd).