@@ -31,7 +31,7 @@ pub enum ProfileScope {
3131 Local ,
3232}
3333
34- #[ derive( Debug , Clone , Serialize , Deserialize , Default ) ]
34+ #[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq ) ]
3535pub struct ProfileSelection {
3636 /// Project-relative path using forward slashes.
3737 pub path : String ,
@@ -134,11 +134,7 @@ pub fn save_workspace(project_root: &Path, settings: &WorkspaceSettings) -> io::
134134
135135/* =============================== Profiles IO =============================== */
136136
137- pub fn save_profile (
138- project_root : & Path ,
139- profile : & Profile ,
140- scope : ProfileScope ,
141- ) -> io:: Result < ( ) > {
137+ pub fn save_profile ( project_root : & Path , profile : & Profile , scope : ProfileScope ) -> io:: Result < ( ) > {
142138 ensure_profiles_dirs ( project_root) ?;
143139 let path = profile_path ( project_root, scope, & profile. name ) ;
144140 let tmp = path. with_extension ( "tmp" ) ;
@@ -151,40 +147,56 @@ pub fn save_profile(
151147/// Returns (Profile, Scope) preferring Local if both exist.
152148pub fn load_profile ( project_root : & Path , name : & str ) -> Option < ( Profile , ProfileScope ) > {
153149 let local = profile_path ( project_root, ProfileScope :: Local , name) ;
154- if let Ok ( bytes) = fs:: read ( & local) {
155- if let Ok ( p) = serde_json:: from_slice :: < Profile > ( & bytes) {
156- return Some ( ( p , ProfileScope :: Local ) ) ;
157- }
150+ if let Ok ( bytes) = fs:: read ( & local)
151+ && let Ok ( p) = serde_json:: from_slice :: < Profile > ( & bytes)
152+ {
153+ return Some ( ( p , ProfileScope :: Local ) ) ;
158154 }
159155 let shared = profile_path ( project_root, ProfileScope :: Shared , name) ;
160- if let Ok ( bytes) = fs:: read ( & shared) {
161- if let Ok ( p) = serde_json:: from_slice :: < Profile > ( & bytes) {
162- return Some ( ( p , ProfileScope :: Shared ) ) ;
163- }
156+ if let Ok ( bytes) = fs:: read ( & shared)
157+ && let Ok ( p) = serde_json:: from_slice :: < Profile > ( & bytes)
158+ {
159+ return Some ( ( p , ProfileScope :: Shared ) ) ;
164160 }
165161 None
166162}
167163
164+ pub fn delete_profile ( project_root : & Path , scope : ProfileScope , name : & str ) -> io:: Result < ( ) > {
165+ let path = profile_path ( project_root, scope, name) ;
166+ if path. exists ( ) {
167+ // Best effort delete; ignore if it fails
168+ let _ = fs:: remove_file ( & path) ;
169+ }
170+ Ok ( ( ) )
171+ }
172+
168173/// Lists all profiles found. If a name exists in both scopes, only the Local one is returned.
169174pub fn list_profiles ( project_root : & Path ) -> Vec < ProfileMeta > {
170175 fn scan ( dir : & Path , scope : ProfileScope , out : & mut Vec < ( String , ProfileScope ) > ) {
171176 if let Ok ( rd) = fs:: read_dir ( dir) {
172177 for ent in rd. flatten ( ) {
173- if let Some ( ext) = ent. path ( ) . extension ( ) {
174- if ext == "json" {
175- if let Some ( os) = ent. path ( ) . file_stem ( ) {
176- let name = os. to_string_lossy ( ) . to_string ( ) ;
177- out. push ( ( name, scope) ) ;
178- }
179- }
178+ if let Some ( ext) = ent. path ( ) . extension ( )
179+ && ext == "json"
180+ && let Some ( os) = ent. path ( ) . file_stem ( )
181+ {
182+ let name = os. to_string_lossy ( ) . to_string ( ) ;
183+ out. push ( ( name, scope) ) ;
180184 }
181185 }
182186 }
183187 }
184188
185189 let mut raw: Vec < ( String , ProfileScope ) > = Vec :: new ( ) ;
186- scan ( & profiles_shared_dir ( project_root) , ProfileScope :: Shared , & mut raw) ;
187- scan ( & profiles_local_dir ( project_root) , ProfileScope :: Local , & mut raw) ;
190+ scan (
191+ & profiles_shared_dir ( project_root) ,
192+ ProfileScope :: Shared ,
193+ & mut raw,
194+ ) ;
195+ scan (
196+ & profiles_local_dir ( project_root) ,
197+ ProfileScope :: Local ,
198+ & mut raw,
199+ ) ;
188200
189201 // keep a single entry per name, preferring Local
190202 use std:: collections:: BTreeMap ;
0 commit comments