init hard reset, pipeline

This commit is contained in:
2026-03-24 13:40:34 +00:00
parent 463f72a123
commit 2638b0fc88
37 changed files with 649 additions and 122 deletions
@@ -7,6 +7,15 @@ pub enum Severity {
Warning,
}
impl Severity {
pub fn is_error(&self) -> bool {
match self {
Severity::Error => true,
Severity::Warning => false,
}
}
}
impl Serialize for Severity {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -2,12 +2,13 @@ use std::collections::HashMap;
use crate::FileId;
use crate::LineIndex;
#[derive(Default)]
#[derive(Default, Debug)]
pub struct FileDB {
files: Vec<FileData>,
uri_to_id: HashMap<String, FileId>,
}
#[derive(Debug)]
struct FileData {
uri: String,
text: String,
@@ -22,12 +23,12 @@ impl FileDB {
}
}
pub fn upsert(&mut self, uri: &str, text: String) -> FileId {
pub fn upsert(&mut self, uri: &str, text: &str) -> FileId {
if let Some(&id) = self.uri_to_id.get(uri) {
let line_index = LineIndex::new(&text);
self.files[id.0 as usize] = FileData {
uri: uri.to_string(),
text,
uri: uri.to_owned(),
text: text.to_owned(),
line_index,
};
id
@@ -35,8 +36,8 @@ impl FileDB {
let id = FileId(self.files.len() as u32);
let line_index = LineIndex::new(&text);
self.files.push(FileData {
uri: uri.to_string(),
text,
uri: uri.to_owned(),
text: text.to_owned(),
line_index,
});
self.uri_to_id.insert(uri.to_string(), id);
@@ -5,14 +5,15 @@ macro_rules! define_id {
pub struct $name(pub u32);
impl $name {
pub const INVALID: $name = $name(u32::MAX);
pub const NONE: $name = $name(u32::MAX);
#[inline]
pub const fn as_u32(self) -> u32 { self.0 }
// Temporary helper for places that still index Vec/slots by usize
#[inline]
pub const fn as_usize(self) -> usize { self.0 as usize }
pub fn is_none(self) -> bool {
self == $name::NONE
}
}
impl From<u32> for $name {
@@ -1,3 +1,4 @@
#[derive(Debug)]
pub struct LineIndex {
line_starts: Vec<u32>,
total_len: u32,
@@ -13,6 +13,20 @@ impl Span {
Self { file, start, end }
}
#[inline]
pub fn none() -> Self {
Self {
file: FileId::NONE,
start: 0,
end: 0,
}
}
#[inline]
pub fn is_none(&self) -> bool {
self.file.is_none()
}
#[inline]
pub fn len(&self) -> u32 {
self.end.saturating_sub(self.start)