Skip to content

Commit

Permalink
fix(utils): blacklisted buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Aug 8, 2024
1 parent 6772d3a commit 53e2339
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ end
---@return nil
local function apply_gutter_hints(gutter_hints, bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
if require("precognition.utils").is_blacklisted_buffer(bufnr) then
if require("precognition.utils").is_blacklisted_buffer(bufnr, config.disabled_fts) then
return
end

Expand Down Expand Up @@ -229,7 +229,7 @@ end
local function display_marks()
local utils = require("precognition.utils")
local bufnr = vim.api.nvim_get_current_buf()
if utils.is_blacklisted_buffer(bufnr) then
if utils.is_blacklisted_buffer(bufnr, config.disabled_fts) then
return
end
local cursorline = vim.fn.line(".")
Expand Down
2 changes: 1 addition & 1 deletion lua/precognition/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function M.char_class(char, big_word)
end

---@param bufnr? integer
---@param disabled_fts? string[]
---@param disabled_fts string[]
---@return boolean
function M.is_blacklisted_buffer(bufnr, disabled_fts)
bufnr = bufnr or vim.api.nvim_get_current_buf()
Expand Down
16 changes: 8 additions & 8 deletions tests/precognition/blacklist_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@ local eq = assert.are.same
describe("blacklist buffers", function()
it("a regular buffer is not blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(true, false)
eq(utils.is_blacklisted_buffer(test_buffer), false)
eq(utils.is_blacklisted_buffer(test_buffer, {}), false)
end)

it("hidden buffer is not blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("buftype", "", { buf = test_buffer })
eq(utils.is_blacklisted_buffer(test_buffer), false)
eq(utils.is_blacklisted_buffer(test_buffer, {}), false)
end)

it("scratch buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(true, true)
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("hidden scratch buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_option_value("buftype", "nofile", { buf = test_buffer })
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("nofile buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("buftype", "nofile", { buf = test_buffer })
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("prompt buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("buftype", "prompt", { buf = test_buffer })
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("help buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, false)
vim.api.nvim_set_option_value("buftype", "help", { buf = test_buffer })
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("terminal buffer is blacklisted", function()
local test_buffer = vim.api.nvim_create_buf(false, false)
vim.api.nvim_open_term(test_buffer, {})
eq(utils.is_blacklisted_buffer(test_buffer), true)
eq(utils.is_blacklisted_buffer(test_buffer, {}), true)
end)

it("blacklisted buffer by filetype", function()
Expand Down

0 comments on commit 53e2339

Please sign in to comment.