summaryrefslogtreecommitdiff
path: root/lua/blink/cmp/completion/trigger/utils.lua
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
committerMike Vink <mike@pionative.com>2025-01-19 13:52:52 +0100
commitb77413ff8f59f380612074f0c9bd49093d8db695 (patch)
tree32c39a811ba96ed4ab0a1c81cce9f8d518ed7e31 /lua/blink/cmp/completion/trigger/utils.lua
Squashed 'mut/neovim/pack/plugins/start/blink.cmp/' content from commit 1cc3b1a
git-subtree-dir: mut/neovim/pack/plugins/start/blink.cmp git-subtree-split: 1cc3b1a908fbcfd15451c4772759549724f38524
Diffstat (limited to 'lua/blink/cmp/completion/trigger/utils.lua')
-rw-r--r--lua/blink/cmp/completion/trigger/utils.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/lua/blink/cmp/completion/trigger/utils.lua b/lua/blink/cmp/completion/trigger/utils.lua
new file mode 100644
index 0000000..b2878c2
--- /dev/null
+++ b/lua/blink/cmp/completion/trigger/utils.lua
@@ -0,0 +1,30 @@
+local context = require('blink.cmp.completion.trigger.context')
+local utils = {}
+
+--- Gets the full Unicode character at cursor position
+--- @return string
+function utils.get_char_at_cursor()
+ local line = context.get_line()
+ if line == '' then return '' end
+ local cursor_col = context.get_cursor()[2]
+
+ -- Find the start of the UTF-8 character
+ local start_col = cursor_col
+ while start_col > 1 do
+ local char = string.byte(line:sub(start_col, start_col))
+ if char < 0x80 or char > 0xBF then break end
+ start_col = start_col - 1
+ end
+
+ -- Find the end of the UTF-8 character
+ local end_col = cursor_col
+ while end_col < #line do
+ local char = string.byte(line:sub(end_col + 1, end_col + 1))
+ if char < 0x80 or char > 0xBF then break end
+ end_col = end_col + 1
+ end
+
+ return line:sub(start_col, end_col)
+end
+
+return utils