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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ Specify if directory names in the completion menu should include a trailing slas
_Default:_ returns the current working directory of the current buffer

Specifies the base directory for relative paths.

### max_traverse_entries (type: number)

_Default:_ `nil`

The maximum count of entries in a directory will this source traverse before returning candidates.

Some directories may have a large number of entries. Users, who prefer to have a time-bounded feedback over completeness, may limit the number of entries this plugin fetches with this option.

If this option is set to nil, there's no effective limit.
7 changes: 6 additions & 1 deletion lua/cmp_path/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local constants = {
---@field public trailing_slash boolean
---@field public label_trailing_slash boolean
---@field public get_cwd fun(): string
---@field public max_traversed_entries number

---@type cmp_path.Option
local defaults = {
Expand All @@ -21,6 +22,7 @@ local defaults = {
get_cwd = function(params)
return vim.fn.expand(('#%d:p:h'):format(params.context.bufnr))
end,
max_traversed_entries = nil,
}

source.new = function()
Expand Down Expand Up @@ -168,7 +170,8 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
table.insert(items, item)
end

while true do
local entry_count = 0
while option.max_traversed_entries == nil or entry_count < option.max_traversed_entries do
local name, fs_type, e = vim.loop.fs_scandir_next(fs)
if e then
return callback(fs_type, nil)
Expand All @@ -177,6 +180,7 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
break
end
create_item(name, fs_type)
entry_count = entry_count + 1
end

callback(nil, items)
Expand All @@ -198,6 +202,7 @@ source._validate_option = function(_, params)
trailing_slash = { option.trailing_slash, 'boolean' },
label_trailing_slash = { option.label_trailing_slash, 'boolean' },
get_cwd = { option.get_cwd, 'function' },
max_traversed_entries = { option.max_traversed_entries, { 'number', 'nil' }},
})
return option
end
Expand Down