Skip to content

Feature Request: Excluded path for filter_on_submit, filter_as_you_type #86

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

Closed
nyngwang opened this issue Jan 22, 2022 · 9 comments
Closed
Labels
enhancement New feature or request

Comments

@nyngwang
Copy link

nyngwang commented Jan 22, 2022

As title. This is a must-have I promise. The current situation is that in both cases some stupid folder like ~/Library/ will be scanned and cause the entire tree to get frozen & my computer very hot!

Debug info.

NVIM Version

NVIM v0.7.0-dev+913-ge07a4b97f
Build type: Release
LuaJIT 2.1.0-beta3
@cseickel cseickel added the enhancement New feature or request label Jan 22, 2022
@cseickel
Copy link
Contributor

It's a good idea, the question is how exactly to do this.

I like the idea of excluding glob patterns, but there can be a lot of variation of what each system's built in fd/find/where command will support. Since I am only testing on my own system, I would prefer to just give people the ability to add their own arbitrary arguments to be injected into the find command we ultimately execute. That would offer the ultimate flexibility for the end user without me having to worry about supporting systems I don't have.

Because I love having everything be dynamic, I would make this option take either a string or a function. The function would be told what the root path is and what the search term is and be able to dynamically pass back extra arguments. You might want to use this to have different excludes for different root directories.

What do you think?

@nyngwang
Copy link
Author

nyngwang commented Jan 22, 2022

[...] I would prefer to just give people the ability to add their own arbitrary arguments to be injected into the find command we ultimately execute. [...]

I was thinking about the same! Currently, you provide a string filter_on_submit, I was thinking about passing a lua function with some parameter:

-- ['/'] = 'open_vsplit' -- current one
['/'] = function (tools) -- Or we don't need this param, just use `require('neo-tree')`
  tools.open_vsplit()
  -- require('neo-tree').open_vsplit() -- or this way without `tools`

  -- User can do other thing
end

But it's hard to imagine for some cases like filter_on_submit, because it is the problem root.

You might want to use this to have different excludes for different root directories.

This one will provide an awesome experience!

@cseickel
Copy link
Contributor

cseickel commented Jan 22, 2022

Recreating the entire command in this case would be a lot of work because it's definitely the most complicated one. I was thinking of adding this as a simplier configuration option, alongside other filter options:

require("neo-tree").setup({
  filesystem = {
    search_limit = 50,
    find_cmd = "fd",
    find_args = "--exclude SomeDir/*" --  I have no idea what the real syntax is yet
    -- or use a function instead of string
    find_args = function(path, search_term)
      if string.len(search_term) > 3 then
        return ""
      end
      if path == "/home/cseickel" then
        return "--exclude Library/*"
      else
        return "--exclude node_modules/*
      end if
    end
  }
})

@nyngwang
Copy link
Author

nyngwang commented Jan 22, 2022

@cseickel: I like this one. I'm using another plugin which has a similar design and it works very well. Here is my config for reference to the structure:

  use {
    -- WARNING: fzf-lua does not include fzf. Run `brew install fzf --HEAD` first!
    'ibhagwan/fzf-lua',
    requires = {
      'kyazdani42/nvim-web-devicons'
    },
    config = function()
      local actions = require "fzf-lua.actions"
      require'fzf-lua'.setup {

      -- many lines skipped
        files = {
          show_cwd_header=true,
          prompt = ' File $ ',
          -- WARNING: Run `brew install fd` to install fd.
          fd_opts =
            "--hidden "..
            "--no-ignore "..
            "--ignore-case "..
            "--type f "..
            -- "--max-depth 15 "..
            " "..
            "--exclude .local "..
            "--exclude .npm "..
            "--exclude .nvm "..
            "--exclude .tmux "..
            "--exclude .cache "..
            "--exclude .vscode "..
            " "..
            "--exclude .DS_Store "..
            "--exclude .git "..
            "--exclude node_modules "..
            "--exclude package-lock.json "..
            "--exclude yarn.lock "..
            "--exclude tags "..
            " ",
          actions = {
            -- WARNING: Required to prevent qf-list on multi-selection.
            ["default"] = actions.file_edit,
          }
        },

@nyngwang
Copy link
Author

nyngwang commented Jan 22, 2022

@cseickel: Is it possible to use the plain-old built-in / to highlight the keyword I want to search inside the file tree? While I think the problem is that I will only use the floating version. Is this possible?

@cseickel
Copy link
Contributor

You are supposed to be able to map "/" to "none" to go back to the built-in vim search. I'm not sure if that will work based on your other bug, but it definitely will after I fix it.

@cseickel
Copy link
Contributor

This is in main right now, find_args is a new option in the filesystem config:

    find_args = {
      "--exclude", ".git",
      "--exclude",  "node_modules"
    },

OR

    -- or use a function instead of list of strings
    find_args = function(cmd, path, search_term, args)
      if cmd ~= "fd" then
        return args
      end
      --maybe you want to force the filter to always include hidden files:
      table.insert(args, "--hidden")
      -- but no one ever wants to see .git files
      table.insert(args, "--exclude")
      table.insert(args, ".git")
      -- or node_modules
      table.insert(args, "--exclude")
      table.insert(args, "node_modules")
      --here is where it pays to use the function, you can exclude more for
      --short search terms, or vary based on the directory
      if string.len(search_term) < 4 and path == "/home/cseickel" then
        table.insert(args, "--exclude")
        table.insert(args, "Library")
      end
      return args
    end,

@nyngwang
Copy link
Author

nyngwang commented Jan 28, 2022

This is in main right now

A good reason for me to switch to main now :)

update: Confirmed it works on:

NVIM v0.7.0-dev+953-gd0493d110
Build type: Release
LuaJIT 2.1.0-beta3

@cseickel
Copy link
Contributor

I put the wrong number in the commit. For reference, this was closed in Release v1.23 in commit 751ee6b.

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

No branches or pull requests

2 participants