Skip to content

Commit

Permalink
feat: add analysis settings support
Browse files Browse the repository at this point in the history
This commit adds support for including settings for the REPL's analysis
passes in the Clarinet.toml file. For example, to disable the trusted
sender analysis, use:

```toml
[project.analysis_settings.check_checker]
trusted_sender = false
```

See: hirosystems/clarity-repl#62
  • Loading branch information
obycode committed Feb 10, 2022
1 parent 470734c commit c7984e3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ pub fn main() {
&mut analysis_db,
&settings.analysis,
&annotations,
settings.analysis_settings,
) {
Ok(diagnostics) => diagnostics,
Err(diagnostics) => {
Expand Down
98 changes: 52 additions & 46 deletions src/lsp/clarity_language_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,34 @@ impl ClarityLanguageBackend {
.interpreter
.collect_annotations(&ast, &code);
diagnostics.append(&mut annotation_diagnostics);
let (analysis, mut analysis_diagnostics) = match incremental_session
.interpreter
.run_analysis(contract_id.clone(), &mut ast, &annotations)
{
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
diagnostics.push(diagnostic);
collected_diagnostics.insert(
contract_url.clone(),
diagnostics
.into_iter()
.map(|d| utils::convert_clarity_diagnotic_to_lsp_diagnostic(d))
.collect::<Vec<Diagnostic>>(),
);
continue;
}
Err((_, _, Some(error))) => {
logs.push(format!("Unable to get anaylis: {:?}", error).into());
continue;
}
_ => {
logs.push("Unable to get diagnostic".into());
continue;
}
};
let (analysis, mut analysis_diagnostics) =
match incremental_session.interpreter.run_analysis(
contract_id.clone(),
&mut ast,
&annotations,
settings.analysis_settings,
) {
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
diagnostics.push(diagnostic);
collected_diagnostics.insert(
contract_url.clone(),
diagnostics
.into_iter()
.map(|d| utils::convert_clarity_diagnotic_to_lsp_diagnostic(d))
.collect::<Vec<Diagnostic>>(),
);
continue;
}
Err((_, _, Some(error))) => {
logs.push(format!("Unable to get anaylis: {:?}", error).into());
continue;
}
_ => {
logs.push("Unable to get diagnostic".into());
continue;
}
};
diagnostics.append(&mut analysis_diagnostics);
collected_diagnostics.insert(
contract_url.clone(),
Expand Down Expand Up @@ -221,27 +224,30 @@ impl ClarityLanguageBackend {
.interpreter
.collect_annotations(&ast, &code);
diagnostics.append(&mut annotation_diagnostics);
let (analysis, mut analysis_diagnostics) = match incremental_session
.interpreter
.run_analysis(contract_id.clone(), &mut ast, &annotations)
{
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
diagnostics.push(diagnostic);
collected_diagnostics.insert(
contract_url.clone(),
diagnostics
.into_iter()
.map(|d| utils::convert_clarity_diagnotic_to_lsp_diagnostic(d))
.collect::<Vec<Diagnostic>>(),
);
return Ok((collected_diagnostics, logs));
}
_ => {
logs.push("Unable to get diagnostic".into());
return Ok((collected_diagnostics, logs));
}
};
let (analysis, mut analysis_diagnostics) =
match incremental_session.interpreter.run_analysis(
contract_id.clone(),
&mut ast,
&annotations,
settings.analysis_settings,
) {
Ok(analysis) => analysis,
Err((_, Some(diagnostic), _)) => {
diagnostics.push(diagnostic);
collected_diagnostics.insert(
contract_url.clone(),
diagnostics
.into_iter()
.map(|d| utils::convert_clarity_diagnotic_to_lsp_diagnostic(d))
.collect::<Vec<Diagnostic>>(),
);
return Ok((collected_diagnostics, logs));
}
_ => {
logs.push("Unable to get diagnostic".into());
return Ok((collected_diagnostics, logs));
}
};
diagnostics.append(&mut analysis_diagnostics);
collected_diagnostics.insert(
contract_url.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/poke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ pub fn load_session_settings(
];
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.parser_version = project_config.project.parser_version;
settings.analysis_settings = project_config.project.analysis_settings;

Ok((settings, chain_config, project_config))
}
Expand Down
16 changes: 13 additions & 3 deletions src/types/project_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clarity_repl::analysis::{AnalysisSettings, AnalysisSettingsFile};
use std::collections::{BTreeMap, HashSet};
use std::fs::File;
use std::io::{BufReader, Read};
Expand All @@ -20,8 +21,9 @@ pub struct ProjectConfigFile {
telemetry: Option<bool>,
requirements: Option<Value>,
analysis: Option<Vec<String>>,
analysis_settings: Option<AnalysisSettingsFile>,
costs_version: Option<u32>,
parser_version: Option<u32>
parser_version: Option<u32>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
Expand All @@ -39,8 +41,9 @@ pub struct ProjectConfig {
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 parser_version: u32,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
Expand Down Expand Up @@ -160,8 +163,15 @@ impl ProjectManifest {
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),
analysis: project_manifest_file.project.analysis,
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)
} else {
AnalysisSettings::default()
},
};

let mut config = ProjectManifest {
Expand Down

0 comments on commit c7984e3

Please sign in to comment.