1- use emmylua_parser:: { BinaryOperator , LuaAstNode , LuaAstToken , LuaComment , LuaDocTag } ;
1+ use emmylua_parser:: { LuaAstNode , LuaComment , LuaDocTag } ;
22
3- use crate :: {
4- compilation:: analyzer:: flow:: {
5- binder:: FlowBinder ,
6- flow_node:: { FlowAssertion , FlowId , FlowNodeKind } ,
7- } ,
8- InFiled , LuaType , LuaVarRefId ,
3+ use crate :: compilation:: analyzer:: flow:: {
4+ binder:: FlowBinder ,
5+ flow_node:: { FlowId , FlowNodeKind } ,
96} ;
107
118enum CastAction {
@@ -14,84 +11,18 @@ enum CastAction {
1411 Force ,
1512}
1613
17- pub fn bind_comment (
18- binder : & mut FlowBinder ,
19- lua_comment : LuaComment ,
20- mut current : FlowId ,
21- ) -> FlowId {
14+ pub fn bind_comment ( binder : & mut FlowBinder , lua_comment : LuaComment , current : FlowId ) -> FlowId {
2215 let cast_tags = lua_comment. get_doc_tags ( ) . filter_map ( |it| match it {
2316 LuaDocTag :: Cast ( cast) => Some ( cast) ,
2417 _ => None ,
2518 } ) ;
2619
27- for cast_tag in cast_tags {
28- let Some ( name_token) = cast_tag. get_name_token ( ) else {
29- continue ;
30- } ;
31- let name = name_token. get_name_text ( ) ;
32- let decl = binder
33- . db
34- . get_decl_index ( )
35- . get_decl_tree ( & binder. file_id )
36- . and_then ( |decl_tree| decl_tree. find_local_decl ( & name, name_token. get_position ( ) ) ) ;
37- let var_ref_id = match decl {
38- Some ( decl) => LuaVarRefId :: DeclId ( decl. get_id ( ) ) ,
39- None => LuaVarRefId :: Name ( name. into ( ) ) ,
40- } ;
41-
42- let mut assertions = vec ! [ ] ;
43- for cast_op_type in cast_tag. get_op_types ( ) {
44- let action = match cast_op_type. get_op ( ) {
45- Some ( op) => {
46- if op. get_op ( ) == BinaryOperator :: OpAdd {
47- CastAction :: Add
48- } else {
49- CastAction :: Remove
50- }
51- }
52- None => CastAction :: Force ,
53- } ;
54-
55- if cast_op_type. is_nullable ( ) {
56- match action {
57- CastAction :: Add => {
58- assertions. push ( FlowAssertion :: TypeAdd ( var_ref_id. clone ( ) , LuaType :: Nil ) ) ;
59- }
60- CastAction :: Remove => {
61- assertions
62- . push ( FlowAssertion :: TypeRemove ( var_ref_id. clone ( ) , LuaType :: Nil ) ) ;
63- }
64- _ => { }
65- }
66- } else if let Some ( doc_typ) = cast_op_type. get_type ( ) {
67- let file_id = binder. file_id ;
68- let key = InFiled :: new ( file_id, doc_typ. get_syntax_id ( ) ) ;
69- let typ = match binder. context . cast_flow . get ( & key) {
70- Some ( t) => t. clone ( ) ,
71- None => continue ,
72- } ;
73-
74- match action {
75- CastAction :: Add => {
76- assertions. push ( FlowAssertion :: TypeAdd ( var_ref_id. clone ( ) , typ. clone ( ) ) ) ;
77- }
78- CastAction :: Remove => {
79- assertions. push ( FlowAssertion :: TypeRemove ( var_ref_id. clone ( ) , typ. clone ( ) ) ) ;
80- }
81- CastAction :: Force => {
82- assertions. push ( FlowAssertion :: TypeForce ( var_ref_id. clone ( ) , typ. clone ( ) ) ) ;
83- }
84- }
85- }
86- }
87-
88- for assertion in assertions {
89- let flow_assertion = assertion. clone ( ) ;
90- let flow_id = binder. create_node ( FlowNodeKind :: Assertion ( flow_assertion. into ( ) ) ) ;
91- binder. add_antecedent ( flow_id, current) ;
92- current = flow_id;
93- }
20+ let mut parent = current;
21+ for cast in cast_tags {
22+ let flow_id = binder. create_node ( FlowNodeKind :: TagCast ( cast. to_ptr ( ) ) ) ;
23+ binder. add_antecedent ( flow_id, parent) ;
24+ parent = flow_id;
9425 }
9526
96- current
27+ parent
9728}
0 commit comments