@@ -3,7 +3,7 @@ use std::rc::Rc;
33use lsp_types:: { Diagnostic , Position , Range } ;
44use roxmltree:: Node ;
55
6- use crate :: { constants:: OYarn , core:: { diagnostics:: { create_diagnostic , DiagnosticCode } , odoo:: SyncOdoo , xml_data:: { OdooData , XmlDataDelete , OdooDataField , XmlDataMenuItem , OdooDataRecord , XmlDataTemplate } } , oyarn, threads:: SessionInfo , Sy } ;
6+ use crate :: { Sy , constants:: OYarn , core:: { diagnostics:: { DiagnosticCode , create_diagnostic } , odoo:: SyncOdoo , xml_data:: { OdooData , OdooDataField , OdooDataRecord , XmlDataAsset , XmlDataDelete , XmlDataMenuItem , XmlDataTemplate } } , oyarn, threads:: SessionInfo } ;
77
88use super :: xml_arch_builder:: XmlArchBuilder ;
99
@@ -36,7 +36,9 @@ impl XmlArchBuilder {
3636 || self . load_template ( session, & child, diagnostics)
3737 || self . load_delete ( session, & child, diagnostics)
3838 || self . load_function ( session, & child, diagnostics)
39- || child. is_text ( ) || child. is_comment ( ) ) {
39+ || self . load_asset ( session, & child, diagnostics)
40+ || child. is_text ( ) || child. is_comment ( )
41+ ) {
4042 if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05005 , & [ child. tag_name ( ) . name ( ) , node. tag_name ( ) . name ( ) ] ) {
4143 diagnostics. push (
4244 Diagnostic {
@@ -603,4 +605,125 @@ impl XmlArchBuilder {
603605 }
604606 true
605607 }
608+
609+ fn load_asset ( & mut self , session : & mut SessionInfo , node : & Node , diagnostics : & mut Vec < Diagnostic > ) -> bool {
610+ if node. tag_name ( ) . name ( ) != "asset" { return false ; }
611+ // Validate required attributes: id, name
612+ let mut found_id = None ;
613+ let mut has_name = false ;
614+ for attr in node. attributes ( ) {
615+ match attr. name ( ) {
616+ "id" => { found_id = Some ( attr. value ( ) . to_string ( ) ) ; } ,
617+ "name" => { has_name = true ; } ,
618+ "active" => { } ,
619+ _ => {
620+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05058 , & [ attr. name ( ) ] ) {
621+ diagnostics. push ( Diagnostic {
622+ range : Range { start : Position :: new ( attr. range ( ) . start as u32 , 0 ) , end : Position :: new ( attr. range ( ) . end as u32 , 0 ) } ,
623+ ..diagnostic. clone ( )
624+ } ) ;
625+ }
626+ }
627+ }
628+ }
629+ if found_id. is_none ( ) {
630+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05059 , & [ ] ) {
631+ diagnostics. push ( Diagnostic {
632+ range : Range { start : Position :: new ( node. range ( ) . start as u32 , 0 ) , end : Position :: new ( node. range ( ) . end as u32 , 0 ) } ,
633+ ..diagnostic. clone ( )
634+ } ) ;
635+ }
636+ }
637+ else if !has_name {
638+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05060 , & [ ] ) {
639+ diagnostics. push ( Diagnostic {
640+ range : Range { start : Position :: new ( node. range ( ) . start as u32 , 0 ) , end : Position :: new ( node. range ( ) . end as u32 , 0 ) } ,
641+ ..diagnostic. clone ( )
642+ } ) ;
643+ }
644+ }
645+ // Validate children: must be bundle, path, or field
646+ let ( mut has_bundle, mut has_path) = ( false , false ) ;
647+ for child in node. children ( ) . filter ( |n| n. is_element ( ) ) {
648+ match child. tag_name ( ) . name ( ) {
649+ "bundle" => {
650+ has_bundle = true ;
651+ for attr in child. attributes ( ) {
652+ if attr. name ( ) != "directive" {
653+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05061 , & [ attr. name ( ) ] ) {
654+ diagnostics. push ( Diagnostic {
655+ range : Range { start : Position :: new ( attr. range ( ) . start as u32 , 0 ) , end : Position :: new ( attr. range ( ) . end as u32 , 0 ) } ,
656+ ..diagnostic. clone ( )
657+ } ) ;
658+ }
659+ }
660+ }
661+ if child. text ( ) . is_none ( ) {
662+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05066 , & [ ] ) {
663+ diagnostics. push ( Diagnostic {
664+ range : Range { start : Position :: new ( child. range ( ) . start as u32 , 0 ) , end : Position :: new ( child. range ( ) . end as u32 , 0 ) } ,
665+ ..diagnostic. clone ( )
666+ } ) ;
667+ }
668+ }
669+ } ,
670+ "path" => {
671+ has_path = true ;
672+ if child. attributes ( ) . count ( ) > 0 {
673+ for attr in child. attributes ( ) {
674+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05062 , & [ attr. name ( ) ] ) {
675+ diagnostics. push ( Diagnostic {
676+ range : Range { start : Position :: new ( attr. range ( ) . start as u32 , 0 ) , end : Position :: new ( attr. range ( ) . end as u32 , 0 ) } ,
677+ ..diagnostic. clone ( )
678+ } ) ;
679+ }
680+ }
681+ }
682+ if child. text ( ) . is_none ( ) {
683+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05067 , & [ ] ) {
684+ diagnostics. push ( Diagnostic {
685+ range : Range { start : Position :: new ( child. range ( ) . start as u32 , 0 ) , end : Position :: new ( child. range ( ) . end as u32 , 0 ) } ,
686+ ..diagnostic. clone ( )
687+ } ) ;
688+ }
689+ }
690+ } ,
691+ "field" => {
692+ self . load_field ( session, & child, diagnostics) ;
693+ } ,
694+ "active" => { } ,
695+ _ => {
696+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05063 , & [ child. tag_name ( ) . name ( ) ] ) {
697+ diagnostics. push ( Diagnostic {
698+ range : Range { start : Position :: new ( child. range ( ) . start as u32 , 0 ) , end : Position :: new ( child. range ( ) . end as u32 , 0 ) } ,
699+ ..diagnostic. clone ( )
700+ } ) ;
701+ }
702+ }
703+ }
704+ }
705+ if !has_bundle {
706+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05064 , & [ ] ) {
707+ diagnostics. push ( Diagnostic {
708+ range : Range { start : Position :: new ( node. range ( ) . start as u32 , 0 ) , end : Position :: new ( node. range ( ) . end as u32 , 0 ) } ,
709+ ..diagnostic. clone ( )
710+ } ) ;
711+ }
712+ }
713+ if !has_path {
714+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05065 , & [ ] ) {
715+ diagnostics. push ( Diagnostic {
716+ range : Range { start : Position :: new ( node. range ( ) . start as u32 , 0 ) , end : Position :: new ( node. range ( ) . end as u32 , 0 ) } ,
717+ ..diagnostic. clone ( )
718+ } ) ;
719+ }
720+ }
721+ let data = OdooData :: ASSET ( XmlDataAsset {
722+ file_symbol : Rc :: downgrade ( & self . xml_symbol ) ,
723+ xml_id : found_id. clone ( ) . map ( |id| oyarn ! ( "{}" , id) ) ,
724+ range : node. range ( ) . clone ( ) ,
725+ } ) ;
726+ self . on_operation_creation ( session, found_id, node, data, diagnostics) ;
727+ true
728+ }
606729}
0 commit comments