From 295bfd15964c65139109710110ecf6367396cfcd Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Mon, 15 Sep 2025 12:51:12 -0400 Subject: [PATCH] derive language for snippets with treesitter --- lua/blink/cmp/sources/snippets/default/init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/blink/cmp/sources/snippets/default/init.lua b/lua/blink/cmp/sources/snippets/default/init.lua index 6716f780..b936dc23 100644 --- a/lua/blink/cmp/sources/snippets/default/init.lua +++ b/lua/blink/cmp/sources/snippets/default/init.lua @@ -18,7 +18,17 @@ function snippets.new(opts) --- @type table self.cache = {} self.registry = require('blink.cmp.sources.snippets.default.registry').new(opts) - self.get_filetype = opts.get_filetype or function() return vim.bo.filetype end + self.get_filetype = opts.get_filetype + or function() + -- determine embedded language with treesitter + local success, parser = pcall(vim.treesitter.get_parser) + if success and parser then + local curline = vim.fn.line('.') + local lang = parser:language_for_range({ curline, 0, curline, 0 }):lang() + if lang ~= '' then return lang end + end + return vim.bo.filetype -- fall back to filetype + end return self end