1+ use crate :: custom_language:: CustomLanguageAction ;
12use crate :: lang:: { CustomLang , LanguageGlobs , SerializableInjection , SgLang } ;
23use crate :: utils:: { ErrorContext as EC , RuleOverwrite , RuleTrace } ;
34
@@ -6,23 +7,13 @@ use ast_grep_config::{
67 DeserializeEnv , GlobalRules , RuleCollection , RuleConfig , from_str, from_yaml_string,
78} ;
89use ast_grep_language:: config_file_type;
9- use clap:: ValueEnum ;
1010use ignore:: WalkBuilder ;
1111use serde:: { Deserialize , Serialize } ;
1212
1313use std:: collections:: { HashMap , HashSet } ;
1414use std:: fs:: read_to_string;
1515use std:: path:: { Path , PathBuf } ;
1616
17- #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , ValueEnum ) ]
18- pub enum CustomLanguagePolicy {
19- /// Load native custom language libraries for this invocation.
20- Allow ,
21- /// Skip native custom language libraries without reporting an error.
22- #[ default]
23- Ignore ,
24- }
25-
2617#[ derive( Serialize , Deserialize , Clone ) ]
2718#[ serde( rename_all = "camelCase" ) ]
2819pub struct TestConfig {
@@ -107,12 +98,12 @@ impl ProjectConfig {
10798 /// The outer Result is for definitely wrong config.
10899 pub fn setup (
109100 config_path : Option < PathBuf > ,
110- custom_languages : CustomLanguagePolicy ,
101+ custom_languages : CustomLanguageAction ,
111102 ) -> Result < Result < Self > > {
112103 let Some ( ( project_dir, mut sg_config) ) = Self :: discover_project ( config_path) ? else {
113104 return Ok ( Err ( anyhow:: anyhow!( EC :: ProjectNotExist ) ) ) ;
114105 } ;
115- let outline_rules = if custom_languages == CustomLanguagePolicy :: Allow {
106+ let outline_rules = if custom_languages == CustomLanguageAction :: Load {
116107 custom_language_outline_rules ( & project_dir, sg_config. custom_languages . as_ref ( ) )
117108 } else {
118109 vec ! [ ]
@@ -145,19 +136,19 @@ fn custom_language_outline_rules(
145136fn register_custom_language (
146137 project_dir : & Path ,
147138 sg_config : AstGrepConfig ,
148- policy : CustomLanguagePolicy ,
139+ action : CustomLanguageAction ,
149140) -> Result < ( ) > {
150141 if let Some ( custom_langs) = sg_config. custom_languages {
151- match policy {
152- CustomLanguagePolicy :: Allow => {
142+ match action {
143+ CustomLanguageAction :: Load => {
153144 SgLang :: register_custom_language ( project_dir, custom_langs) ?;
154145 }
155- CustomLanguagePolicy :: Ignore if !custom_langs. is_empty ( ) => {
146+ CustomLanguageAction :: Ignore if !custom_langs. is_empty ( ) => {
156147 eprintln ! (
157148 "Warning: custom languages are ignored because native libraries can execute malicious code. Review the project before using `--custom-languages allow`."
158149 ) ;
159150 }
160- CustomLanguagePolicy :: Ignore => { }
151+ CustomLanguageAction :: Ignore => { }
161152 }
162153 }
163154 if let Some ( globs) = sg_config. language_globs {
@@ -307,7 +298,9 @@ const CONFIG_FILE_YML: &str = "sgconfig.yml";
307298const CONFIG_FILE_YAML : & str = "sgconfig.yaml" ;
308299
309300/// return None if config file does not exist
310- fn find_config_path_with_default ( config_path : Option < PathBuf > ) -> Result < Option < PathBuf > > {
301+ pub ( crate ) fn find_config_path_with_default (
302+ config_path : Option < PathBuf > ,
303+ ) -> Result < Option < PathBuf > > {
311304 if config_path. is_some ( ) {
312305 return Ok ( config_path) ;
313306 }
0 commit comments