Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/workshop_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! canonical Workshop source model. It deliberately contains no HIR,
//! lowering, backend encoding, or catalog state.

use workshop_rs::arena::Arena;
use workshop_rs::source::{FileId as WorkshopFileId, Position, SourceFile, Span as WorkshopSpan};

use crate::span::{FileId, SourceMap, Span};
Expand Down Expand Up @@ -35,21 +34,22 @@ pub enum SourceBridgeError {
#[derive(Clone)]
pub struct WorkshopSourceBridge {
source_map: SourceMap,
files: Arena<SourceFile>,
files: Vec<SourceFile>,
del_to_workshop: Vec<WorkshopFileId>,
}

impl WorkshopSourceBridge {
/// Build Workshop source-file entries and a stable DEL-file-ID mapping.
pub fn from_source_map(sources: &SourceMap) -> Result<Self, SourceBridgeError> {
let mut files = Arena::new();
let mut files = Vec::new();
let mut del_to_workshop = Vec::new();

for source in sources.files() {
let Some(path) = source.name.to_str() else {
return Err(SourceBridgeError::NonUtf8Path(source.id));
};
let workshop_file = files.push(SourceFile::new(path));
let workshop_file = WorkshopFileId::from_index(files.len());
files.push(SourceFile::new(path));
let index = source.id.0 as usize;
if del_to_workshop.len() <= index {
del_to_workshop.resize(index + 1, workshop_file);
Expand All @@ -64,8 +64,8 @@ impl WorkshopSourceBridge {
})
}

/// The workshop-rs source-file arena, in DEL source-map order.
pub fn files(&self) -> &Arena<SourceFile> {
/// Workshop source-file entries in DEL source-map order.
pub fn files(&self) -> &[SourceFile] {
&self.files
}

Expand Down
4 changes: 2 additions & 2 deletions tests/workshop_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn bridge_preserves_cross_file_identity_and_unicode_positions() {
assert_ne!(first_workshop, second_workshop);
assert_eq!(bridge.files().len(), 2);
assert_eq!(
bridge.files().get(first_workshop),
bridge.files().get(first_workshop.index()),
Some(&SourceFile::new("src/main.del"))
);
assert_eq!(
bridge.files().get(second_workshop),
bridge.files().get(second_workshop.index()),
Some(&SourceFile::new("lib/β.del"))
);

Expand Down
Loading