version history MVP
implement basic version history support; there's now an icon in the footer that lets you see the previous versions and their sources I'm a bit worried about spoilers but honestly it's yet another way to hint yourself at the cool secrets so I don't mind
This commit is contained in:
parent
46dee56331
commit
c58c07d846
28 changed files with 1066 additions and 330 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, ops::Range};
|
||||
use std::{collections::HashMap, ops::Range, path::PathBuf};
|
||||
|
||||
use anyhow::Context;
|
||||
use codespan_reporting::{
|
||||
|
@ -6,13 +6,27 @@ use codespan_reporting::{
|
|||
files::SimpleFiles,
|
||||
term::termcolor::{ColorChoice, StandardStream},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use ulid::Ulid;
|
||||
|
||||
use crate::tree::{SemaBranchId, SemaRoots, SemaTree};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct RevisionInfo {
|
||||
pub is_latest: bool,
|
||||
pub number: usize,
|
||||
pub commit: String,
|
||||
pub commit_short: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Source {
|
||||
Tree { input: String, tree_path: String },
|
||||
Tree {
|
||||
input: String,
|
||||
tree_path: String,
|
||||
target_path: PathBuf,
|
||||
revision_info: RevisionInfo,
|
||||
},
|
||||
Other(String),
|
||||
}
|
||||
|
||||
|
@ -37,7 +51,6 @@ pub type FileId = <Files as codespan_reporting::files::Files<'static>>::FileId;
|
|||
/// Treehouse compilation context.
|
||||
pub struct Treehouse {
|
||||
pub files: Files,
|
||||
pub diagnostics: Vec<Diagnostic<FileId>>,
|
||||
|
||||
pub tree: SemaTree,
|
||||
pub branches_by_named_id: HashMap<String, SemaBranchId>,
|
||||
|
@ -52,7 +65,6 @@ impl Treehouse {
|
|||
pub fn new() -> Self {
|
||||
Self {
|
||||
files: Files::new(),
|
||||
diagnostics: vec![],
|
||||
|
||||
tree: SemaTree::default(),
|
||||
branches_by_named_id: HashMap::new(),
|
||||
|
@ -91,15 +103,11 @@ impl Treehouse {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn report_diagnostics(&self) -> anyhow::Result<()> {
|
||||
let writer = StandardStream::stderr(ColorChoice::Auto);
|
||||
let config = codespan_reporting::term::Config::default();
|
||||
for diagnostic in &self.diagnostics {
|
||||
codespan_reporting::term::emit(&mut writer.lock(), &config, &self.files, diagnostic)
|
||||
.context("could not emit diagnostic")?;
|
||||
pub fn revision_info(&self, file_id: FileId) -> Option<&RevisionInfo> {
|
||||
match self.source(file_id) {
|
||||
Source::Tree { revision_info, .. } => Some(revision_info),
|
||||
Source::Other(_) => None,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn next_missingno(&mut self) -> Ulid {
|
||||
|
@ -107,12 +115,6 @@ impl Treehouse {
|
|||
.generate()
|
||||
.expect("just how much disk space do you have?")
|
||||
}
|
||||
|
||||
pub fn has_errors(&self) -> bool {
|
||||
self.diagnostics
|
||||
.iter()
|
||||
.any(|diagnostic| diagnostic.severity == Severity::Error)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TomlError {
|
||||
|
@ -140,3 +142,18 @@ pub fn toml_error_to_diagnostic(error: TomlError) -> Diagnostic<FileId> {
|
|||
notes: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_diagnostics(files: &Files, diagnostics: &[Diagnostic<FileId>]) -> anyhow::Result<()> {
|
||||
let writer = StandardStream::stderr(ColorChoice::Auto);
|
||||
let config = codespan_reporting::term::Config::default();
|
||||
for diagnostic in diagnostics {
|
||||
codespan_reporting::term::emit(&mut writer.lock(), &config, files, diagnostic)
|
||||
.context("could not emit diagnostic")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_errors(diagnostics: &[Diagnostic<FileId>]) -> bool {
|
||||
diagnostics.iter().any(|d| d.severity == Severity::Error)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue