Skip to content

Options no_ignore, no_ignore_parent, hidden and follow #80

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ See [default configuration](https://github.com/nvim-telescope/telescope.nvim#tel

- `open_buffer_indicators` (default: `{previous = "•", others = "∘"}`)

- `follow` (default: `false`)

If true, follows symlinks (i.e. uses `-L` flag for the `rg` command)

- `hidden` (default: `false`)

Determines whether to show hidden files or not

- `no_ignore` (default: `false`)

Show files ignored by .gitignore, .ignore, etc.

- `no_ignore_parent` (default: `false`)

Show files ignored by .gitignore, .ignore, etc. in parent dirs.

### Example Configuration:

```
Expand All @@ -205,12 +221,6 @@ telescope.setup {

```

### Known Limitations

For files not already in your history, smart-open uses ripgrep for scanning the current directory. (The command is roughly: `rg --files --glob-case-insensitive --hidden --ignore-file=<cwd>/.ff-ignore -g <ignore_patterns...>`).

As a result, files added to git, _but also ignored by git_, will not be included. While not common, this is something that git allows. If this becomes a problem you can work around it by either changing your git ignore patterns, editing the file in neovim in some other way, (thereby adding it to the history), or by using ripgrep's `.ignore` file for overriding git.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik, this is still a limitation. Ripgrep will not list a file that is added to git if it also matches a .gitignore pattern. (I believe git ls-files does the right thing here, and would list such files.)


### Highlight Groups

```vim
Expand Down
4 changes: 4 additions & 0 deletions lua/smart-open/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ return {
set_config("match_algorithm", ext_config.match_algorithm)
set_config("cwd_only", ext_config.cwd_only)
set_config("buffer_indicators", ext_config.buffer_indicators)
set_config("hidden", ext_config.hidden)
set_config("no_ignore", ext_config.no_ignore)
set_config("no_ignore_parent", ext_config.no_ignore_parent)
set_config("follow", ext_config.follow)

config.db_filename = vim.fn.stdpath("data") .. "/smart_open.sqlite3"

Expand Down
4 changes: 4 additions & 0 deletions lua/telescope/_extensions/smart_open/default_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ return {
previous = "•",
others = "∘",
},
no_ignore = false,
no_ignore_parent = false,
follow = false,
hidden = false,
}
33 changes: 25 additions & 8 deletions lua/telescope/_extensions/smart_open/file_scanner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,44 @@ local function spawn(cmd, opts, input, onexit)
return stop
end

local function ripgrep_scan(basedir, ignore_patterns, on_insert, on_complete)
local function ripgrep_scan(opts, on_insert, on_complete)
local stderr = ""
local args = {
"--files",
"--glob-case-insensitive",
"--line-buffered",
"--hidden",
"--color",
"never",
"--ignore-file",
basedir .. "/.ff-ignore",
opts.cwd .. "/.ff-ignore",
}

for _, value in ipairs(ignore_patterns) do
for _, value in ipairs(opts.ignore_patterns) do
table.insert(args, "-g")
table.insert(args, "!" .. value)
end

if opts.hidden then
args[#args + 1] = "--hidden"
end

if opts.no_ignore then
args[#args + 1] = "--no-ignore"
end

if opts.no_ignore_parent then
args[#args + 1] = "--no-ignore-parent"
end

if opts.follow then
args[#args + 1] = "-L"
end

local done = false
local stop

local start_time
stop = spawn("rg", { args = args, cwd = basedir }, {
stop = spawn("rg", { args = args, cwd = opts.cwd }, {
stdout = function(_, chunk)
if not start_time then
start_time = vim.loop.uptime()
Expand All @@ -80,7 +97,7 @@ local function ripgrep_scan(basedir, ignore_patterns, on_insert, on_complete)
end

for line in splitlines(chunk) do
if #line > 0 and on_insert(basedir .. "/" .. line) == false then
if #line > 0 and on_insert(opts.cwd .. "/" .. line) == false then
done = true
stop()
return vim.schedule(function()
Expand All @@ -99,8 +116,8 @@ local function ripgrep_scan(basedir, ignore_patterns, on_insert, on_complete)
end)
end

return function(cwd, ignore_patterns, on_insert, on_complete)
ripgrep_scan(cwd, ignore_patterns, on_insert, function(exit_code, err)
return function(opts, on_insert, on_complete)
ripgrep_scan(opts, on_insert, function(exit_code, err)
if exit_code ~= 0 then
print("ripgrep exited with code", exit_code, "and error:", err)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/_extensions/smart_open/finder/finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ return function(history, opts, context)

local h = { frecency = 0, recent_rank = 0 }

file_scanner(opts.cwd, opts.ignore_patterns, function(fullpath)
file_scanner(opts, function(fullpath)
if not is_added[fullpath] then
local entry_data = create_entry_data(fullpath, h, context)
match_runner.add_entry(entry_data)
Expand Down
4 changes: 4 additions & 0 deletions lua/telescope/_extensions/smart_open/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function M.start(opts)
ignore_patterns = vim.F.if_nil(opts.ignore_patterns, config.ignore_patterns),
show_scores = vim.F.if_nil(opts.show_scores, config.show_scores),
match_algorithm = opts.match_algorithm or config.match_algorithm,
no_ignore = vim.F.if_nil(opts.no_ignore, config.no_ignore),
no_ignore_parent = vim.F.if_nil(opts.no_ignore_parent, config.no_ignore_parent),
follow = vim.F.if_nil(opts.follow, config.follow),
hidden = vim.F.if_nil(opts.hidden, config.hidden),
}, context)
opts.get_status_text = finder.get_status_text

Expand Down