11use std:: { ops:: Deref , sync:: Arc } ;
22
33use emmylua_parser:: { LuaAstNode , LuaCallExpr , LuaExpr , LuaSyntaxKind } ;
4+ use rowan:: TextRange ;
45
56use crate :: {
67 db_index:: {
@@ -318,11 +319,7 @@ fn unwrapp_return_type(
318319 call_expr : LuaCallExpr ,
319320) -> InferResult {
320321 match & return_type {
321- LuaType :: Table
322- | LuaType :: TableConst ( _)
323- | LuaType :: Any
324- | LuaType :: Unknown
325- | LuaType :: Instance ( _) => {
322+ LuaType :: Table | LuaType :: Any | LuaType :: Unknown => {
326323 let id = InFiled {
327324 file_id : cache. get_file_id ( ) ,
328325 value : call_expr. get_range ( ) ,
@@ -332,6 +329,35 @@ fn unwrapp_return_type(
332329 LuaInstanceType :: new ( return_type, id) . into ( ) ,
333330 ) ) ;
334331 }
332+ LuaType :: TableConst ( inst) => {
333+ if is_need_wrap_instance ( cache, & call_expr, inst) {
334+ let id = InFiled {
335+ file_id : cache. get_file_id ( ) ,
336+ value : call_expr. get_range ( ) ,
337+ } ;
338+
339+ return Ok ( LuaType :: Instance (
340+ LuaInstanceType :: new ( return_type. clone ( ) , id) . into ( ) ,
341+ ) ) ;
342+ }
343+
344+ return Ok ( return_type) ;
345+ }
346+ LuaType :: Instance ( inst) => {
347+ if is_need_wrap_instance ( cache, & call_expr, inst. get_range ( ) ) {
348+ let id = InFiled {
349+ file_id : cache. get_file_id ( ) ,
350+ value : call_expr. get_range ( ) ,
351+ } ;
352+
353+ return Ok ( LuaType :: Instance (
354+ LuaInstanceType :: new ( return_type. clone ( ) , id) . into ( ) ,
355+ ) ) ;
356+ }
357+
358+ return Ok ( return_type) ;
359+ }
360+
335361 LuaType :: MuliReturn ( multi) => {
336362 if is_last_expr ( & call_expr) {
337363 return Ok ( return_type) ;
@@ -369,6 +395,18 @@ fn unwrapp_return_type(
369395 Ok ( return_type)
370396}
371397
398+ fn is_need_wrap_instance (
399+ cache : & mut LuaInferCache ,
400+ call_expr : & LuaCallExpr ,
401+ inst : & InFiled < TextRange > ,
402+ ) -> bool {
403+ if cache. get_file_id ( ) != inst. file_id {
404+ return false ;
405+ }
406+
407+ return !call_expr. get_range ( ) . contains ( inst. value . start ( ) ) ;
408+ }
409+
372410fn is_last_expr ( call_expr : & LuaCallExpr ) -> bool {
373411 let parent = call_expr. syntax ( ) . parent ( ) ;
374412 if let Some ( parent) = parent {
0 commit comments