compiler: Store an optional version number with the document

A None value means the file on disk is the golden version.

We have an editor, the LSP and the preview that all need to at least
notice when they have newer data then their peers. So IMHO it makes
sense to have an optional document version around.

The language server protocol makes use of a version number already. This
patch moves that code into the compiler so that it is stored with the
actual data getting versioned.
This commit is contained in:
Tobias Hunger 2023-12-05 21:22:01 +01:00 committed by Tobias Hunger
parent dc536ac599
commit d785f2d5df
20 changed files with 116 additions and 52 deletions

View file

@ -12,7 +12,7 @@ This module has different sub modules with the actual parser functions
*/
use crate::diagnostics::{BuildDiagnostics, SourceFile, Spanned};
use crate::diagnostics::{BuildDiagnostics, SourceFile, SourceFileVersion, Spanned};
pub use smol_str::SmolStr;
use std::{convert::TryFrom, fmt::Display};
@ -987,12 +987,14 @@ pub fn parse_expression_as_bindingexpression(
pub fn parse(
source: String,
path: Option<&std::path::Path>,
version: SourceFileVersion,
build_diagnostics: &mut BuildDiagnostics,
) -> SyntaxNode {
let mut p = DefaultParser::new(&source, build_diagnostics);
p.source_file = std::rc::Rc::new(crate::diagnostics::SourceFileInner::new(
path.map(|p| crate::pathutils::clean_path(p)).unwrap_or_default(),
source,
version,
));
document::parse_document(&mut p);
SyntaxNode {
@ -1009,7 +1011,7 @@ pub fn parse_file<P: AsRef<std::path::Path>>(
let source = crate::diagnostics::load_from_path(&path)
.map_err(|d| build_diagnostics.push_internal_error(d))
.ok()?;
Some(parse(source, Some(path.as_ref()), build_diagnostics))
Some(parse(source, Some(path.as_ref()), None, build_diagnostics))
}
pub fn parse_tokens(