Skip to content

Commit b56a2b1

Browse files
feat(config): add ignored filetypes option (#108)
1 parent 82e03b1 commit b56a2b1

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ MiniDeps.add({
346346
-- adjusts spacing to ensure icons are aligned
347347
nerd_font_variant = 'normal',
348348

349+
-- don't show completions or signature help for these filetypes. Keymaps are also disabled.
350+
blocked_filetypes = {},
351+
349352
kind_icons = {
350353
Text = '󰉿',
351354
Method = '󰊕',

lua/blink/cmp/config.lua

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
--- @field highlight? blink.cmp.HighlightConfig
135135
--- @field nerd_font_variant? 'mono' | 'normal'
136136
--- @field kind_icons? table<string, string>
137+
--- @field blocked_filetypes? string[]
137138

138139
--- @type blink.cmp.Config
139140
local config = {
@@ -310,6 +311,9 @@ local config = {
310311
-- adjusts spacing to ensure icons are aligned
311312
nerd_font_variant = 'normal',
312313

314+
-- don't show completions or signature help for these filetypes. Keymaps are also disabled.
315+
blocked_filetypes = {},
316+
313317
kind_icons = {
314318
Text = '󰉿',
315319
Method = '󰊕',

lua/blink/cmp/keymap.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function keymap.setup(opts)
4444
-- applied on other autocmds, such as LspAttach used by nvim-lspconfig and most configs
4545
vim.api.nvim_create_autocmd('InsertEnter', {
4646
callback = function()
47-
if utils.is_special_buffer() then return end
47+
if utils.is_ignored_buffer() then return end
4848
keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands)
4949
end,
5050
})

lua/blink/cmp/trigger/completion.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function trigger.activate_autocmds()
3838
return
3939

4040
-- ignore if in a special buffer
41-
elseif utils.is_special_buffer() then
41+
elseif utils.is_ignored_buffer() then
4242
trigger.hide()
4343

4444
-- character forces a trigger according to the sources, create a fresh context
@@ -61,7 +61,7 @@ function trigger.activate_autocmds()
6161

6262
vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
6363
callback = function(ev)
64-
if utils.is_special_buffer() then return end
64+
if utils.is_ignored_buffer() then return end
6565

6666
-- we were told to ignore the cursor moved event, so we update the context
6767
-- but don't send an on_show event upstream

lua/blink/cmp/trigger/signature.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function trigger.activate_autocmds()
3939

4040
for _, last_char in ipairs(last_chars) do
4141
-- ignore if in a special buffer
42-
if utils.is_special_buffer() then
42+
if utils.is_ignored_buffer() then
4343
trigger.hide()
4444
break
4545
-- character forces a trigger according to the sources, refresh the existing context if it exists
@@ -60,7 +60,7 @@ function trigger.activate_autocmds()
6060
-- check if we've moved outside of the context by diffing against the query boundary
6161
vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
6262
callback = function(ev)
63-
if utils.is_special_buffer() then return end
63+
if utils.is_ignored_buffer() then return end
6464

6565
-- characters added so let textchanged handle it
6666
if #last_chars ~= 0 then return end

lua/blink/cmp/utils.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ function utils.union_keys(t1, t2)
2828
return vim.tbl_keys(t3)
2929
end
3030

31-
--- Determines whether the current buffer is a "special" buffer
31+
--- Determines whether the current buffer is a "special" buffer or if the filetype is in the list of ignored filetypes
3232
--- @return boolean
33-
function utils.is_special_buffer()
33+
function utils.is_ignored_buffer()
3434
local bufnr = vim.api.nvim_get_current_buf()
3535
local buftype = vim.api.nvim_get_option_value('buftype', { buf = bufnr })
36+
local blocked_filetypes = require('blink.cmp.config').blocked_filetypes or {}
37+
local buf_filetype = vim.api.nvim_get_option_value('filetype', { buf = bufnr })
38+
39+
if vim.tbl_contains(blocked_filetypes, buf_filetype) then return true end
3640
return buftype ~= ''
3741
end
3842

0 commit comments

Comments
 (0)