cl-typeck: Add path-resolution relative to an ID

Great for interactive debugging
This commit is contained in:
2024-07-21 05:57:15 -05:00
parent 9d7ab77999
commit 6bf34fdff6
2 changed files with 55 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
use crate::{definition::Def, project::Project};
use crate::{definition::Def, path::Path, project::Project};
use cl_structures::index_map::*;
// define the index types
@@ -46,6 +46,15 @@ impl<'p, 'c> Handle<'p, 'c> {
self.prj.pool.get(self.id)
}
pub fn navigate(self, path: Path) -> (Option<Self>, Option<Self>) {
match self.prj.get(path, self.id) {
Some((Some(ty), Some(vl), _)) => (Some(self.with(ty)), Some(self.with(vl))),
Some((_, Some(vl), _)) => (None, Some(self.with(vl))),
Some((Some(ty), _, _)) => (Some(self.with(ty)), None),
_ => (None, None),
}
}
/// Gets the [Project] this handle points to.
pub fn project(self) -> &'p Project<'c> {
self.prj