Skip to content

Commit 67150c9

Browse files
Store plugins in the Crate structure
commit-id:988401af
1 parent c161fce commit 67150c9

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/project/crate_data.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use cairo_lang_filesystem::db::{
77
FilesGroupEx,
88
};
99
use cairo_lang_filesystem::ids::{CrateId, CrateLongId, Directory};
10+
use cairo_lang_semantic::plugin::PluginSuite;
1011
use cairo_lang_utils::{Intern, LookupIntern};
1112
use smol_str::SmolStr;
1213

1314
use crate::lang::db::AnalysisDatabase;
1415

1516
/// A complete set of information needed to set up a real crate in the analysis database.
16-
#[derive(Debug, PartialEq, Eq)]
17+
#[derive(Debug)]
1718
pub struct Crate {
1819
/// Crate name.
1920
pub name: SmolStr,
@@ -36,6 +37,10 @@ pub struct Crate {
3637

3738
/// Crate settings.
3839
pub settings: CrateSettings,
40+
41+
/// Plugins required by the crate.
42+
#[allow(dead_code)] // TODO: remove. The field is used later in the stack
43+
pub plugins: PluginSuite,
3944
}
4045

4146
impl Crate {
@@ -61,6 +66,8 @@ impl Crate {
6166
if let Some(file_stems) = &self.custom_main_file_stems {
6267
inject_virtual_wrapper_lib(db, crate_id, file_stems);
6368
}
69+
70+
// TODO (later in the stack): Intern the plugin suite and set as override.
6471
}
6572

6673
/// Construct a [`Crate`] from data already applied to the [`AnalysisDatabase`].
@@ -79,7 +86,11 @@ impl Crate {
7986

8087
let custom_main_file_stems = extract_custom_file_stems(db, crate_id);
8188

82-
Some(Self { name, discriminator, root, custom_main_file_stems, settings })
89+
// TODO (later in the stack): Extract plugins associated with this crate
90+
// from db and store it in this suite.
91+
let plugins = PluginSuite::default();
92+
93+
Some(Self { name, discriminator, root, custom_main_file_stems, settings, plugins })
8394
}
8495

8596
/// States whether this is the `core` crate.

src/project/scarb.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use cairo_lang_filesystem::cfg::CfgSet;
77
use cairo_lang_filesystem::db::{
88
CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig,
99
};
10+
use cairo_lang_semantic::inline_macros::get_default_plugin_suite;
11+
use cairo_lang_semantic::plugin::PluginSuite;
1012
use itertools::Itertools;
1113
use scarb_metadata::{
1214
CompilationUnitComponentDependencyMetadata, CompilationUnitComponentId, Metadata,
@@ -15,6 +17,7 @@ use scarb_metadata::{
1517
use smol_str::ToSmolStr;
1618
use tracing::{debug, error, warn};
1719

20+
use super::builtin_plugins::BuiltinPlugin;
1821
use super::manifest_registry::member_config::MemberConfig;
1922
use crate::lang::db::AnalysisDatabase;
2023
use crate::project::crate_data::Crate;
@@ -180,12 +183,34 @@ pub fn extract_crates(metadata: &Metadata) -> Vec<Crate> {
180183

181184
let custom_main_file_stems = (file_stem != "lib").then_some(vec![file_stem.into()]);
182185

186+
let plugin_dependencies = package
187+
.and_then(|package| metadata.get_package_plugin_dependencies(&package.id))
188+
.unwrap_or_default();
189+
190+
let plugins = plugin_dependencies
191+
.into_iter()
192+
.filter_map(|plugin_metadata| {
193+
let builtin_plugin =
194+
BuiltinPlugin::from_plugin_metadata(metadata, plugin_metadata)?;
195+
196+
Some(builtin_plugin.suite())
197+
})
198+
.chain([get_default_plugin_suite()].into_iter())
199+
.fold(PluginSuite::default(), |mut acc, suite| {
200+
acc.add(suite);
201+
acc
202+
});
203+
204+
// TODO: delete before merging
205+
debug!("Plugins for {}: {:#?}", package.unwrap().id.repr, plugins);
206+
183207
let cr = Crate {
184208
name: crate_name.into(),
185209
discriminator: component.discriminator.as_ref().map(ToSmolStr::to_smolstr),
186210
root: root.into(),
187211
custom_main_file_stems,
188212
settings,
213+
plugins,
189214
};
190215

191216
if compilation_unit.package == component.package {
@@ -237,6 +262,8 @@ pub fn extract_crates(metadata: &Metadata) -> Vec<Crate> {
237262
let name = first_crate.name.clone();
238263
let discriminator = first_crate.discriminator.clone();
239264

265+
let plugins = first_crate.plugins.clone();
266+
240267
let custom_main_file_stems =
241268
crs.into_iter().flat_map(|cr| cr.custom_main_file_stems.unwrap()).collect();
242269

@@ -246,6 +273,7 @@ pub fn extract_crates(metadata: &Metadata) -> Vec<Crate> {
246273
root,
247274
custom_main_file_stems: Some(custom_main_file_stems),
248275
settings,
276+
plugins,
249277
});
250278
}
251279

0 commit comments

Comments
 (0)