mirror of
https://codeberg.org/FelipeLema/cmp-async-path
synced 2025-05-10 19:58:38 +00:00
Merge pull request #53 from amarakon/main
Remove the leading slash from the directory label
This commit is contained in:
commit
91ff86cd9c
@ -37,6 +37,12 @@ _Default:_ `false`
|
||||
|
||||
Specify if completed directory names should include a trailing slash. Enabling this option makes this source behave like Vim's built-in path completion.
|
||||
|
||||
### label_trailing_slash (type: boolean)
|
||||
|
||||
_Default:_ `true`
|
||||
|
||||
Specify if directory names in the completion menu should include a trailing slash.
|
||||
|
||||
### get_cwd (type: function)
|
||||
|
||||
_Default:_ returns the current working directory of the current buffer
|
||||
|
@ -11,11 +11,13 @@ local constants = {
|
||||
|
||||
---@class cmp_path.Option
|
||||
---@field public trailing_slash boolean
|
||||
---@field public label_trailing_slash boolean
|
||||
---@field public get_cwd fun(): string
|
||||
|
||||
---@type cmp_path.Option
|
||||
local defaults = {
|
||||
trailing_slash = false,
|
||||
label_trailing_slash = true,
|
||||
get_cwd = function(params)
|
||||
return vim.fn.expand(('#%d:p:h'):format(params.context.bufnr))
|
||||
end,
|
||||
@ -153,7 +155,11 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
|
||||
}
|
||||
if fs_type == 'directory' then
|
||||
item.kind = cmp.lsp.CompletionItemKind.Folder
|
||||
item.label = name .. '/'
|
||||
if option.label_trailing_slash then
|
||||
item.label = name .. '/'
|
||||
else
|
||||
item.label = name
|
||||
end
|
||||
item.insertText = name .. '/'
|
||||
if not option.trailing_slash then
|
||||
item.word = name
|
||||
@ -190,6 +196,7 @@ source._validate_option = function(_, params)
|
||||
local option = vim.tbl_deep_extend('keep', params.option, defaults)
|
||||
vim.validate({
|
||||
trailing_slash = { option.trailing_slash, 'boolean' },
|
||||
label_trailing_slash = { option.label_trailing_slash, 'boolean' },
|
||||
get_cwd = { option.get_cwd, 'function' },
|
||||
})
|
||||
return option
|
||||
|
Loading…
Reference in New Issue
Block a user