-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b75f43
commit 40926ae
Showing
8 changed files
with
181 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use cairo_lang_compiler::project::{ | ||
update_crate_root, update_crate_roots_from_project_config, ProjectConfig, | ||
}; | ||
use cairo_lang_defs::db::{DefsDatabase, DefsGroup}; | ||
use cairo_lang_doc::db::{DocDatabase, DocGroup}; | ||
use cairo_lang_filesystem::db::{ | ||
init_files_group, AsFilesGroupMut, FilesDatabase, FilesGroup, CORELIB_CRATE_NAME, | ||
}; | ||
use cairo_lang_parser::db::{ParserDatabase, ParserGroup}; | ||
use cairo_lang_semantic::db::{SemanticDatabase, SemanticGroup}; | ||
use cairo_lang_semantic::inline_macros::get_default_plugin_suite; | ||
use cairo_lang_semantic::plugin::PluginSuite; | ||
use cairo_lang_starknet::starknet_plugin_suite; | ||
use cairo_lang_syntax::node::db::{SyntaxDatabase, SyntaxGroup}; | ||
use cairo_lang_utils::Upcast; | ||
|
||
use salsa; | ||
|
||
/// The Cairo compiler Salsa database tailored for scarb-doc usage. | ||
#[salsa::database( | ||
FilesDatabase, | ||
ParserDatabase, | ||
SyntaxDatabase, | ||
DefsDatabase, | ||
SemanticDatabase, | ||
DocDatabase | ||
)] | ||
pub struct ScarbDocDatabase { | ||
storage: salsa::Storage<Self>, | ||
} | ||
|
||
impl ScarbDocDatabase { | ||
pub fn new(project_config: Option<ProjectConfig>) -> Self { | ||
let mut db = Self { | ||
storage: Default::default(), | ||
}; | ||
|
||
init_files_group(&mut db); | ||
|
||
let plugin_suite = [get_default_plugin_suite(), starknet_plugin_suite()] | ||
.into_iter() | ||
.fold(PluginSuite::default(), |mut acc, suite| { | ||
acc.add(suite); | ||
acc | ||
}); | ||
|
||
db.apply_plugin_suite(plugin_suite); | ||
|
||
if let Some(config) = project_config { | ||
db.apply_project_config(config); | ||
} | ||
|
||
db | ||
} | ||
|
||
fn apply_plugin_suite(&mut self, plugin_suite: PluginSuite) { | ||
self.set_macro_plugins(plugin_suite.plugins); | ||
self.set_inline_macro_plugins(plugin_suite.inline_macro_plugins.into()); | ||
self.set_analyzer_plugins(plugin_suite.analyzer_plugins); | ||
} | ||
|
||
fn apply_project_config(&mut self, config: ProjectConfig) { | ||
update_crate_roots_from_project_config(self, &config); | ||
if let Some(corelib) = &config.corelib { | ||
update_crate_root(self, &config, CORELIB_CRATE_NAME.into(), corelib.clone()); | ||
} | ||
} | ||
} | ||
|
||
impl salsa::Database for ScarbDocDatabase {} | ||
|
||
impl salsa::ParallelDatabase for ScarbDocDatabase { | ||
fn snapshot(&self) -> salsa::Snapshot<Self> { | ||
salsa::Snapshot::new(ScarbDocDatabase { | ||
storage: self.storage.snapshot(), | ||
}) | ||
} | ||
} | ||
|
||
impl AsFilesGroupMut for ScarbDocDatabase { | ||
fn as_files_group_mut(&mut self) -> &mut (dyn FilesGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn FilesGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn FilesGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn ParserGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn ParserGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn SyntaxGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn SyntaxGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn DefsGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn DefsGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn SemanticGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn SemanticGroup + 'static) { | ||
self | ||
} | ||
} | ||
|
||
impl Upcast<dyn DocGroup> for ScarbDocDatabase { | ||
fn upcast(&self) -> &(dyn DocGroup + 'static) { | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod compilation; | ||
pub mod db; | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.