After this commit, clangd will only keep the last 3 accessed ASTs in
memory. Preambles for each of the opened files are still kept in
memory to make completion and AST rebuilds fast.
AST rebuilds are usually fast enough, but having the last ASTs in
memory still considerably improves latency of operations like
findDefinition and documeneHighlight, which are often sent multiple
times a second when moving around the code. So keeping some of the last
accessed ASTs in memory seems like a reasonable tradeoff.
This may be change aversion, but I'm not sure this class does enough after this change - it doesn't store the inputs or the outputs/cache, so it kind of seems like it wants to be a function.
I guess the motivation here is that storing the outputs means dealing with the cache, and the cache is local to TUScheduler.
But CppFile is only used in TUScheduler, so we could move this there too? It feels like expanding the scope more than I'd like.
The upside is that I think it's a more natural division of responsibility: CppFile could continue to be the "main" holder of the shared_ptr<Preamble> (which we don't limit, but share), and instead of Optional<ParsedAST> it'd have a weak_ptr<ParsedAST> which is controlled and can be refreshed through the cache.
As discussed offline, the cache could look something like: