From 1267fcfe8845f547b6d88d9a857859fb442fde6a Mon Sep 17 00:00:00 2001 From: amarakon Date: Sun, 2 Oct 2022 23:12:54 -0400 Subject: [PATCH 1/4] Remove the leading slash from the directory label --- lua/cmp_path/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index f9e9214..45b79fb 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -153,7 +153,7 @@ source._candidates = function(_, dirname, include_hidden, option, callback) } if fs_type == 'directory' then item.kind = cmp.lsp.CompletionItemKind.Folder - item.label = name .. '/' + item.label = name item.insertText = name .. '/' if not option.trailing_slash then item.word = name From 78a7bce3bc9aa5c6695d2f2f5e04cea63563c656 Mon Sep 17 00:00:00 2001 From: amarakon Date: Mon, 3 Oct 2022 01:02:17 -0400 Subject: [PATCH 2/4] Add `visual_slash` option with the default `true` --- README.md | 6 ++++++ lua/cmp_path/init.lua | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4904574..a47e451 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. +### visual_slash (type: boolean) + +_Default:_ `false` + +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 45b79fb..e3ec0e1 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 visual_slash boolean ---@field public get_cwd fun(): string ---@type cmp_path.Option local defaults = { trailing_slash = false, + visual_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.visual_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' }, + visual_slash = { option.visual_slash, 'boolean' }, get_cwd = { option.get_cwd, 'function' }, }) return option From d5a571d79cc30a8d457d177eea6078bf2716dc68 Mon Sep 17 00:00:00 2001 From: amarakon Date: Mon, 3 Oct 2022 02:18:49 -0400 Subject: [PATCH 3/4] Change `visual_slash` to `label_trailing_slash` --- README.md | 2 +- lua/cmp_path/init.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a47e451..6ea37cb 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ _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. -### visual_slash (type: boolean) +### label_trailing_slash (type: boolean) _Default:_ `false` diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index e3ec0e1..4e63d27 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -11,13 +11,13 @@ local constants = { ---@class cmp_path.Option ---@field public trailing_slash boolean ----@field public visual_slash boolean +---@field public label_trailing_slash boolean ---@field public get_cwd fun(): string ---@type cmp_path.Option local defaults = { trailing_slash = false, - visual_slash = true, + label_trailing_slash = true, get_cwd = function(params) return vim.fn.expand(('#%d:p:h'):format(params.context.bufnr)) end, @@ -155,7 +155,7 @@ source._candidates = function(_, dirname, include_hidden, option, callback) } if fs_type == 'directory' then item.kind = cmp.lsp.CompletionItemKind.Folder - if option.visual_slash then + if option.label_trailing_slash then item.label = name .. '/' else item.label = name @@ -196,7 +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' }, - visual_slash = { option.visual_slash, 'boolean' }, + label_trailing_slash = { option.label_trailing_slash, 'boolean' }, get_cwd = { option.get_cwd, 'function' }, }) return option From 7b9a575bcd096e1afe829b2a0f2c554c5c276662 Mon Sep 17 00:00:00 2001 From: Amar Al-Zubaidi <92645199+amarakon@users.noreply.github.com> Date: Mon, 3 Oct 2022 03:49:32 -0400 Subject: [PATCH 4/4] README: Change false to true --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ea37cb..1cfd7a6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Specify if completed directory names should include a trailing slash. Enabling t ### label_trailing_slash (type: boolean) -_Default:_ `false` +_Default:_ `true` Specify if directory names in the completion menu should include a trailing slash.