lsp/fscache: set version on token.File
Files can be loaded directly by different parts of the LSP, but also by
modpkgload. It is desirable to keep a file fully self-contained: once it
is loaded, it should ideally keep with it all its metadata. This avoids
going back to the fs to fetch further metadata later on, which could run
the risk of race conditions.
A while ago we added File.[Set]Content() so that we could easily get
from an AST back to the bytes that built it. Various messages from the
LSP server to the client require that version numbers of files are
included which helps to avoid race conditions, especially if the client
is sending async modification messages whilst a sync rpc message is in
progress.
To better support this, we add the version number to the token.File and
so once a file has been loaded (and probably parsed to an AST), we can
get back not just to its raw bytes, but also to its version number.
Also whilst we're here, improve the naming of fields in token.File.
Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: Ic1736cb997d0c71375a5476ceabc85c42586293a
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1225196
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>