Skip to content

Commit

Permalink
feat(performance): max_filesize option (def: 1M) skips large files
Browse files Browse the repository at this point in the history
By default, ripgrep will search all files in the project, which can be
slow if there are large files. Now, files larger than 1 megabyte are
skipped from the search altogether by default. This can be customized
with the `max_filesize` option in the `blink-ripgrep` configuration.

The possible values are determined by ripgrep itself. Examples:

- "1024" (bytes by default)
- "200K"
- "1M"
- "999G" (effectively opts out of ignoring any files)
  • Loading branch information
mikavilpas committed Nov 26, 2024
1 parent aeded6f commit ceeff2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ return {
---@module "blink-ripgrep"
---@type blink-ripgrep.Options
opts = {
-- For many options, see `rg --help` for an exact description of
-- the values that ripgrep expects.

-- the minimum length of the current word to start searching
-- (if the word is shorter than this, the search will not start)
prefix_min_len = 3,

-- The number of lines to show around each match in the preview window
context_size = 5,

-- The maximum file size that ripgrep should include in its search.
-- Useful when your project contains large files that might cause
-- performance issues.
-- Examples: "1024" (bytes by default), "200K", "1M", "1G"
max_filesize = "1M",
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion lua/blink-ripgrep/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
---@field prefix_min_len? number
---@field get_command? fun(context: blink.cmp.Context, prefix: string): string[] # Changing this might break things - if you need some customization, please open and issue 🙂
---@field get_prefix? fun(context: blink.cmp.Context): string
---@field context_size? number "The number of lines to show around each match"
---@field context_size? number # The number of lines to show around each match
---@field max_filesize? number # The maximum file size that ripgrep should include in its search. Examples: "1024" (bytes by default), "200K", "1M", "1G"

---@class blink-ripgrep.RgSource : blink.cmp.Source
---@field prefix_min_len number
Expand Down Expand Up @@ -58,6 +59,7 @@ function RgSource.new(opts)
"--json",
"--context=" .. (opts.context_size or 5),
"--word-regexp",
"--max-filesize=" .. (opts.max_filesize or "1M"),
"--ignore-case",
"--",
prefix .. "[\\w_-]+",
Expand Down

0 comments on commit ceeff2f

Please sign in to comment.