diff --git a/README.md b/README.md index 4904574..1cfd7a6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index f9e9214..4e63d27 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -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