Skip to content

Commit

Permalink
Review related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wawel37 committed Oct 14, 2024
1 parent 83ff2aa commit 35c6dee
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
9 changes: 4 additions & 5 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion extensions/scarb-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ serde_json.workspace = true
salsa.workspace = true
smol_str.workspace = true
thiserror.workspace = true
semver.workspace = true

[dev-dependencies]
assert_fs.workspace = true
Expand Down
10 changes: 1 addition & 9 deletions extensions/scarb-doc/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use cairo_lang_syntax::node::db::{SyntaxDatabase, SyntaxGroup};
use cairo_lang_utils::Upcast;

use salsa;
use scarb_metadata::PackageMetadata;
use semver::Version;

/// The Cairo compiler Salsa database tailored for scarb-doc usage.
#[salsa::database(
Expand All @@ -33,12 +31,10 @@ use semver::Version;
)]
pub struct ScarbDocDatabase {
storage: salsa::Storage<Self>,
main_package_name: String,
main_package_version: Version,
}

impl ScarbDocDatabase {
pub fn new(project_config: Option<ProjectConfig>, main_package: &PackageMetadata) -> Self {
pub fn new(project_config: Option<ProjectConfig>) -> Self {
let plugin_suite = [get_default_plugin_suite(), starknet_plugin_suite()]
.into_iter()
.fold(PluginSuite::default(), |mut acc, suite| {
Expand All @@ -47,8 +43,6 @@ impl ScarbDocDatabase {
});
let mut db = Self {
storage: Default::default(),
main_package_name: main_package.name.clone(),
main_package_version: main_package.version.clone(),
};

init_files_group(&mut db);
Expand Down Expand Up @@ -94,8 +88,6 @@ impl salsa::ParallelDatabase for ScarbDocDatabase {
fn snapshot(&self) -> salsa::Snapshot<Self> {
salsa::Snapshot::new(ScarbDocDatabase {
storage: self.storage.snapshot(),
main_package_name: self.main_package_name.clone(),
main_package_version: self.main_package_version.clone(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/scarb-doc/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct PackagesSerializationError(#[from] SerdeError);
pub struct MissingPackageError(pub String);

#[derive(Debug, Error)]
#[error("Cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`.")]
#[error("cairo's `Cfg` must serialize identically as Scarb Metadata's `Cfg`")]
pub struct CfgParseError(#[from] SerdeError);

#[derive(Debug, Error)]
Expand Down
22 changes: 4 additions & 18 deletions extensions/scarb-doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::db::ScarbDocDatabase;
use crate::metadata::compilation::get_project_config;
use anyhow::Result;
use cairo_lang_compiler::diagnostics::DiagnosticsReporter;
use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Maybe, Severity};
use cairo_lang_diagnostics::{FormattedDiagnosticEntry, Severity};
use cairo_lang_filesystem::{
db::{Edition, FilesGroup},
ids::{CrateId, CrateLongId},
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn generate_packages_information(

let project_config = get_project_config(metadata, package_metadata)?;

let db = ScarbDocDatabase::new(Some(project_config), package_metadata);
let db = ScarbDocDatabase::new(Some(project_config));

let main_crate_id = db.intern_crate(CrateLongId::Real {
name: package_metadata.name.clone().into(),
Expand All @@ -73,12 +73,8 @@ pub fn generate_packages_information(
setup_diagnostics_reporter(&db, main_crate_id, package_compilation_unit)
.skip_lowering_diagnostics();

let crate_ = generate_language_elements_tree_for_package(
&db,
main_crate_id,
should_document_private_items,
)
.map_err(|_| DiagnosticError(package_metadata.name.clone()));
let crate_ = Crate::new(&db, main_crate_id, should_document_private_items)
.map_err(|_| DiagnosticError(package_metadata.name.clone()));

if crate_.is_err() {
diagnostics_reporter.ensure(&db)?;
Expand All @@ -95,16 +91,6 @@ pub fn generate_packages_information(
Ok(packages_information)
}

fn generate_language_elements_tree_for_package(
db: &ScarbDocDatabase,
main_crate_id: CrateId,
document_private_items: bool,
) -> Maybe<Crate> {
// let main_crate_id = db.get_main_crate_id();

Crate::new(db, main_crate_id, document_private_items)
}

fn setup_diagnostics_reporter<'a>(
db: &ScarbDocDatabase,
main_crate_id: CrateId,
Expand Down

0 comments on commit 35c6dee

Please sign in to comment.