Skip to content

Commit

Permalink
fix: nvim_buf_set_option -> nvim_get_option_value
Browse files Browse the repository at this point in the history
  • Loading branch information
sQVe committed Jan 29, 2024
1 parent 9bd7ab3 commit ada90df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lua/bufignore/file-processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local config = require('bufignore.config')
local M = {}

--- Checks if a buffer meets the requirements for unlisting.
--- @param bufnr number
--- @param bufnr integer
--- @param file_path string
--- @return boolean `true` if the buffer meets the unlisting requirements, otherwise `false`.
M._is_valid_for_unlisting = function(bufnr, file_path)
Expand All @@ -17,7 +17,7 @@ M._is_valid_for_unlisting = function(bufnr, file_path)
-- Buffer is loaded
and vim.api.nvim_buf_is_loaded(bufnr)
-- Buffer is listed
and vim.api.nvim_buf_get_option(bufnr, 'buflisted')
and vim.api.nvim_get_option_value('buflisted', { buf = bufnr })
-- User-defined pre_unlist callback is either falsy or returns true.
and (
not user_config.pre_unlist
Expand All @@ -33,9 +33,11 @@ M._unlist_ignored_file = function(file_path)
---@diagnostic disable-next-line: param-type-mismatch
local bufnr = vim.fn.bufnr(file_path)

if M._is_valid_for_unlisting(bufnr, file_path) then
-- Unlist git ignored file buffer.
vim.api.nvim_buf_set_option(bufnr, 'buflisted', false)
if bufnr ~= nil then
if M._is_valid_for_unlisting(bufnr, file_path) then
-- Unlist git ignored file buffer.
vim.api.nvim_set_option_value('buflisted', false, { buf = bufnr })
end
end
end)
end
Expand Down
15 changes: 11 additions & 4 deletions lua/bufignore/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ end
--- @param ignore_cwd_only boolean Whether to only validate files in the current working directory or not.
--- @return boolean is_valid_file_path `true` if the file path is valid, otherwise `false`.
--- @private
M._is_valid_file = function(relative_file_path, absolute_file_path, ignore_cwd_only)
M._is_valid_file = function(
relative_file_path,
absolute_file_path,
ignore_cwd_only
)
local is_non_empty_file_path = relative_file_path ~= nil
and relative_file_path:len() > 0

Expand All @@ -36,7 +40,10 @@ M._is_valid_file = function(relative_file_path, absolute_file_path, ignore_cwd_o

local is_file_path_in_cwd = false
if is_non_empty_file_path then
is_file_path_in_cwd = vim.startswith(absolute_file_path, vim.fn.getcwd())
is_file_path_in_cwd = vim.startswith(
absolute_file_path,
vim.fn.getcwd() or '--- INVALID CWD ---'
)
end

return is_non_empty_file_path and is_file_path_in_cwd
Expand Down Expand Up @@ -98,7 +105,7 @@ end
--- Adds an event to the queue, and starts processing if not already running.
--- @param relative_file_path string
M.enqueue_file = function(relative_file_path)
local user_config = config.get_user_config()
local user_config = config.get_user_config()
local absolute_file_path = vim.fn.fnamemodify(relative_file_path, ':p')

if
Expand All @@ -107,7 +114,7 @@ M.enqueue_file = function(relative_file_path)
relative_file_path,
absolute_file_path,
user_config.ignore_sources.ignore_cwd_only
)
)
then
table.insert(M._queue, absolute_file_path)

Expand Down

0 comments on commit ada90df

Please sign in to comment.