Closed davidscotson closed 3 years ago
@davidscotson yeah I've looked into this before to some degree. I have an idea to resolve this. I'll give it a go later. Opening in telescope project by default is a great idea. I know it's something you could probably set up yourself but I will look into adding a global variable or something for this also
Moving the cd command before the call to the builtin (and adding one in the case of the grep) appears to have sorted this for me.
diff --git a/lua/telescope/_extensions/project_actions.lua b/lua/telescope/_extensions/project_actions.lua
1 index ad6c1f9..390ed16 100644
2 --- a/lua/telescope/_extensions/project_actions.lua
3 +++ b/lua/telescope/_extensions/project_actions.lua
4 @@ -70,13 +70,14 @@ end
5 project_actions.find_project_files = function(prompt_bufnr)
6 local dir = actions.get_selected_entry(prompt_bufnr).value
7 actions._close(prompt_bufnr, true)
8 - builtin.find_files({cwd = dir})
9 vim.fn.execute("cd " .. dir, "silent")
10 + builtin.find_files({cwd = dir})
11 end
12 -
13 project_actions.search_in_project_files = function(prompt_bufnr)
14 local dir = actions.get_selected_entry(prompt_bufnr).value
15 actions._close(prompt_bufnr, true)
16 + vim.fn.execute("cd " .. dir, "silent")
17 builtin.live_grep({cwd = dir})
18 end
19 -
~
Awesome! Thanks @davidscotson That was what I was going to try. I will get onto that later
@davidscotson should be resolved with the latest commit. Appreciate the help on this one.
I'm expecting the working directory to change to the root of the project I switch to, even if I select a file within a sub-directory.
I believe it does work like this sometimes, but it also fails to happen quite a lot, and I remain with pwd set as the directory I was in before.
I think, though it seems odd, that the difference is whether I start vim initially with a directory or a file. If the first thing I open is a directory, it seems to break the changing of the pwd when I jump to a project file.
Starting without a directory or file, which for me currently opens startify (though I'm hoping to replace that with opening into this plugin by default), also shows issues, but it works if I jump to a project from the start screen, but if I select a file from the startify list, then try to jump from there, the issue returns.
Notably, the w command to change the working directory seems to always work, but the f and s commands (as well as the default) show this issue, which leads me to believe it's something that the telescope builtins are doing when they are called, but I have no idea what that might be or why being in a netrw directory or startify opened file would affect it.