Skip to content

Commit

Permalink
--
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Dec 8, 2024
1 parent fff9cd2 commit 3a7d0d5
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

use std::collections::BTreeMap;

use metaslang_cst::text_index::TextIndex;

use crate::cst::{Cursor, Node};
use crate::parser::ParseOutput;

#[derive(Clone)]
pub struct File {
id: String,
parse_output: ParseOutput,
tree: Node,

resolved_imports: BTreeMap<usize, String>,
}

impl File {
pub(super) fn new(id: String, parse_output: ParseOutput) -> Self {
pub(super) fn new(id: String, tree: Node) -> Self {
Self {
id,
parse_output,
tree,

resolved_imports: BTreeMap::new(),
}
Expand All @@ -28,11 +29,11 @@ impl File {
}

pub fn tree(&self) -> &Node {
self.parse_output.tree()
&self.tree
}

pub fn create_tree_cursor(&self) -> Cursor {
self.parse_output.create_tree_cursor()
self.tree.clone().cursor_with_offset(TextIndex::ZERO)
}

pub(super) fn resolve_import(&mut self, import_path: &Cursor, destination_file_id: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl InternalCompilationBuilder {
let import_paths = extract_import_paths(parse_output.create_tree_cursor())
.map_err(AddFileError::Internal)?;

let file = File::new(id.clone(), parse_output);
let file = File::new(id.clone(), parse_output.tree().clone());
self.files.insert(id, file);

Ok(AddFileResponse { import_paths })
Expand Down
37 changes: 24 additions & 13 deletions crates/codegen/runtime/cargo/crate/src/runtime/compilation/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use semver::Version;

use crate::bindings::{create_with_resolver, Bindings, PathResolver};
use crate::compilation::File;
use crate::cst::{Cursor, KindTypes};

pub struct CompilationUnit {
language_version: Version,
Expand Down Expand Up @@ -37,22 +38,32 @@ impl CompilationUnit {
}

fn bindings(&self) -> &Bindings {
todo!()
// struct Resolver;
self.bindings.get_or_init(|| {
let resolver = Resolver {
files: self.files.clone(),
};

// impl PathResolver for Resolver {
// fn resolve_path(&self, context_path: &str, path_to_resolve: &str) -> Option<String> {
// files[context_path].resolved_import(&path_to_resolve)
// }
// }
let mut bindings =
create_with_resolver(self.language_version.clone(), Rc::new(resolver));

// let bindings = create_with_resolver(language_version, resolver);
for (id, file) in &self.files {
bindings.add_user_file(id, file.create_tree_cursor());
}

// for file in files.values() {
// bindings.add_file(file);
// }
bindings
})
}
}

struct Resolver {
files: BTreeMap<String, Rc<File>>,
}

// self.bindings
// .get_or_init(|| create_with_resolver(self.language_version, PathResolver::default()))
impl PathResolver<KindTypes> for Resolver {
fn resolve_path(&self, context_path: &str, path_to_resolve: &Cursor) -> Option<String> {
self.files
.get(context_path)?
.resolved_import(path_to_resolve)
.cloned()
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a7d0d5

Please sign in to comment.