Skip to content
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
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ See [default configuration](https://github.com/nvim-telescope/telescope.nvim#tel
- `result_limit` (default: `40`)

Limit the number of results returned. Note that this is kept intentionally low by default for performance. The main goal of this plugin is to be able to jump to the file you want with very few keystrokes. Smart open should put relevant results at your fingertips without having to waste time typing too much or scanning through a long list of results. If you need to scan regardless, go ahead and increase this limit. However, if better search results would make that unnecessary and there's a chance that smart open could provide them, please [file a bug](https://github.com/danielfalk/smart-open.nvim/issues/new) to help make it better.
- `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 @@ -219,12 +234,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 @@ -23,6 +23,10 @@ return {
set_config("buffer_indicators", ext_config.buffer_indicators)
set_config("mappings", ext_config.mappings)
set_config("result_limit", ext_config.result_limit)
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 @@ -45,7 +45,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 @@ -38,6 +38,10 @@ function M.start(opts)
show_scores = vim.F.if_nil(opts.show_scores, config.show_scores),
match_algorithm = opts.match_algorithm or config.match_algorithm,
result_limit = vim.F.if_nil(opts.result_limit, config.result_limit),
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