Add show_hidden_files_by_default option (#2)

MR requested at https://github.com/hrsh7th/cmp-path/pull/66#issuecomment-1938589117

Reviewed-on: https://codeberg.org/FelipeLema/cmp-async-path/pulls/2
Co-authored-by: davidsierradz <davidsierradz@gmail.com>
Co-committed-by: davidsierradz <davidsierradz@gmail.com>
This commit is contained in:
davidsierradz 2024-02-15 20:59:14 +00:00 committed by FelipeLema
parent 89eb42f1f2
commit 6eeaf0f396
2 changed files with 11 additions and 2 deletions

View File

@ -52,3 +52,9 @@ Specify if directory names in the completion menu should include a trailing slas
_Default:_ returns the current working directory of the current buffer _Default:_ returns the current working directory of the current buffer
Specifies the base directory for relative paths. Specifies the base directory for relative paths.
### show_hidden_files_by_default (type: boolean)
_Default:_ `false`
Specify if hidden files should appear in the completion menu without the need of typing `.` first.

View File

@ -12,6 +12,7 @@ local constants = {max_lines = 20}
---@field public trailing_slash boolean ---@field public trailing_slash boolean
---@field public label_trailing_slash boolean ---@field public label_trailing_slash boolean
---@field public get_cwd fun(table): string ---@field public get_cwd fun(table): string
---@field public show_hidden_files_by_default boolean
---@type cmp_path.Option ---@type cmp_path.Option
local defaults = { local defaults = {
@ -20,6 +21,7 @@ local defaults = {
get_cwd = function(params) get_cwd = function(params)
return vim.fn.expand(('#%d:p:h'):format(params.context.bufnr)) return vim.fn.expand(('#%d:p:h'):format(params.context.bufnr))
end, end,
show_hidden_files_by_default = false,
} }
source.new = function() return setmetatable({}, {__index = source}) end source.new = function() return setmetatable({}, {__index = source}) end
@ -36,8 +38,8 @@ source.complete = function(self, params, callback)
return callback() return callback()
end end
local include_hidden = string.sub(params.context.cursor_before_line, local include_hidden = option.show_hidden_files_by_default or
params.offset, params.offset) == '.' string.sub(params.context.cursor_before_line, params.offset, params.offset) == '.'
self:_candidates(dirname, include_hidden, option, function(err, candidates) self:_candidates(dirname, include_hidden, option, function(err, candidates)
if err then if err then
return callback() return callback()
@ -211,6 +213,7 @@ source._validate_option = function(_, params)
trailing_slash = {option.trailing_slash, 'boolean'}, trailing_slash = {option.trailing_slash, 'boolean'},
label_trailing_slash = {option.label_trailing_slash, 'boolean'}, label_trailing_slash = {option.label_trailing_slash, 'boolean'},
get_cwd = {option.get_cwd, 'function'}, get_cwd = {option.get_cwd, 'function'},
show_hidden_files_by_default = {option.show_hidden_files_by_default, 'boolean'},
}) })
return option return option
end end