Emacs doesn’t index the file, the LSP server does (in this case that is clangd). The LSP protocol supports asynchronous notifications when results are available, so in principle clangd should be accepting your request and replying with a token that will identify the results when they are available.
lsp-mode would then process the results as normal once it receives a notification with that token.
In the comments, you reported seeing these log messages:
LSP :: Connected to [clangd:57835/starting].
Debugger entered--Lisp error: (error "The connected server(s) does not support method te...")
error("The connected server(s) does not support method %s..." "textDocument/definition")
lsp--send-request-async((:jsonrpc "2.0" :method "textDocument/definition" :params
This indicates that clangd has not advertised that it supports looking up definitions. Since it then starts working a few seconds later, this sounds like a bug in clangd. Or maybe clangd just doesn’t support this at all, and you’re falling back to some other xref backend, in which case the answer to your question has nothing to do with
lsp-mode at all. You should check the value of
Edit: if the problem is simply that your batch process is running before the connection to the LSP server is fully established, then use the
lsp-after-initialize-hook hook to start it instead.