From 68966dbc6015ee3f6eb8f06856ac7a379a8a4dcc Mon Sep 17 00:00:00 2001
From: tim3nd <tim3nd@outlook.com>
Date: Thu, 28 Nov 2024 23:25:02 +0800
Subject: [PATCH 1/3] feat(render): support `source_id` and `source_name` in
 menu render

---
 README.md                                           | 6 ++++++
 lua/blink/cmp/completion/windows/render/context.lua | 6 ++++++
 lua/blink/cmp/config/completion/menu.lua            | 7 +++++++
 lua/blink/cmp/highlights.lua                        | 1 +
 4 files changed, 20 insertions(+)

diff --git a/README.md b/README.md
index 31b5b7ba..19bffce2 100644
--- a/README.md
+++ b/README.md
@@ -422,6 +422,12 @@ MiniDeps.add({
             text = function(ctx) return ctx.label_description end,
             highlight = 'BlinkCmpLabelDescription',
           },
+
+          source_name = {
+            width = { max = 30 },
+            text = function(ctx) return '[' .. ctx.source_name .. ']' end,
+            highlight = 'BlinkCmpSource',
+          },
         },
       },
     },
diff --git a/lua/blink/cmp/completion/windows/render/context.lua b/lua/blink/cmp/completion/windows/render/context.lua
index 225b2e9a..dafebcf2 100644
--- a/lua/blink/cmp/completion/windows/render/context.lua
+++ b/lua/blink/cmp/completion/windows/render/context.lua
@@ -9,6 +9,8 @@
 --- @field kind_icon string
 --- @field icon_gap string
 --- @field deprecated boolean
+--- @field source_id string
+--- @field source_name string
 
 local context = {}
 
@@ -46,6 +48,8 @@ function context.new(draw, item, matched_indices)
 
   local label_detail = (item.labelDetails and item.labelDetails.detail or ''):gsub('\n', newline_char)
   local label_description = (item.labelDetails and item.labelDetails.description or ''):gsub('\n', newline_char)
+  local source_id = item.source_id
+  local source_name = item.source_name
 
   return {
     self = draw,
@@ -58,6 +62,8 @@ function context.new(draw, item, matched_indices)
     kind_icon = kind_icon,
     icon_gap = config.nerd_font_variant == 'mono' and '' or ' ',
     deprecated = item.deprecated or (item.tags and vim.tbl_contains(item.tags, 1)) or false,
+    source_id = source_id,
+    source_name = source_name,
   }
 end
 
diff --git a/lua/blink/cmp/config/completion/menu.lua b/lua/blink/cmp/config/completion/menu.lua
index a809ab6a..29ff1b42 100644
--- a/lua/blink/cmp/config/completion/menu.lua
+++ b/lua/blink/cmp/config/completion/menu.lua
@@ -96,6 +96,13 @@ local window = {
           text = function(ctx) return ctx.label_description end,
           highlight = 'BlinkCmpLabelDescription',
         },
+
+        source_name = {
+          width = { max = 30 },
+          -- source_name or source_id are supported
+          text = function(ctx) return ctx.source_name end,
+          highlight = 'BlinkCmpSource',
+        },
       },
     },
   },
diff --git a/lua/blink/cmp/highlights.lua b/lua/blink/cmp/highlights.lua
index 1956ff70..093aa5d4 100644
--- a/lua/blink/cmp/highlights.lua
+++ b/lua/blink/cmp/highlights.lua
@@ -17,6 +17,7 @@ function highlights.setup()
   set_hl('BlinkCmpLabelDetail', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
   set_hl('BlinkCmpLabelDescription', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
   set_hl('BlinkCmpKind', { link = use_nvim_cmp and 'CmpItemKind' or 'Special' })
+  set_hl('BlinkCmpSource', { link = use_nvim_cmp and 'CmpItemMenu' or 'NonText' })
   for _, kind in ipairs(require('blink.cmp.types').CompletionItemKind) do
     set_hl('BlinkCmpKind' .. kind, { link = use_nvim_cmp and 'CmpItemKind' .. kind or 'BlinkCmpKind' })
   end

From a953e98a4cae4a7e84157ab88dda9cb796f14f5a Mon Sep 17 00:00:00 2001
From: tim3nd <tim3nd@outlook.com>
Date: Fri, 29 Nov 2024 01:06:07 +0800
Subject: [PATCH 2/3] doc: fix inconsistent readme

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 19bffce2..3f18f858 100644
--- a/README.md
+++ b/README.md
@@ -425,7 +425,7 @@ MiniDeps.add({
 
           source_name = {
             width = { max = 30 },
-            text = function(ctx) return '[' .. ctx.source_name .. ']' end,
+            text = function(ctx) return ctx.source_name end,
             highlight = 'BlinkCmpSource',
           },
         },

From a0839b8c576235e16bff22fa9a9eb6c8312dc7cd Mon Sep 17 00:00:00 2001
From: Liam Dyer <liamcdyer@gmail.com>
Date: Thu, 28 Nov 2024 12:09:26 -0500
Subject: [PATCH 3/3] docs: add source_name hl group and draw docs

---
 README.md | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 3f18f858..f1fb3315 100644
--- a/README.md
+++ b/README.md
@@ -661,9 +661,10 @@ MiniDeps.add({
 | `BlinkCmpLabel` | Pmenu | Label of the completion item |
 | `BlinkCmpLabelDeprecated` | Comment | Deprecated label of the completion item |
 | `BlinkCmpLabelMatch` | Pmenu | (Currently unused) Label of the completion item when it matches the query |
-| `BlinkCmpGhostText` | Comment | Preview item with ghost text  |
 | `BlinkCmpKind` | Special | Kind icon/text of the completion item |
 | `BlinkCmpKind<kind>` | Special | Kind icon/text of the completion item |
+| `BlinkCmpSourceName` | NonText | Source name of the completion item |
+| `BlinkCmpGhostText` | Comment | Preview item with ghost text  |
 | `BlinkCmpDoc` | NormalFloat | The documentation window |
 | `BlinkCmpDocBorder` | NormalFloat | The documentation window border |
 | `BlinkCmpDocCursorLine` | Visual | The documentation window cursor line |
@@ -802,6 +803,13 @@ completion.menu.draw = {
       text = function(ctx) return ctx.label_description end,
       highlight = 'BlinkCmpLabelDescription',
     },
+
+    source_name = {
+      width = { max = 30 },
+      -- source_name or source_id are supported
+      text = function(ctx) return ctx.source_name end,
+      highlight = 'BlinkCmpSource',
+    },
   },
 }
 ```