nirish

config files for niri window manager
Log | Files | Refs | README | LICENSE

parser.lua (1314B)


      1 local msg = require 'mp.msg'
      2 
      3 local g = require 'modules.globals'
      4 local scanning = require 'modules.navigation.scanning'
      5 local fb = require 'modules.apis.fb'
      6 
      7 ---@class ParserAPI: FbAPI
      8 local parser_api = setmetatable({}, { __index = fb })
      9 
     10 ---Returns the index of the parser.
     11 ---@return number
     12 function parser_api:get_index() return g.parsers[self].index end
     13 
     14 ---Returns the ID of the parser
     15 ---@return string
     16 function parser_api:get_id() return g.parsers[self].id end
     17 
     18 ---A newer API for adding items to the root.
     19 ---Only adds the item if the same item does not already exist in the root.
     20 ---Wrapper around `fb.register_root_item`.
     21 ---@param item Item|string
     22 ---@param priority? number  The priority for the added item. Uses the parsers priority by default.
     23 ---@return boolean
     24 function parser_api:register_root_item(item, priority)
     25     return fb.register_root_item(item, priority or g.parsers[self:get_id()].priority)
     26 end
     27 
     28 ---Runs choose_and_parse starting from the next parser.
     29 ---@async
     30 ---@param directory string
     31 ---@return Item[]?
     32 ---@return Opts?
     33 function parser_api:defer(directory)
     34     msg.trace("deferring to other parsers...")
     35     local list, opts = scanning.choose_and_parse(directory, self:get_index() + 1)
     36     fb.get_parse_state().already_deferred = true
     37     return list, opts
     38 end
     39 
     40 return parser_api