| 3671 | extern const TSLanguage *tree_sitter_java(void); |
| 3672 | |
| 3673 | void cbm_run_java_lsp(CBMArena *arena, CBMFileResult *result, const char *source, int source_len, |
| 3674 | TSNode root) { |
| 3675 | if (!arena || !result || !source) |
| 3676 | return; |
| 3677 | |
| 3678 | CBMTypeRegistry reg; |
| 3679 | cbm_registry_init(®, arena); |
| 3680 | |
| 3681 | /* Java stdlib — java.lang/util/io/etc. */ |
| 3682 | cbm_java_stdlib_register(®, arena); |
| 3683 | |
| 3684 | /* Module QN comes from the file result. */ |
| 3685 | const char *module_qn = result->module_qn ? result->module_qn : ""; |
| 3686 | |
| 3687 | JavaLSPContext ctx; |
| 3688 | java_lsp_init(&ctx, arena, source, source_len, ®, NULL, module_qn, &result->resolved_calls); |
| 3689 | |
| 3690 | /* Add imports collected by extract_imports.c — they are stored as |
| 3691 | * (local_name, module_path = full Java path). We translate to the LSP |
| 3692 | * import shape here. |
| 3693 | * |
| 3694 | * Note: extract_imports.c can't tell static / on-demand from the AST in |
| 3695 | * a uniform way, so the LSP re-scans the AST for those distinctions in |
| 3696 | * java_lsp_process_file. We still re-emit TYPE imports here so that |
| 3697 | * resolution works even if process_file's import scan misses |
| 3698 | * pre-grammar-version edge cases. */ |
| 3699 | for (int i = 0; i < result->imports.count; i++) { |
| 3700 | CBMImport *imp = &result->imports.items[i]; |
| 3701 | if (!imp->local_name || !imp->module_path) |
| 3702 | continue; |
| 3703 | java_lsp_add_import(&ctx, imp->local_name, imp->module_path, CBM_JAVA_IMPORT_TYPE); |
| 3704 | } |
| 3705 | |
| 3706 | /* Register file-local defs into the registry. */ |
| 3707 | register_local_func_or_type_from_file(&ctx, ®, result); |
| 3708 | |
| 3709 | /* Populate field metadata from the AST so eval_field_access works on |
| 3710 | * receivers other than `this`. Also patch method signatures with |
| 3711 | * generics-preserving types (extract_defs strips generics from |
| 3712 | * d->param_types via clean_type_name). */ |
| 3713 | uint32_t rn = ts_node_named_child_count(root); |
| 3714 | for (uint32_t i = 0; i < rn; i++) { |
| 3715 | TSNode c = ts_node_named_child(root, i); |
| 3716 | const char *ck = ts_node_type(c); |
| 3717 | if (strcmp(ck, "class_declaration") == 0 || strcmp(ck, "interface_declaration") == 0 || |
| 3718 | strcmp(ck, "enum_declaration") == 0 || strcmp(ck, "record_declaration") == 0) { |
| 3719 | populate_class_fields_from_ast(&ctx, ®, c, NULL); |
| 3720 | patch_method_signatures_from_ast(&ctx, ®, c, NULL); |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | /* Walk the file. */ |
| 3725 | java_lsp_process_file(&ctx, root); |
| 3726 | } |
| 3727 | |
| 3728 | /* ── Cross-file LSP ───────────────────────────────────────────────── */ |
| 3729 |
no test coverage detected