11use regex:: Regex ;
2- use std:: { collections:: HashSet , path:: PathBuf , process:: Command } ;
2+ use std:: { borrow :: Cow , collections:: HashSet , path:: PathBuf , process:: Command } ;
33
44use crate :: config:: configs:: { EmmyrcWorkspacePathConfig , EmmyrcWorkspacePathItem } ;
55
@@ -60,10 +60,9 @@ impl PreProcessContext {
6060 }
6161
6262 fn pre_process_path ( & self , path : & str ) -> String {
63- let mut path = path. to_string ( ) ;
64- path = self . replace_env_var ( & path) ;
63+ let path = self . replace_env_var ( path) ;
6564 // ${workspaceFolder} == {workspaceFolder}
66- path = path. replace ( "$" , "" ) ;
65+ let mut path = path. replace ( "$" , "" ) ; // ideally, this should be `Cow`
6766 let workspace_str = match self . workspace . to_str ( ) {
6867 Some ( path) => path,
6968 None => {
@@ -129,10 +128,10 @@ impl PreProcessContext {
129128 }
130129
131130 // compact luals
132- fn replace_env_var ( & self , path : & str ) -> String {
131+ fn replace_env_var < ' a > ( & self , path : & ' a str ) -> Cow < ' a , str > {
133132 let re = match & self . env_var_regex {
134133 Some ( re) => re,
135- None => return path . to_string ( ) ,
134+ None => return Cow :: Borrowed ( path ) ,
136135 } ;
137136 re. replace_all ( path, |caps : & regex:: Captures | {
138137 let key = & caps[ 1 ] ;
@@ -141,7 +140,6 @@ impl PreProcessContext {
141140 String :: new ( )
142141 } )
143142 } )
144- . to_string ( )
145143 }
146144
147145 fn replace_placeholders ( & self , input : & str , workspace_folder : & str ) -> String {
0 commit comments