@@ -9,6 +9,7 @@ pub struct FileGenericIndex {
99 generic_params : Vec < TagGenericParams > ,
1010 root_node_ids : Vec < GenericEffectId > ,
1111 effect_nodes : Vec < GenericEffectRangeNode > ,
12+ pending_type_params : Vec < GenericParam > ,
1213}
1314
1415impl FileGenericIndex {
@@ -17,6 +18,7 @@ impl FileGenericIndex {
1718 generic_params : Vec :: new ( ) ,
1819 root_node_ids : Vec :: new ( ) ,
1920 effect_nodes : Vec :: new ( ) ,
21+ pending_type_params : Vec :: new ( ) ,
2022 }
2123 }
2224
@@ -76,6 +78,14 @@ impl FileGenericIndex {
7678 }
7779 }
7880
81+ pub fn append_pending_type_param ( & mut self , param : GenericParam ) {
82+ self . pending_type_params . push ( param) ;
83+ }
84+
85+ pub fn clear_pending_type_params ( & mut self ) {
86+ self . pending_type_params . clear ( ) ;
87+ }
88+
7989 fn get_start ( & self , ranges : & [ TextRange ] ) -> Option < usize > {
8090 let params_ids = self . find_generic_params ( ranges. first ( ) ?. start ( ) ) ?;
8191 let mut start = 0 ;
@@ -134,22 +144,33 @@ impl FileGenericIndex {
134144 position : TextSize ,
135145 name : & str ,
136146 ) -> Option < ( GenericTplId , Option < LuaType > ) > {
137- let params_ids = self . find_generic_params ( position) ? ;
138-
139- for params_id in params_ids . iter ( ) . rev ( ) {
140- if let Some ( params ) = self . generic_params . get ( * params_id )
141- && let Some ( ( id , param ) ) = params . params . get ( name )
142- {
143- let tpl_id = if params . is_func {
144- GenericTplId :: Func ( * id as u32 )
145- } else {
146- GenericTplId :: Type ( * id as u32 )
147- } ;
148- return Some ( ( tpl_id , param . type_constraint . clone ( ) ) ) ;
147+ if let Some ( params_ids) = self . find_generic_params ( position) {
148+ for params_id in params_ids . iter ( ) . rev ( ) {
149+ if let Some ( params ) = self . generic_params . get ( * params_id )
150+ && let Some ( ( id , param ) ) = params . params . get ( name )
151+ {
152+ let tpl_id = if params . is_func {
153+ GenericTplId :: Func ( * id as u32 )
154+ } else {
155+ GenericTplId :: Type ( * id as u32 )
156+ } ;
157+ return Some ( ( tpl_id , param . type_constraint . clone ( ) ) ) ;
158+ }
149159 }
150160 }
151161
152- None
162+ // 搜索前置类型参数, 例如 ---@alias Pick<T, K extends keyof T>
163+ self . pending_type_params
164+ . iter ( )
165+ . enumerate ( )
166+ . rev ( )
167+ . find ( |( _, param) | param. name == name)
168+ . map ( |( idx, param) | {
169+ (
170+ GenericTplId :: Type ( idx as u32 ) ,
171+ param. type_constraint . clone ( ) ,
172+ )
173+ } )
153174 }
154175
155176 fn find_generic_params ( & self , position : TextSize ) -> Option < Vec < usize > > {
0 commit comments