Using extmarks with unloaded buffer

I am writing a library for showing comments, say github code review comments. Users will be able to see which lines have comments and call show_comments() to display comments on that line. What is the best way to keep track of the location of comments after users edit the file?

I am thinking of using extmarks, however, because comments may be in files that haven’t been opened, I am using uri_from_fname to “reserve” buf number and setting extmarks with that number. But the problem is that we can’t set extmarks in unloaded buffers. Is there any way to get over this problem?

I also notice that signs do not suffer from this problem. Is it possible to set sign without showing it in the sign column so that I can use it to track the position of comments?

Can you set a ++once autocommand to lazily set the extmarks when the buffer is loaded? Perhaps checking bufname with bufenter? (careful with bufname as it is not consistently cased/slashed on windows)

That works. Didn’t know that BufEnter will be fired when the buffer is loaded by vim.fn.loadbuf. Thanks.