helix icon indicating copy to clipboard operation
helix copied to clipboard

File picker should be populated with files under current directory if the current directory is under a hidden directory

Open emi2k01 opened this issue 2 years ago • 5 comments

Reproduction steps

mkdir -p test/{.git,.hidden,foo} \
    && touch test/{.hidden/index.html,foo/main.rs} \
    && cd test/.hidden \
    && hx

press <space>f.

File picker should show index.html but it shows only main.rs because it starts looking from test/ instead of .hidden/.

Since pwd is test/.hidden/, "ignore" configs shouldn't affect the visibility of files under .hidden.

Environment

  • Platform: Linux
  • Helix version: helix v0.5.0-244-g49e06787

emi2k01 avatar Dec 16 '21 02:12 emi2k01

diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs
index 92a59f31..f6279a1b 100644
--- a/helix-core/src/lib.rs
+++ b/helix-core/src/lib.rs
@@ -55,7 +55,7 @@ pub fn find_root(root: Option<&str>) -> Option<std::path::PathBuf> {
 
     for ancestor in root.ancestors() {
         // TODO: also use defined roots if git isn't found
-        if ancestor.join(".git").is_dir() {
+        if is_hidden_dir(&ancestor) || ancestor.join(".git").is_dir() {
             return Some(ancestor.to_path_buf());
         }
     }
@@ -143,6 +143,15 @@ pub fn merge_toml_values(left: toml::Value, right: toml::Value) -> toml::Value {
     }
 }
 
+fn is_hidden_dir(path: &std::path::Path) -> bool {
+    path.is_dir()
+        && path
+            .file_name()
+            .and_then(std::ffi::OsStr::to_str)
+            .map(|file_name| file_name.starts_with("."))
+            == Some(true)
+}
+

would something like this do it? This makes the hidden directory the workspace root if it finds one before finding a git repo.

emi2k01 avatar Dec 16 '21 22:12 emi2k01

I believe you can submit a pull request for this.

pickfire avatar Jan 07 '22 13:01 pickfire

I'm having the same issue, that files in the hidden directory cannot be accessed. Indeed, we can access the files in the hidden directory by applying the above patch. However, if you do it, when you are in the hidden directory, it will become root, and the behavior will be different from when you are in the not hidden directory.

For example, when you make directories like the following and open hx,

mkdir -p test/{.git,.hidden,foo} \
    && touch test/{.hidden/index.html,foo/main.rs} \
    && cd test \
    && hx

the file picker (space + f) shows only foo/main.rs, and the result will be the same after changing the current directory (cd foo in shell or :cd foo in hx), because root is test whether you're in the test or test/foo.

But root becomes .hidden when you're in .hidden, and only index.html is shown if the patch is applied. It feels a little weird.

I'm not sure what is the best, but I can raise some suggestions (ideas aside from implementation)

  1. files under the current directory are shown even if the ancestor is a hidden directory
    (both .hidden/index.html and foo/main.rs are listed when you're in .hidden but only foo/main.rs in test or foo)
  2. toggle whether or not to show hidden files in the picker easily, e.g. press Ctrl-h, (config in [editor.file-picker] will be the default)

hayashikun avatar Feb 19 '22 11:02 hayashikun

Since <space>f opens file picker in the project root it's understandable that it doesn't show the files. Doing <space>F to open the file picker at CWD shows "index.html".

zen3ger avatar Jun 12 '22 15:06 zen3ger

I think that has been solved by the editor.file-picker.hidden = false config setting ?

poliorcetics avatar Apr 23 '24 13:04 poliorcetics