@@ -4,6 +4,7 @@ use figment::{
4
4
value:: { Dict , Map , Value } ,
5
5
Figment , Profile , Provider ,
6
6
} ;
7
+ use foundry_compilers:: ProjectCompileOutput ;
7
8
use itertools:: Itertools ;
8
9
9
10
mod natspec;
@@ -53,6 +54,20 @@ impl InlineConfig {
53
54
Self :: default ( )
54
55
}
55
56
57
+ /// Tries to create a new instance by detecting inline configurations from the project compile
58
+ /// output.
59
+ pub fn new_parsed ( output : & ProjectCompileOutput , config : & Config ) -> eyre:: Result < Self > {
60
+ let natspecs: Vec < NatSpec > = NatSpec :: parse ( output, & config. root ) ;
61
+ let profiles = & config. profiles ;
62
+ let mut inline = Self :: new ( ) ;
63
+ for natspec in & natspecs {
64
+ inline. insert ( natspec) ?;
65
+ // Validate after parsing as TOML.
66
+ natspec. validate_profiles ( profiles) ?;
67
+ }
68
+ Ok ( inline)
69
+ }
70
+
56
71
/// Inserts a new [`NatSpec`] into the [`InlineConfig`].
57
72
pub fn insert ( & mut self , natspec : & NatSpec ) -> Result < ( ) , InlineConfigError > {
58
73
let map = if let Some ( function) = & natspec. function {
@@ -92,13 +107,16 @@ impl InlineConfig {
92
107
Figment :: from ( base) . merge ( self . provide ( contract, function) )
93
108
}
94
109
95
- /// Returns `true` if a configuration is present at the given contract and function level.
96
- pub fn contains ( & self , contract : & str , function : & str ) -> bool {
97
- // Order swapped to avoid allocation in `get_function` since order doesn't matter here.
98
- self . get_contract ( contract)
99
- . filter ( |map| !map. is_empty ( ) )
100
- . or_else ( || self . get_function ( contract, function) )
101
- . is_some_and ( |map| !map. is_empty ( ) )
110
+ /// Returns `true` if a configuration is present at the given contract level.
111
+ pub fn contains_contract ( & self , contract : & str ) -> bool {
112
+ self . get_contract ( contract) . is_some_and ( |map| !map. is_empty ( ) )
113
+ }
114
+
115
+ /// Returns `true` if a configuration is present at the function level.
116
+ ///
117
+ /// Does not include contract-level configurations.
118
+ pub fn contains_function ( & self , contract : & str , function : & str ) -> bool {
119
+ self . get_function ( contract, function) . is_some_and ( |map| !map. is_empty ( ) )
102
120
}
103
121
104
122
fn get_contract ( & self , contract : & str ) -> Option < & DataMap > {
0 commit comments