Skip to content

Commit

Permalink
refactor: build symtab marcher gradually instead of making it from a …
Browse files Browse the repository at this point in the history
…symtab iterator
  • Loading branch information
SpontanCombust committed May 30, 2024
1 parent 48218f0 commit d180653
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
23 changes: 11 additions & 12 deletions crates/analysis/src/symbol_analysis/symbol_table/marcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ pub struct SymbolTableMarcher<'a> {
}

impl<'a> SymbolTableMarcher<'a> {
pub fn new() -> Self {
Self {
inner: Vec::new()
}
}

pub fn add_step(&mut self, symtab: &'a SymbolTable) {
self.inner.push(symtab)
}


pub fn test_contains(&self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
for symtab in &self.inner {
symtab.test_contains_symbol(path)?;
Expand Down Expand Up @@ -86,18 +97,6 @@ impl<'a> SymbolTableMarcher<'a> {
}


pub trait IntoSymbolTableMarcher<'a> {
fn into_marcher(self) -> SymbolTableMarcher<'a> where Self: Sized;
}

impl<'a, It> IntoSymbolTableMarcher<'a> for It
where It: Iterator<Item = &'a SymbolTable> + 'a {
fn into_marcher(self) -> SymbolTableMarcher<'a> where Self: Sized {
SymbolTableMarcher { inner: self.collect() }
}
}


#[derive(Clone)]
pub struct ClassHierarchy<'a> {
marcher: SymbolTableMarcher<'a>,
Expand Down
27 changes: 17 additions & 10 deletions crates/lsp/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::RwLock;
use tower_lsp::Client;
use abs_path::AbsPath;
use witcherscript::{script_document::ScriptDocument, Script};
use witcherscript_analysis::symbol_analysis::symbol_table::{marcher::{IntoSymbolTableMarcher, SymbolTableMarcher}, SymbolTable};
use witcherscript_analysis::symbol_analysis::symbol_table::{marcher::SymbolTableMarcher, SymbolTable};
use witcherscript_project::{ContentGraph, SourceTree, SourceTreeFile, SourceTreePath};
use crate::{config::Config, reporting::Reporter};

Expand Down Expand Up @@ -125,16 +125,23 @@ impl Backend {


pub async fn march_symbol_tables<'a>(&self, symtabs: &'a SymbolTables, content_path: &AbsPath) -> SymbolTableMarcher<'a> {
let content_dependency_paths: Vec<_> =
[content_path.to_owned()].into_iter()
.chain(self.content_graph
.read().await
.walk_dependencies(&content_path)
.map(|n| n.content.path().to_owned()))
let dependency_paths: Vec<_> =
self.content_graph
.read().await
.walk_dependencies(&content_path)
.map(|n| n.content.path().to_owned())
.collect();

let symtab_iter =
[content_path.to_owned()].into_iter()
.chain(dependency_paths.into_iter())
.filter_map(|p| symtabs.get(&p));

content_dependency_paths.into_iter()
.filter_map(|p| symtabs.get(&p))
.into_marcher()
let mut marcher = SymbolTableMarcher::new();
for symtab in symtab_iter {
marcher.add_step(symtab);
}

marcher
}
}

0 comments on commit d180653

Please sign in to comment.