Skip to content

Commit

Permalink
Define new event target for JSON, and revert option passing
Browse files Browse the repository at this point in the history
  For the program to be consistent, the 'EventListener' target that we
  pass to a Project should be responsible for the output format.
  Otherwise, we are contingent on developers to remember passing the
  option at call-site. Plus, it overloads the project code with an extra
  boolean option.

  Instead, since the behaviour is solely driven by the execution
  context, we can instantiate a different event target upfront, and
  simply hold on to it throughout the program.

  As a nice side-effect, we can gently re-organize the code to keep the
  terminal printing logic and the json printing logic separate.
  • Loading branch information
KtorZ committed Nov 13, 2024
1 parent 1a75568 commit d24a71e
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 594 deletions.
1 change: 0 additions & 1 deletion crates/aiken-lsp/src/server/lsp_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl LspProject {
PropertyTest::DEFAULT_MAX_SUCCESS,
Tracing::verbose(),
None,
false,
);

self.project.restore(checkpoint);
Expand Down
29 changes: 7 additions & 22 deletions crates/aiken-project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,11 @@ where
uplc: bool,
tracing: Tracing,
env: Option<String>,
json: bool,
) -> Result<(), Vec<Error>> {
let options = Options {
code_gen_mode: CodeGenMode::Build(uplc),
tracing,
env,
json,
};

self.compile(options)
Expand All @@ -227,7 +225,7 @@ where

let mut modules = self.parse_sources(self.config.name.clone())?;

self.type_check(&mut modules, Tracing::silent(), None, false, false)?;
self.type_check(&mut modules, Tracing::silent(), None, false)?;

let destination = destination.unwrap_or_else(|| self.root.join("docs"));

Expand Down Expand Up @@ -269,7 +267,6 @@ where
property_max_success: usize,
tracing: Tracing,
env: Option<String>,
json: bool,
) -> Result<(), Vec<Error>> {
let options = Options {
tracing,
Expand All @@ -285,7 +282,6 @@ where
property_max_success,
}
},
json,
};

self.compile(options)
Expand Down Expand Up @@ -347,7 +343,6 @@ where
root: self.root.clone(),
name: self.config.name.to_string(),
version: self.config.version.clone(),
json: options.json,
});

let env = options.env.as_deref();
Expand All @@ -358,7 +353,7 @@ where

let mut modules = self.parse_sources(self.config.name.clone())?;

self.type_check(&mut modules, options.tracing, env, true, options.json)?;
self.type_check(&mut modules, options.tracing, env, true)?;

match options.code_gen_mode {
CodeGenMode::Build(uplc_dump) => {
Expand Down Expand Up @@ -405,8 +400,7 @@ where
self.collect_tests(verbose, match_tests, exact_match, options.tracing)?;

if !tests.is_empty() {
self.event_listener
.handle_event(Event::RunningTests { json: options.json });
self.event_listener.handle_event(Event::RunningTests);
}

let tests = self.run_tests(tests, seed, property_max_success);
Expand All @@ -433,11 +427,8 @@ where
})
.collect();

self.event_listener.handle_event(Event::FinishedTests {
seed,
tests,
json: options.json,
});
self.event_listener
.handle_event(Event::FinishedTests { seed, tests });

if !errors.is_empty() {
Err(errors)
Expand Down Expand Up @@ -646,11 +637,7 @@ where
Ok(blueprint)
}

fn with_dependencies(
&mut self,
parsed_packages: &mut ParsedModules,
json: bool,
) -> Result<(), Vec<Error>> {
fn with_dependencies(&mut self, parsed_packages: &mut ParsedModules) -> Result<(), Vec<Error>> {
let manifest = deps::download(&self.event_listener, &self.root, &self.config)?;

for package in manifest.packages {
Expand All @@ -661,7 +648,6 @@ where
root: lib.clone(),
name: package.name.to_string(),
version: package.version.clone(),
json,
});

self.read_package_source_files(&lib.join("lib"))?;
Expand Down Expand Up @@ -850,11 +836,10 @@ where
tracing: Tracing,
env: Option<&str>,
validate_module_name: bool,
json: bool,
) -> Result<(), Vec<Error>> {
let our_modules: BTreeSet<String> = modules.keys().cloned().collect();

self.with_dependencies(modules, json)?;
self.with_dependencies(modules)?;

for name in modules.sequence(&our_modules)? {
if let Some(module) = modules.remove(&name) {
Expand Down
2 changes: 0 additions & 2 deletions crates/aiken-project/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub struct Options {
pub code_gen_mode: CodeGenMode,
pub tracing: Tracing,
pub env: Option<String>,
pub json: bool,
}

impl Default for Options {
Expand All @@ -13,7 +12,6 @@ impl Default for Options {
code_gen_mode: CodeGenMode::NoOp,
tracing: Tracing::silent(),
env: None,
json: false,
}
}
}
Expand Down
Loading

0 comments on commit d24a71e

Please sign in to comment.