Skip to content

Commit 7c3ad2b

Browse files
authored
feat: add get_filetype option for snippet source (#352)
Closes #292
1 parent 91ea929 commit 7c3ad2b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ MiniDeps.add({
384384
global_snippets = { 'all' },
385385
extended_filetypes = {},
386386
ignored_filetypes = {},
387+
get_filetype = function(context)
388+
return vim.bo.filetype
389+
end
387390
}
388391

389392
--- Example usage for disabling the snippet provider after pressing trigger characters (i.e. ".")

lua/blink/cmp/sources/snippets/init.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
--- @field global_snippets string[]
55
--- @field extended_filetypes table<string, string[]>
66
--- @field ignored_filetypes string[]
7+
--- @field get_filetype fun(context: blink.cmp.Context): string
78

89
local snippets = {}
910

@@ -13,11 +14,12 @@ function snippets.new(opts)
1314
self.cache = {}
1415
--- @type blink.cmp.SnippetsOpts
1516
self.registry = require('blink.cmp.sources.snippets.registry').new(opts or {})
17+
self.get_filetype = opts.get_filetype or function() return vim.bo.filetype end
1618
return self
1719
end
1820

19-
function snippets:get_completions(_, callback)
20-
local filetype = vim.bo.filetype
21+
function snippets:get_completions(context, callback)
22+
local filetype = self.get_filetype(context)
2123
if vim.tbl_contains(self.registry.config.ignored_filetypes, filetype) then return callback() end
2224

2325
if not self.cache[filetype] then

0 commit comments

Comments
 (0)