Skip to content

add symlink follow support to file_scanner #93

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 2 commits 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Options can be set when opening the picker. For example:
require('telescope').extensions.smart_open.smart_open {
cwd_only = true,
filename_first = false,
follow_symlinks = false,
}
```

Expand All @@ -176,6 +177,10 @@ require('telescope').extensions.smart_open.smart_open {

Format filename as "filename path/to/parent/directory" if `true` and "path/to/parent/directory/filename" if `false`.

- `follow_symlinks` (default: `false`)

Follow symlinks (beware of loops or deep trees). If the tree doesn't loop and isn't too deep this can be useful in certain repositories.


## Configuration

Expand Down Expand Up @@ -203,6 +208,8 @@ See [default configuration](https://github.com/nvim-telescope/telescope.nvim#tel

- `result_limit` (default: `40`)

- `follow_symlinks` (default: `false`)

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.

### Example Configuration:
Expand Down
1 change: 1 addition & 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,5 @@ return {
previous = "•",
others = "∘",
},
follow_symlinks = false,
}
10 changes: 7 additions & 3 deletions lua/telescope/_extensions/smart_open/file_scanner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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(basedir, ignore_patterns, follow_symlinks, on_insert, on_complete)
local stderr = ""
local args = {
"--files",
Expand All @@ -60,6 +60,10 @@ local function ripgrep_scan(basedir, ignore_patterns, on_insert, on_complete)
basedir .. "/.ff-ignore",
}

if follow_symlinks then
table.insert(args, "--follow")
end

for _, value in ipairs(ignore_patterns) do
table.insert(args, "-g")
table.insert(args, "!" .. value)
Expand Down Expand Up @@ -99,8 +103,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(cwd, ignore_patterns, on_insert, on_complete, follow_symlinks)
ripgrep_scan(cwd, ignore_patterns, follow_symlinks, 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 @@ -52,7 +52,7 @@ return function(history, opts, context)
end
end, function()
match_runner.entries_complete()
end)
end, opts.follow_symlinks)

return setmetatable({
close = function() end,
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/_extensions/smart_open/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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),
follow_symlinks = vim.F.if_nil(opts.follow_symlinks, config.follow_symlinks),
}, context)
opts.get_status_text = finder.get_status_text

Expand Down