emmylua_ls 0.23.1

A language server for emmylua.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
use std::{
    collections::{HashMap, HashSet},
    sync::Arc,
};

use emmylua_code_analysis::{
    DeclReferenceCell, FileId, LuaCompilation, LuaDeclId, LuaMemberId, LuaMemberKey,
    LuaSemanticDeclId, LuaType, LuaTypeDeclId, SemanticDeclLevel, SemanticModel,
};
use emmylua_parser::{
    LuaAssignStat, LuaAst, LuaAstNode, LuaAstToken, LuaCallExpr, LuaNameToken, LuaStringToken,
    LuaSyntaxNode, LuaSyntaxToken, LuaTableField,
};
use lsp_types::Location;

#[derive(Default)]
struct ReferenceSearchContext {
    visited_module_exports: HashSet<FileId>,
    visited_semantic_ids: HashSet<LuaSemanticDeclId>,
}

pub fn search_references(
    semantic_model: &SemanticModel,
    compilation: &LuaCompilation,
    token: LuaSyntaxToken,
) -> Option<Vec<Location>> {
    let mut result = Vec::new();
    if let Some(semantic_decl) =
        semantic_model.find_decl(token.clone().into(), SemanticDeclLevel::default())
    {
        match semantic_decl {
            LuaSemanticDeclId::LuaDecl(decl_id) => {
                let _ = search_decl_references_with_token(
                    semantic_model,
                    compilation,
                    decl_id,
                    token,
                    &mut result,
                );
            }
            LuaSemanticDeclId::Member(member_id) => {
                let _ =
                    search_member_references(semantic_model, compilation, member_id, &mut result);
            }
            LuaSemanticDeclId::TypeDecl(type_decl_id) => {
                let _ = search_type_decl_references(semantic_model, type_decl_id, &mut result);
            }
            _ => {}
        }
    } else if let Some(token) = LuaStringToken::cast(token.clone()) {
        let _ = search_string_references(semantic_model, token, &mut result);
    } else if semantic_model.get_emmyrc().references.fuzzy_search {
        let _ = fuzzy_search_references(compilation, token, &mut result);
    }

    // 简单过滤, 同行的多个引用只保留一个
    // let filtered_result = filter_duplicate_and_covered_locations(result);
    // Some(filtered_result)

    Some(result)
}

pub fn search_decl_references_with_token(
    semantic_model: &SemanticModel,
    compilation: &LuaCompilation,
    decl_id: LuaDeclId,
    token: LuaSyntaxToken,
    result: &mut Vec<Location>,
) -> Option<()> {
    let mut ctx = ReferenceSearchContext::default();
    let mut semantic_cache = HashMap::new();
    let previous_result = result.len();
    let ret = search_semantic_references_with_ctx(
        &mut ctx,
        compilation,
        &mut semantic_cache,
        LuaSemanticDeclId::LuaDecl(decl_id),
        result,
    );
    // 如果不等于当前文件, 那么我们可能是引用了其他文件的导出
    if ret.is_none()
        && previous_result == result.len()
        && decl_id.file_id != semantic_model.get_file_id()
    {
        if let Some(semantic_decl) =
            semantic_model.find_decl(token.clone().into(), SemanticDeclLevel::NoTrace)
        {
            if let LuaSemanticDeclId::LuaDecl(decl_id) = semantic_decl {
                return search_semantic_references_with_ctx(
                    &mut ctx,
                    compilation,
                    &mut semantic_cache,
                    LuaSemanticDeclId::LuaDecl(decl_id),
                    result,
                );
            }
        }
    }
    ret
}

pub fn search_decl_references(
    _semantic_model: &SemanticModel,
    compilation: &LuaCompilation,
    decl_id: LuaDeclId,
    result: &mut Vec<Location>,
) -> Option<()> {
    let mut ctx = ReferenceSearchContext::default();
    let mut semantic_cache = HashMap::new();
    search_semantic_references_with_ctx(
        &mut ctx,
        compilation,
        &mut semantic_cache,
        LuaSemanticDeclId::LuaDecl(decl_id),
        result,
    )
}

fn search_decl_references_with_ctx<'a>(
    ctx: &mut ReferenceSearchContext,
    semantic_model: &SemanticModel<'a>,
    compilation: &'a LuaCompilation,
    semantic_cache: &mut HashMap<FileId, Arc<SemanticModel<'a>>>,
    decl_id: LuaDeclId,
    result: &mut Vec<Location>,
    worklist: &mut Vec<LuaSemanticDeclId>,
) -> Option<()> {
    let decl = semantic_model
        .get_db()
        .get_decl_index()
        .get_decl(&decl_id)?;
    if decl.is_local() {
        let decl_refs = semantic_model
            .get_db()
            .get_reference_index()
            .get_decl_references(&decl_id.file_id, &decl_id)?;
        let document = semantic_model.get_document();
        // 加入自己
        if let Some(location) = document.to_lsp_location(decl.get_range()) {
            result.push(location);
        }
        let typ = semantic_model.get_type(decl.get_id().into());
        let should_follow_value_alias = matches!(
            typ,
            LuaType::Signature(_)
                | LuaType::Table
                | LuaType::TableConst(_)
                | LuaType::Ref(_)
                | LuaType::Def(_)
        );

        for decl_ref in &decl_refs.cells {
            let location = document.to_lsp_location(decl_ref.range)?;
            result.push(location);
            if should_follow_value_alias {
                let _ = enqueue_value_alias_references(ctx, semantic_model, decl_ref, worklist);
            }
        }

        let _ = extend_module_return_value_references(
            ctx,
            semantic_model,
            compilation,
            semantic_cache,
            decl_id,
            result,
            worklist,
        );

        return Some(());
    } else {
        let name = decl.get_name();
        let global_references = semantic_model
            .get_db()
            .get_reference_index()
            .get_global_references(name)?;
        for in_filed_syntax_id in global_references {
            let document = semantic_model.get_document_by_file_id(in_filed_syntax_id.file_id)?;
            let location = document.to_lsp_location(in_filed_syntax_id.value.get_range())?;
            result.push(location);
        }
    }

    Some(())
}

pub fn search_member_references(
    _semantic_model: &SemanticModel,
    compilation: &LuaCompilation,
    member_id: LuaMemberId,
    result: &mut Vec<Location>,
) -> Option<()> {
    let mut ctx = ReferenceSearchContext::default();
    let mut semantic_cache = HashMap::new();
    search_semantic_references_with_ctx(
        &mut ctx,
        compilation,
        &mut semantic_cache,
        LuaSemanticDeclId::Member(member_id),
        result,
    )
}

fn search_member_references_with_ctx<'a>(
    ctx: &mut ReferenceSearchContext,
    semantic_model: &SemanticModel<'a>,
    compilation: &'a LuaCompilation,
    semantic_cache: &mut HashMap<FileId, Arc<SemanticModel<'a>>>,
    member_id: LuaMemberId,
    result: &mut Vec<Location>,
    worklist: &mut Vec<LuaSemanticDeclId>,
) -> Option<()> {
    let member = semantic_model
        .get_db()
        .get_member_index()
        .get_member(&member_id)?;
    let key = member.get_key();
    let index_references = semantic_model
        .get_db()
        .get_reference_index()
        .get_index_references(key)?;

    let semantic_id = LuaSemanticDeclId::Member(member_id);
    for in_filed_syntax_id in index_references {
        let reference_semantic_model =
            get_semantic_model_cached(compilation, semantic_cache, in_filed_syntax_id.file_id)?;
        let root = reference_semantic_model.get_root();
        let node = in_filed_syntax_id.value.to_node_from_root(root.syntax())?;
        if reference_semantic_model.is_reference_to(
            node.clone(),
            semantic_id.clone(),
            SemanticDeclLevel::default(),
        ) {
            let document = reference_semantic_model.get_document();
            let range = in_filed_syntax_id.value.get_range();
            let location = document.to_lsp_location(range)?;
            result.push(location);
            let _ = search_member_secondary_references(
                ctx,
                reference_semantic_model.as_ref(),
                node,
                result,
                worklist,
            );
        }
    }

    Some(())
}

fn search_member_secondary_references(
    ctx: &mut ReferenceSearchContext,
    semantic_model: &SemanticModel,
    node: LuaSyntaxNode,
    result: &mut Vec<Location>,
    worklist: &mut Vec<LuaSemanticDeclId>,
) -> Option<()> {
    let position = node.text_range().start();
    let parent = LuaAst::cast(node.parent()?)?;
    match parent {
        LuaAst::LuaAssignStat(assign_stat) => {
            let (vars, values) = assign_stat.get_var_and_expr_list();
            let idx = values
                .iter()
                .position(|value| value.get_position() == position)?;
            let var = vars.get(idx)?;
            let decl_id = LuaDeclId::new(semantic_model.get_file_id(), var.get_position());
            enqueue_semantic_id(ctx, worklist, LuaSemanticDeclId::LuaDecl(decl_id));
            let document = semantic_model.get_document();
            let range = document.to_lsp_location(var.get_range())?;
            result.push(range);
        }
        LuaAst::LuaLocalStat(local_stat) => {
            let local_names = local_stat.get_local_name_list().collect::<Vec<_>>();
            let mut values = local_stat.get_value_exprs();
            let idx = values.position(|value| value.get_position() == position)?;
            let name = local_names.get(idx)?;
            let decl_id = LuaDeclId::new(semantic_model.get_file_id(), name.get_position());
            enqueue_semantic_id(ctx, worklist, LuaSemanticDeclId::LuaDecl(decl_id));
            let document = semantic_model.get_document();
            let range = document.to_lsp_location(name.get_range())?;
            result.push(range);
        }
        _ => {}
    }

    Some(())
}

fn search_string_references(
    semantic_model: &SemanticModel,
    token: LuaStringToken,
    result: &mut Vec<Location>,
) -> Option<()> {
    let string_token_text = token.get_value();
    let string_refs = semantic_model
        .get_db()
        .get_reference_index()
        .get_string_references(&string_token_text);

    for in_filed_reference_range in string_refs {
        let document = semantic_model.get_document_by_file_id(in_filed_reference_range.file_id)?;
        let location = document.to_lsp_location(in_filed_reference_range.value)?;
        result.push(location);
    }

    Some(())
}

fn fuzzy_search_references(
    compilation: &LuaCompilation,
    token: LuaSyntaxToken,
    result: &mut Vec<Location>,
) -> Option<()> {
    let name = LuaNameToken::cast(token)?;
    let name_text = name.get_name_text();
    let fuzzy_references = compilation
        .get_db()
        .get_reference_index()
        .get_index_references(&LuaMemberKey::Name(name_text.to_string().into()))?;

    let mut semantic_cache = HashMap::new();
    for in_filed_syntax_id in fuzzy_references {
        let semantic_model =
            if let Some(semantic_model) = semantic_cache.get_mut(&in_filed_syntax_id.file_id) {
                semantic_model
            } else {
                let semantic_model = compilation.get_semantic_model(in_filed_syntax_id.file_id)?;
                semantic_cache.insert(in_filed_syntax_id.file_id, semantic_model);
                semantic_cache.get_mut(&in_filed_syntax_id.file_id)?
            };

        let document = semantic_model.get_document();
        let range = in_filed_syntax_id.value.get_range();
        let location = document.to_lsp_location(range)?;
        result.push(location);
    }

    Some(())
}

fn search_type_decl_references(
    semantic_model: &SemanticModel,
    type_decl_id: LuaTypeDeclId,
    result: &mut Vec<Location>,
) -> Option<()> {
    let refs = semantic_model
        .get_db()
        .get_reference_index()
        .get_type_references(&type_decl_id)?;
    let mut document_cache = HashMap::new();
    for in_filed_reference_range in refs {
        let document = if let Some(document) = document_cache.get(&in_filed_reference_range.file_id)
        {
            document
        } else {
            let document =
                semantic_model.get_document_by_file_id(in_filed_reference_range.file_id)?;
            document_cache.insert(in_filed_reference_range.file_id, document);
            document_cache.get(&in_filed_reference_range.file_id)?
        };
        let location = document.to_lsp_location(in_filed_reference_range.value)?;
        result.push(location);
    }

    Some(())
}

fn enqueue_value_alias_references(
    ctx: &mut ReferenceSearchContext,
    semantic_model: &SemanticModel,
    decl_ref: &DeclReferenceCell,
    worklist: &mut Vec<LuaSemanticDeclId>,
) -> Option<()> {
    let root = semantic_model.get_root();
    let position = decl_ref.range.start();
    let token = root.syntax().token_at_offset(position).right_biased()?;
    let parent = token.parent()?;

    match parent.parent()? {
        assign_stat_node if LuaAssignStat::can_cast(assign_stat_node.kind().into()) => {
            let assign_stat = LuaAssignStat::cast(assign_stat_node)?;
            let (vars, values) = assign_stat.get_var_and_expr_list();
            let idx = values
                .iter()
                .position(|value| value.get_position() == position)?;
            let var = vars.get(idx)?;
            let decl_id = semantic_model
                .find_decl(var.syntax().clone().into(), SemanticDeclLevel::default())?;
            if let LuaSemanticDeclId::Member(member_id) = decl_id {
                enqueue_semantic_id(ctx, worklist, LuaSemanticDeclId::Member(member_id));
            }
        }
        table_field_node if LuaTableField::can_cast(table_field_node.kind().into()) => {
            let table_field = LuaTableField::cast(table_field_node)?;
            let decl_id = semantic_model.find_decl(
                table_field.syntax().clone().into(),
                SemanticDeclLevel::default(),
            )?;
            if let LuaSemanticDeclId::Member(member_id) = decl_id {
                enqueue_semantic_id(ctx, worklist, LuaSemanticDeclId::Member(member_id));
            }
        }
        _ => {}
    }

    Some(())
}

/// 如果是模块导出, 那么我们需要找到所有引用了这个模块的变量
fn extend_module_return_value_references<'a>(
    ctx: &mut ReferenceSearchContext,
    semantic_model: &SemanticModel<'a>,
    compilation: &'a LuaCompilation,
    semantic_cache: &mut HashMap<FileId, Arc<SemanticModel<'a>>>,
    decl_id: LuaDeclId,
    result: &mut Vec<Location>,
    worklist: &mut Vec<LuaSemanticDeclId>,
) -> Option<()> {
    let module_file_id = decl_id.file_id;
    let module_info = semantic_model
        .get_db()
        .get_module_index()
        .get_module(module_file_id)?;
    if module_info.semantic_id.as_ref() != Some(&LuaSemanticDeclId::LuaDecl(decl_id)) {
        return Some(());
    }

    if !ctx.visited_module_exports.insert(module_file_id) {
        return Some(());
    }

    let file_dependency = semantic_model
        .get_db()
        .get_file_dependencies_index()
        .get_file_dependencies();
    let mut dependents = file_dependency.collect_file_dependents(vec![module_file_id]);
    dependents.sort();
    let mut visited_bindings: HashSet<LuaSemanticDeclId> = HashSet::new();

    for dependent_file_id in dependents {
        let dependent_semantic_model =
            get_semantic_model_cached(compilation, semantic_cache, dependent_file_id)?;

        let root = dependent_semantic_model.get_root();
        for node in root.descendants::<LuaAst>() {
            let LuaAst::LuaCallExpr(call_expr) = node else {
                continue;
            };

            if !call_expr.is_require() {
                continue;
            }

            if resolve_require_target_file_id(dependent_semantic_model.as_ref(), &call_expr)
                != Some(module_file_id)
            {
                continue;
            }

            if let Some(binding_semantic) =
                find_require_call_binding_semantic(dependent_semantic_model.as_ref(), &call_expr)
            {
                if !visited_bindings.insert(binding_semantic.clone()) {
                    continue;
                }

                match binding_semantic {
                    LuaSemanticDeclId::LuaDecl(_) | LuaSemanticDeclId::Member(_) => {
                        enqueue_semantic_id(ctx, worklist, binding_semantic);
                    }
                    _ => {}
                }
            } else {
                let document = dependent_semantic_model.get_document();
                let location = document.to_lsp_location(call_expr.get_range())?;
                result.push(location);
            }
        }
    }

    Some(())
}

fn resolve_require_target_file_id(
    semantic_model: &SemanticModel,
    call_expr: &LuaCallExpr,
) -> Option<FileId> {
    let args = call_expr.get_args_list()?;
    let first_arg = args.get_args().next()?;
    let require_path_type = semantic_model.infer_expr(first_arg).ok()?;
    let module_path: String = match &require_path_type {
        LuaType::StringConst(module_path) => module_path.as_ref().to_string(),
        _ => return None,
    };

    let module_info = semantic_model
        .get_db()
        .get_module_index()
        .find_module(&module_path)?;
    Some(module_info.file_id)
}

fn find_require_call_binding_semantic(
    semantic_model: &SemanticModel,
    call_expr: &LuaCallExpr,
) -> Option<LuaSemanticDeclId> {
    let position = call_expr.get_position();

    let mut current = call_expr.syntax().parent();
    while let Some(node) = current {
        let Some(parent) = LuaAst::cast(node.clone()) else {
            current = node.parent();
            continue;
        };

        match parent {
            LuaAst::LuaLocalStat(local_stat) => {
                let local_names = local_stat.get_local_name_list().collect::<Vec<_>>();
                let mut values = local_stat.get_value_exprs();
                let idx = values.position(|value| value.get_position() == position)?;
                let name = local_names.get(idx)?;
                return Some(LuaSemanticDeclId::LuaDecl(LuaDeclId::new(
                    semantic_model.get_file_id(),
                    name.get_position(),
                )));
            }
            LuaAst::LuaAssignStat(assign_stat) => {
                let (vars, values) = assign_stat.get_var_and_expr_list();
                let idx = values
                    .iter()
                    .position(|value| value.get_position() == position)?;
                let var = vars.get(idx)?;
                return semantic_model
                    .find_decl(var.syntax().clone().into(), SemanticDeclLevel::default());
            }
            _ => {}
        }

        current = node.parent();
    }

    None
}

#[allow(unused)]
fn filter_duplicate_and_covered_locations(locations: Vec<Location>) -> Vec<Location> {
    if locations.is_empty() {
        return locations;
    }
    let mut sorted_locations = locations;
    sorted_locations.sort_by(|a, b| {
        a.uri
            .to_string()
            .cmp(&b.uri.to_string())
            .then_with(|| a.range.start.line.cmp(&b.range.start.line))
            .then_with(|| b.range.end.line.cmp(&a.range.end.line))
    });

    let mut result = Vec::new();
    let mut seen_lines_by_uri: HashMap<String, HashSet<u32>> = HashMap::new();

    for location in sorted_locations {
        let uri_str = location.uri.to_string();
        let seen_lines = seen_lines_by_uri.entry(uri_str).or_default();

        let start_line = location.range.start.line;
        let end_line = location.range.end.line;

        let is_covered = (start_line..=end_line).any(|line| seen_lines.contains(&line));

        if !is_covered {
            for line in start_line..=end_line {
                seen_lines.insert(line);
            }
            result.push(location);
        }
    }

    // 最终按位置排序
    result.sort_by(|a, b| {
        a.uri
            .to_string()
            .cmp(&b.uri.to_string())
            .then_with(|| a.range.start.line.cmp(&b.range.start.line))
            .then_with(|| a.range.start.character.cmp(&b.range.start.character))
    });

    result
}

fn enqueue_semantic_id(
    ctx: &mut ReferenceSearchContext,
    worklist: &mut Vec<LuaSemanticDeclId>,
    semantic_id: LuaSemanticDeclId,
) {
    if ctx.visited_semantic_ids.insert(semantic_id.clone()) {
        worklist.push(semantic_id);
    }
}

fn get_semantic_model_cached<'a>(
    compilation: &'a LuaCompilation,
    semantic_cache: &mut HashMap<FileId, Arc<SemanticModel<'a>>>,
    file_id: FileId,
) -> Option<Arc<SemanticModel<'a>>> {
    if let Some(cached) = semantic_cache.get(&file_id) {
        return Some(Arc::clone(cached));
    }

    let semantic_model = Arc::new(compilation.get_semantic_model(file_id)?);
    semantic_cache.insert(file_id, Arc::clone(&semantic_model));
    Some(semantic_model)
}

fn search_semantic_references_with_ctx<'a>(
    ctx: &mut ReferenceSearchContext,
    compilation: &'a LuaCompilation,
    semantic_cache: &mut HashMap<FileId, Arc<SemanticModel<'a>>>,
    start: LuaSemanticDeclId,
    result: &mut Vec<Location>,
) -> Option<()> {
    let mut worklist = Vec::new();
    if ctx.visited_semantic_ids.insert(start.clone()) {
        worklist.push(start);
    } else {
        return Some(());
    }

    let mut first = true;
    let mut start_ret = Some(());

    while let Some(semantic_id) = worklist.pop() {
        let ret = match semantic_id {
            LuaSemanticDeclId::LuaDecl(decl_id) => {
                match get_semantic_model_cached(compilation, semantic_cache, decl_id.file_id) {
                    Some(semantic_model) => search_decl_references_with_ctx(
                        ctx,
                        semantic_model.as_ref(),
                        compilation,
                        semantic_cache,
                        decl_id,
                        result,
                        &mut worklist,
                    ),
                    None => None,
                }
            }
            LuaSemanticDeclId::Member(member_id) => {
                match get_semantic_model_cached(compilation, semantic_cache, member_id.file_id) {
                    Some(semantic_model) => search_member_references_with_ctx(
                        ctx,
                        semantic_model.as_ref(),
                        compilation,
                        semantic_cache,
                        member_id,
                        result,
                        &mut worklist,
                    ),
                    None => None,
                }
            }
            _ => Some(()),
        };

        if first {
            start_ret = ret;
            first = false;
        }
    }

    start_ret
}