@@ -4,6 +4,7 @@ use figment::{
44 value:: { Dict , Map , Value } ,
55 Figment , Profile , Provider ,
66} ;
7+ use foundry_compilers:: ProjectCompileOutput ;
78use itertools:: Itertools ;
89
910mod natspec;
@@ -53,6 +54,20 @@ impl InlineConfig {
5354 Self :: default ( )
5455 }
5556
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+
5671 /// Inserts a new [`NatSpec`] into the [`InlineConfig`].
5772 pub fn insert ( & mut self , natspec : & NatSpec ) -> Result < ( ) , InlineConfigError > {
5873 let map = if let Some ( function) = & natspec. function {
@@ -92,13 +107,16 @@ impl InlineConfig {
92107 Figment :: from ( base) . merge ( self . provide ( contract, function) )
93108 }
94109
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 ( ) )
102120 }
103121
104122 fn get_contract ( & self , contract : & str ) -> Option < & DataMap > {
0 commit comments