Skip to content

Commit

Permalink
feat: consolidate repl settings in config file
Browse files Browse the repository at this point in the history
This change moves all of the REPL specific settings under
`[project.repl]` in Clarinet.toml and allows the parsing of the file to
use data structures from the REPL, providing a simple mechanism to add
configuration options for any analysis passes.
  • Loading branch information
obycode committed Feb 10, 2022
1 parent c7984e3 commit cfe7af3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
7 changes: 3 additions & 4 deletions src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub fn main() {
Command::Check(cmd) if cmd.file.is_some() => {
let file = cmd.file.unwrap();
let mut settings = repl::SessionSettings::default();
settings.analysis = vec!["all".into()];
settings.repl_settings.analysis.enable_all_passes();

let mut session = repl::Session::new(settings.clone());
let code = match fs::read_to_string(&file) {
Expand All @@ -419,7 +419,7 @@ pub fn main() {
let (ast, mut diagnostics, mut success) = session.interpreter.build_ast(
contract_id.clone(),
code.clone(),
settings.parser_version,
settings.repl_settings.parser_version,
);
let (annotations, mut annotation_diagnostics) =
session.interpreter.collect_annotations(&ast, &code);
Expand All @@ -431,9 +431,8 @@ pub fn main() {
let mut analysis_diagnostics = match analysis::run_analysis(
&mut contract_analysis,
&mut analysis_db,
&settings.analysis,
&annotations,
settings.analysis_settings,
&settings.repl_settings.analysis,
) {
Ok(diagnostics) => diagnostics,
Err(diagnostics) => {
Expand Down
3 changes: 2 additions & 1 deletion src/generate/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ history.txt
name = "{}"
authors = []
telemetry = {}
analysis = ["check_checker"]
[project.repl.analysis]
passes = ["check_checker"]
# [contracts.counter]
# path = "contracts/counter.clar"
Expand Down
7 changes: 3 additions & 4 deletions src/lsp/clarity_language_backend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clarity_repl::clarity::analysis::ContractAnalysis;
use clarity_repl::repl::{Session, SessionSettings};
use clarity_repl::analysis;

use serde_json::Value;
use tower_lsp::jsonrpc::Result;
Expand Down Expand Up @@ -112,7 +113,7 @@ impl ClarityLanguageBackend {
let (mut ast, mut diagnostics, _) = incremental_session.interpreter.build_ast(
contract_id.clone(),
code.clone(),
settings.parser_version,
settings.repl_settings.parser_version,
);

// Run the analysis, and try to move to the next contract if we throw an error:
Expand All @@ -126,7 +127,6 @@ impl ClarityLanguageBackend {
contract_id.clone(),
&mut ast,
&annotations,
settings.analysis_settings,
) {
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
Expand Down Expand Up @@ -194,7 +194,7 @@ impl ClarityLanguageBackend {
) -> std::result::Result<(HashMap<Url, Vec<Diagnostic>>, Logs), (String, Logs)> {
let mut logs = vec![];
let mut settings = SessionSettings::default();
settings.analysis = vec!["all".into()];
settings.repl_settings.analysis.enable_all_passes();

let mut incremental_session = Session::new(settings.clone());
let mut collected_diagnostics = HashMap::new();
Expand Down Expand Up @@ -229,7 +229,6 @@ impl ClarityLanguageBackend {
contract_id.clone(),
&mut ast,
&annotations,
settings.analysis_settings,
) {
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
Expand Down
8 changes: 1 addition & 7 deletions src/poke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,7 @@ pub fn load_session_settings(
"bns".to_string(),
];
settings.initial_deployer = initial_deployer;
settings.costs_version = project_config.project.costs_version;
settings.parser_version = project_config.project.parser_version;

if let Some(ref analysis_passes) = project_config.project.analysis {
settings.analysis = analysis_passes.clone();
}
settings.analysis_settings = project_config.project.analysis_settings;
settings.repl_settings = project_config.project.repl_settings.clone();

Ok((settings, chain_config, project_config))
}
Expand Down
4 changes: 2 additions & 2 deletions src/runnner/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ mod sessions {
});
}
settings.initial_deployer = initial_deployer;
settings.costs_version = project_config.project.costs_version;
settings.repl_settings = project_config.project.repl_settings;
settings.include_boot_contracts = vec![
"pox".to_string(),
format!("costs-v{}", project_config.project.costs_version),
format!("costs-v{}", settings.repl_settings.costs_version),
"bns".to_string(),
];
let mut session = Session::new(settings.clone());
Expand Down
44 changes: 27 additions & 17 deletions src/types/project_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clarity_repl::analysis::{AnalysisSettings, AnalysisSettingsFile};
use clarity_repl::repl;
use std::collections::{BTreeMap, HashSet};
use std::fs::File;
use std::io::{BufReader, Read};
Expand All @@ -20,10 +20,12 @@ pub struct ProjectConfigFile {
description: Option<String>,
telemetry: Option<bool>,
requirements: Option<Value>,
analysis: Option<Vec<String>>,
analysis_settings: Option<AnalysisSettingsFile>,
repl: Option<repl::SettingsFile>,

// The fields below have been moved into repl above, but are kept here for
// backwards compatibility.
analysis: Option<Vec<clarity_repl::analysis::Pass>>,
costs_version: Option<u32>,
parser_version: Option<u32>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
Expand All @@ -40,10 +42,7 @@ pub struct ProjectConfig {
pub description: String,
pub telemetry: bool,
pub requirements: Option<Vec<RequirementConfig>>,
pub analysis: Option<Vec<String>>,
pub analysis_settings: AnalysisSettings,
pub costs_version: u32,
pub parser_version: u32,
pub repl_settings: repl::Settings,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
Expand Down Expand Up @@ -153,7 +152,7 @@ impl ProjectManifest {
pub fn from_project_manifest_file(
project_manifest_file: ProjectManifestFile,
) -> ProjectManifest {
let project = ProjectConfig {
let mut project = ProjectConfig {
name: project_manifest_file.project.name.clone(),
requirements: None,
description: project_manifest_file
Expand All @@ -162,18 +161,29 @@ impl ProjectManifest {
.unwrap_or("".into()),
authors: project_manifest_file.project.authors.unwrap_or(vec![]),
telemetry: project_manifest_file.project.telemetry.unwrap_or(false),
costs_version: project_manifest_file.project.costs_version.unwrap_or(2),
parser_version: project_manifest_file.project.parser_version.unwrap_or(2),
analysis: project_manifest_file.project.analysis,
analysis_settings: if let Some(analysis_settings) =
project_manifest_file.project.analysis_settings
{
AnalysisSettings::from(analysis_settings)
repl_settings: if let Some(repl_settings) = project_manifest_file.project.repl {
repl::Settings::from(repl_settings)
} else {
AnalysisSettings::default()
repl::Settings::default()
},
};

// Check for deprecated settings
if let Some(passes) = project_manifest_file.project.analysis {
println!(
"{}: use of 'project.analysis' in Clarinet.toml is deprecated; use project.repl.analysis.passes",
yellow!("warning")
);
project.repl_settings.analysis.set_passes(passes);
}
if let Some(costs_version) = project_manifest_file.project.costs_version {
println!(
"{}: use of 'project.costs_version' in Clarinet.toml is deprecated; use project.repl.costs_version",
yellow!("warning")
);
project.repl_settings.costs_version = costs_version;
}

let mut config = ProjectManifest {
project,
contracts: BTreeMap::new(),
Expand Down

0 comments on commit cfe7af3

Please sign in to comment.