@@ -368,11 +368,20 @@ impl ProjectSettings {
368368 } ;
369369 let mut groups = if libraries {
370370 let mut groups = Vec :: new ( ) ;
371- if !module_sources. is_empty ( ) {
371+ if module_sources
372+ . iter ( )
373+ . any ( |source| source[ "group" ] == "modules" )
374+ {
372375 groups. push (
373376 json ! ( { "id" : "modules" , "title" : local( zh, "Modules" , "模块" ) , "layout" : "sidebar" } ) ,
374377 ) ;
375378 }
379+ if module_sources
380+ . iter ( )
381+ . any ( |source| source[ "group" ] == "facets" )
382+ {
383+ groups. push ( json ! ( { "id" : "facets" , "title" : local( zh, "Web Facets" , "Web Facet" ) , "layout" : "sidebar" } ) ) ;
384+ }
376385 if module_sources. is_empty ( )
377386 || sources. iter ( ) . any ( |source| source[ "group" ] == "libraries" )
378387 {
@@ -468,6 +477,8 @@ impl ProjectSettings {
468477 // (folder, source file, source) in folder order, so that an
469478 // enclosing module comes before the modules inside it.
470479 let mut rows: Vec < ( PathBuf , PathBuf , Value ) > = Vec :: new ( ) ;
480+ let mut facet_sources = Vec :: new ( ) ;
481+ let mut unreadable_facets: u64 = 0 ;
471482 for ( project, file, revision, classpath, name) in classpaths {
472483 let rel = project_model:: relative_inside ( root, & file) . ok_or_else ( fail) ?;
473484 let choices = modules:: Choices {
@@ -479,6 +490,32 @@ impl ProjectSettings {
479490 if classpath. editable {
480491 bindings. insert ( id. clone ( ) , file. clone ( ) ) ;
481492 }
493+ // Web Facet is stored in another native XML source. Keep it
494+ // separate from .classpath so each save replaces exactly one file.
495+ // A facet file this page cannot edit safely costs only its own
496+ // source: the module still shows, and the page reports one
497+ // degradation for all such files.
498+ if facet_sources. len ( ) < 256 {
499+ let facet_file = project. join ( crate :: web_facet:: FILE ) ;
500+ if fs:: symlink_metadata ( & facet_file) . is_ok_and ( |info| info. is_file ( ) ) {
501+ let facet = read ( & facet_file) . and_then ( |( bytes, revision) | {
502+ Ok ( crate :: web_facet:: fields ( zh, & bytes) ?. map ( |fields| ( revision, fields) ) )
503+ } ) ;
504+ match facet {
505+ Ok ( Some ( ( revision, fields) ) ) => {
506+ let rel = project_model:: relative_inside ( root, & facet_file)
507+ . ok_or_else ( fail) ?;
508+ let facet_id = format ! ( "facet{:x}" , Sha256 :: digest( rel. as_bytes( ) ) ) ;
509+ if paths. insert ( facet_file. clone ( ) ) {
510+ bindings. insert ( facet_id. clone ( ) , facet_file) ;
511+ facet_sources. push ( json ! ( { "id" : facet_id, "group" : "facets" , "title" : name. clone( ) , "path" : rel, "revision" : revision, "writable" : true , "fields" : fields} ) ) ;
512+ }
513+ }
514+ Ok ( None ) => { }
515+ Err ( _) => unreadable_facets += 1 ,
516+ }
517+ }
518+ }
482519 rows. push ( ( project, file, json ! ( { "id" : id, "group" : "modules" , "title" : name, "path" : rel, "revision" : revision, "writable" : classpath. editable, "fields" : fields} ) ) ) ;
483520 }
484521 let mut unavailable = 0 ;
@@ -554,6 +591,16 @@ impl ProjectSettings {
554591 }
555592 sources. push ( source) ;
556593 }
594+ sources. extend ( facet_sources) ;
595+ if unreadable_facets > 0 {
596+ // An error from `degraded` only means the arguments were invalid,
597+ // so the page itself stands.
598+ let _ = context. diagnostics ( ) . degraded (
599+ context. function_id ( ) ,
600+ "webFacetUnreadable" ,
601+ Some ( unreadable_facets) ,
602+ ) ;
603+ }
557604 Ok ( sources)
558605 }
559606 /// Prepares only the confirmed native source; publication belongs to the host.
@@ -591,6 +638,8 @@ impl ProjectSettings {
591638 let values = params[ "values" ] . as_object ( ) . ok_or_else ( fail) ?;
592639 let replacement = if path. ends_with ( ".classpath" ) {
593640 crate :: module_structure:: edit ( & bytes, parent, values) ?
641+ } else if path. ends_with ( crate :: web_facet:: FILE ) {
642+ crate :: web_facet:: edit ( & bytes, values) ?
594643 } else if path. ends_with ( SETTINGS ) {
595644 let workspace = context. workspace_context ( ) . ok_or_else ( fail) ?;
596645 let options = session. model_options ( workspace. context_id ( ) ) ;
@@ -769,8 +818,11 @@ pub(crate) fn write_classpath(
769818 xmltree:: XMLNode :: Element ( _) => doc
770819 . write_with_config (
771820 & mut out,
821+ // Eclipse writes `<entry .../>`; matching it keeps a
822+ // save from rewriting every self-closing line.
772823 xmltree:: EmitterConfig :: new ( )
773824 . perform_indent ( true )
825+ . pad_self_closing ( false )
774826 . write_document_declaration ( false ) ,
775827 )
776828 . map_err ( |_| fail ( ) ) ?,
0 commit comments