Skip to content

Commit

Permalink
feat(config): add ignored filetypes option (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry authored Oct 15, 2024
1 parent 82e03b1 commit b56a2b1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ MiniDeps.add({
-- adjusts spacing to ensure icons are aligned
nerd_font_variant = 'normal',

-- don't show completions or signature help for these filetypes. Keymaps are also disabled.
blocked_filetypes = {},

kind_icons = {
Text = '󰉿',
Method = '󰊕',
Expand Down
4 changes: 4 additions & 0 deletions lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
--- @field highlight? blink.cmp.HighlightConfig
--- @field nerd_font_variant? 'mono' | 'normal'
--- @field kind_icons? table<string, string>
--- @field blocked_filetypes? string[]

--- @type blink.cmp.Config
local config = {
Expand Down Expand Up @@ -310,6 +311,9 @@ local config = {
-- adjusts spacing to ensure icons are aligned
nerd_font_variant = 'normal',

-- don't show completions or signature help for these filetypes. Keymaps are also disabled.
blocked_filetypes = {},

kind_icons = {
Text = '󰉿',
Method = '󰊕',
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function keymap.setup(opts)
-- applied on other autocmds, such as LspAttach used by nvim-lspconfig and most configs
vim.api.nvim_create_autocmd('InsertEnter', {
callback = function()
if utils.is_special_buffer() then return end
if utils.is_ignored_buffer() then return end
keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands)
end,
})
Expand Down
4 changes: 2 additions & 2 deletions lua/blink/cmp/trigger/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function trigger.activate_autocmds()
return

-- ignore if in a special buffer
elseif utils.is_special_buffer() then
elseif utils.is_ignored_buffer() then
trigger.hide()

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

vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
callback = function(ev)
if utils.is_special_buffer() then return end
if utils.is_ignored_buffer() then return end

-- we were told to ignore the cursor moved event, so we update the context
-- but don't send an on_show event upstream
Expand Down
4 changes: 2 additions & 2 deletions lua/blink/cmp/trigger/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function trigger.activate_autocmds()

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

-- characters added so let textchanged handle it
if #last_chars ~= 0 then return end
Expand Down
8 changes: 6 additions & 2 deletions lua/blink/cmp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ function utils.union_keys(t1, t2)
return vim.tbl_keys(t3)
end

--- Determines whether the current buffer is a "special" buffer
--- Determines whether the current buffer is a "special" buffer or if the filetype is in the list of ignored filetypes
--- @return boolean
function utils.is_special_buffer()
function utils.is_ignored_buffer()
local bufnr = vim.api.nvim_get_current_buf()
local buftype = vim.api.nvim_get_option_value('buftype', { buf = bufnr })
local blocked_filetypes = require('blink.cmp.config').blocked_filetypes or {}
local buf_filetype = vim.api.nvim_get_option_value('filetype', { buf = bufnr })

if vim.tbl_contains(blocked_filetypes, buf_filetype) then return true end
return buftype ~= ''
end

Expand Down

0 comments on commit b56a2b1

Please sign in to comment.