Merge pull request #53 from amarakon/main

Remove the leading slash from the directory label
This commit is contained in:
hrsh7th 2022-10-03 17:04:43 +09:00 committed by GitHub
commit 91ff86cd9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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