1- use crate :: embed:: types:: { EmbedCandidate , GuestLanguage , TemplateTagKind } ;
2- use crate :: workspace:: DocumentFileSource ;
1+ use crate :: embed:: types:: { EmbedCandidate , EmbedDetectionContext , GuestLanguage , TemplateTagKind } ;
32
43/// A single embed detector. Entirely const-constructible.
54///
@@ -38,6 +37,12 @@ pub(crate) enum EmbedDetector {
3837 /// Matches `EmbedCandidate::Directive`. Always matches (no pattern).
3938 /// The guest language depends on the host framework.
4039 Directive { target : EmbedTarget } ,
40+
41+ /// Matches `EmbedCandidate::AttributeValue` by attribute name.
42+ AttributeValue { target : EmbedTarget } ,
43+
44+ /// Matches `EmbedCandidate::CallArgument` by callee name.
45+ CallArgument { target : EmbedTarget } ,
4146}
4247
4348impl EmbedDetector {
@@ -47,21 +52,21 @@ impl EmbedDetector {
4752 pub fn try_match (
4853 & self ,
4954 candidate : & EmbedCandidate ,
50- file_source : & DocumentFileSource ,
55+ context : & EmbedDetectionContext ,
5156 ) -> Option < GuestLanguage > {
5257 match ( self , candidate) {
5358 // Element detector VS an Element candidate: match by tag name
5459 ( Self :: Element { tag, target } , EmbedCandidate :: Element { tag_name, .. } ) => {
5560 if tag_name. text ( ) . eq_ignore_ascii_case ( tag) {
56- target. resolve ( candidate, file_source )
61+ target. resolve ( candidate, context )
5762 } else {
5863 None
5964 }
6065 }
6166
6267 // Frontmatter detector + Frontmatter candidate: always matches
6368 ( Self :: Frontmatter { target } , EmbedCandidate :: Frontmatter { .. } ) => {
64- target. resolve ( candidate, file_source )
69+ target. resolve ( candidate, context )
6570 }
6671
6772 // TemplateTag detector + TaggedTemplate candidate with Identifier tag
@@ -73,7 +78,7 @@ impl EmbedDetector {
7378 } ,
7479 ) => {
7580 if name. text ( ) == * tag {
76- target. resolve ( candidate, file_source )
81+ target. resolve ( candidate, context )
7782 } else {
7883 None
7984 }
@@ -87,14 +92,14 @@ impl EmbedDetector {
8792 ) => match tag {
8893 TemplateTagKind :: MemberExpression { object : obj, .. } => {
8994 if obj. text ( ) == * object {
90- target. resolve ( candidate, file_source )
95+ target. resolve ( candidate, context )
9196 } else {
9297 None
9398 }
9499 }
95100 TemplateTagKind :: CallExpression { callee } => {
96101 if callee. text ( ) == * object {
97- target. resolve ( candidate, file_source )
102+ target. resolve ( candidate, context )
98103 } else {
99104 None
100105 }
@@ -104,12 +109,20 @@ impl EmbedDetector {
104109
105110 // TextExpression detector + TextExpression candidate: always matches
106111 ( Self :: TextExpression { target } , EmbedCandidate :: TextExpression { .. } ) => {
107- target. resolve ( candidate, file_source )
112+ target. resolve ( candidate, context )
108113 }
109114
110115 // Directive detector + Directive candidate: always matches
111116 ( Self :: Directive { target } , EmbedCandidate :: Directive { .. } ) => {
112- target. resolve ( candidate, file_source)
117+ target. resolve ( candidate, context)
118+ }
119+
120+ ( Self :: AttributeValue { target } , EmbedCandidate :: AttributeValue { .. } ) => {
121+ target. resolve ( candidate, context)
122+ }
123+
124+ ( Self :: CallArgument { target } , EmbedCandidate :: CallArgument { .. } ) => {
125+ target. resolve ( candidate, context)
113126 }
114127
115128 // Mismatched variant — no match
@@ -126,7 +139,7 @@ pub(crate) enum EmbedTarget {
126139 /// Guest language depends on element attributes / host file source.
127140 Dynamic {
128141 /// Function that is used to determine the guest language.
129- resolver : fn ( & EmbedCandidate , & DocumentFileSource ) -> Option < GuestLanguage > ,
142+ resolver : fn ( & EmbedCandidate , & EmbedDetectionContext ) -> Option < GuestLanguage > ,
130143 /// Possible fallback. Use `None` to tell the matcher to ignore the snippet
131144 fallback : Option < GuestLanguage > ,
132145 } ,
@@ -137,11 +150,11 @@ impl EmbedTarget {
137150 fn resolve (
138151 & self ,
139152 candidate : & EmbedCandidate ,
140- file_source : & DocumentFileSource ,
153+ context : & EmbedDetectionContext ,
141154 ) -> Option < GuestLanguage > {
142155 match self {
143156 Self :: Static ( g) => Some ( * g) ,
144- Self :: Dynamic { resolver, fallback } => resolver ( candidate, file_source ) . or ( * fallback) ,
157+ Self :: Dynamic { resolver, fallback } => resolver ( candidate, context ) . or ( * fallback) ,
145158 }
146159 }
147160}
0 commit comments