@@ -44,7 +44,7 @@ local buf_matchers = {
4444-- @usage local heirline_component = { provider = "Example Provider", condition = function() return require("astroui.status").condition.buffer_matches { buftype = { "terminal" } } end }
4545function M .buffer_matches (patterns , bufnr , op )
4646 if not op then op = " or" end
47- if not bufnr then bufnr = 0 end
47+ if not bufnr then bufnr = vim . api . nvim_get_current_buf () end
4848 if vim .api .nvim_buf_is_valid (bufnr ) then
4949 for kind , pattern_list in pairs (patterns ) do
5050 if buf_matchers [kind ](pattern_list , bufnr ) then
@@ -83,7 +83,8 @@ function M.is_statusline_showcmd() return vim.fn.has "nvim-0.9" == 1 and vim.opt
8383-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.is_git_repo }
8484function M .is_git_repo (bufnr )
8585 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
86- return vim .b [bufnr or 0 ].gitsigns_head or vim .b [bufnr or 0 ].gitsigns_status_dict
86+ if not bufnr then bufnr = 0 end
87+ return vim .b [bufnr ].gitsigns_head or vim .b [bufnr ].gitsigns_status_dict
8788end
8889
8990--- A condition function if there are any git changes
9293-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.git_changed }
9394function M .git_changed (bufnr )
9495 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
95- local git_status = vim .b [bufnr or 0 ].gitsigns_status_dict
96+ if not bufnr then bufnr = 0 end
97+ local git_status = vim .b [bufnr ].gitsigns_status_dict
9698 return git_status and (git_status .added or 0 ) + (git_status .removed or 0 ) + (git_status .changed or 0 ) > 0
9799end
98100
102104-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.file_modified }
103105function M .file_modified (bufnr )
104106 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
105- return vim .bo [bufnr or 0 ].modified
107+ if not bufnr then bufnr = 0 end
108+ return vim .bo [bufnr ].modified
106109end
107110
108111--- A condition function if the current buffer is read only
111114-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.file_read_only }
112115function M .file_read_only (bufnr )
113116 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
114- local buffer = vim .bo [bufnr or 0 ]
117+ if not bufnr then bufnr = 0 end
118+ local buffer = vim .bo [bufnr ]
115119 return not buffer .modifiable or buffer .readonly
116120end
117121
@@ -121,12 +125,13 @@ end
121125-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.has_diagnostics }
122126function M .has_diagnostics (bufnr )
123127 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
128+ if not bufnr then bufnr = 0 end
124129 if package.loaded [" astrocore" ] and require (" astrocore" ).config .features .diagnostics_mode == 0 then return false end
125130 -- TODO: remove when dropping support for neovim 0.9
126131 if vim .diagnostic .count then
127- return vim .tbl_contains (vim .diagnostic .count (bufnr or 0 ), function (v ) return v > 0 end , { predicate = true })
132+ return vim .tbl_contains (vim .diagnostic .count (bufnr ), function (v ) return v > 0 end , { predicate = true })
128133 else
129- return # vim .diagnostic .get (bufnr or 0 ) > 0
134+ return # vim .diagnostic .get (bufnr ) > 0
130135 end
131136end
132137
136141-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.has_filetype }
137142function M .has_filetype (bufnr )
138143 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
139- local filetype = vim .bo [bufnr or 0 ].filetype
144+ if not bufnr then bufnr = 0 end
145+ local filetype = vim .bo [bufnr ].filetype
140146 return filetype and filetype ~= " "
141147end
142148
146152-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.is_file }
147153function M .is_file (bufnr )
148154 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
149- return vim .bo [bufnr or 0 ].buftype == " "
155+ if not bufnr then bufnr = 0 end
156+ return vim .bo [bufnr ].buftype == " "
150157end
151158
152159--- A condition function if a virtual environment is activated
@@ -166,12 +173,13 @@ function M.aerial_available() return package.loaded["aerial"] end
166173-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.lsp_attached }
167174function M .lsp_attached (bufnr )
168175 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
176+ if not bufnr then bufnr = 0 end
169177 return (
170178 -- HACK: Check for lsp utilities loaded first, get_active_clients seems to have a bug if called too early (tokyonight colorscheme seems to be a good way to expose this for some reason)
171179package.loaded [" astrolsp" ]
172180 -- TODO: remove get_active_clients when dropping support for Neovim 0.9
173181 --- @diagnostic disable-next-line : deprecated
174- and next ((vim .lsp .get_clients or vim .lsp .get_active_clients ) { bufnr = bufnr or 0 }) ~= nil
182+ and next ((vim .lsp .get_clients or vim .lsp .get_active_clients ) { bufnr = bufnr }) ~= nil
175183 )
176184 or (package.loaded [" conform" ] and next (require (" conform" ).list_formatters (bufnr )) ~= nil )
177185 or (package.loaded [" lint" ] and next (require (" lint" )._resolve_linter_by_ft (vim .bo [bufnr ].filetype or " " )) ~= nil )
183191-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.treesitter_available }
184192function M .treesitter_available (bufnr )
185193 if type (bufnr ) == " table" then bufnr = bufnr .bufnr end
186- if not bufnr then bufnr = vim . api . nvim_get_current_buf () end
194+ if not bufnr then bufnr = 0 end
187195 local ft = vim .bo [bufnr ].filetype
188196 local lang = vim .treesitter .language .get_lang (ft )
189197 local parser_avail , _ = pcall (vim .treesitter .get_string_parser , " " , lang )
0 commit comments