@@ -1994,6 +1994,8 @@ static void process_function(GoLSPContext *ctx, TSNode func_node) {
19941994 // resolver. Since #1909 receiver-qualified Go method QNs, that shared
19951995 // form is package_qn.ReceiverType.method for methods (the ONE-formula
19961996 // contract: cbm_go_receiver_type_name) and package_qn.func for functions.
1997+ // A package may hold any number of init() functions, so each one is
1998+ // package_qn.init#<file>:<N> (#1910, cbm_go_init_qn — the same formula).
19971999 ctx -> enclosing_func_qn = cbm_arena_sprintf (ctx -> arena , "%s.%s" , ctx -> package_qn , func_name );
19982000 if (strcmp (ts_node_type (func_node ), "method_declaration" ) == 0 ) {
19992001 TSNode recv = ts_node_child_by_field_name (func_node , "receiver" , 8 );
@@ -2004,6 +2006,9 @@ static void process_function(GoLSPContext *ctx, TSNode func_node) {
20042006 recv_type , func_name );
20052007 }
20062008 }
2009+ } else if (strcmp (func_name , "init" ) == 0 ) {
2010+ ctx -> enclosing_func_qn = cbm_go_init_qn (ctx -> arena , ctx -> enclosing_func_qn , ctx -> rel_path ,
2011+ func_node , ctx -> source );
20072012 }
20082013
20092014 // Push function scope
@@ -2261,7 +2266,7 @@ static void go_registry_with_stdlib(CBMTypeRegistry *reg, CBMArena *arena) {
22612266// --- Entry point: build registry from file defs + run LSP ---
22622267
22632268void cbm_run_go_lsp (CBMArena * arena , CBMFileResult * result , const char * source , int source_len ,
2264- TSNode root ) {
2269+ TSNode root , const char * rel_path ) {
22652270
22662271 CBMTypeRegistry reg ;
22672272 cbm_registry_init (& reg , arena );
@@ -2619,6 +2624,7 @@ void cbm_run_go_lsp(CBMArena *arena, CBMFileResult *result, const char *source,
26192624 // Phase 2: Build LSP context and run
26202625 GoLSPContext lsp_ctx ;
26212626 go_lsp_init (& lsp_ctx , arena , source , source_len , & reg , module_qn , & result -> resolved_calls );
2627+ lsp_ctx .rel_path = rel_path ;
26222628
26232629 // Add imports
26242630 for (int i = 0 ; i < result -> imports .count ; i ++ ) {
@@ -3239,9 +3245,9 @@ static void extract_type_params_from_ast(CBMArena *arena, CBMTypeRegistry *reg,
32393245extern const TSLanguage * tree_sitter_go (void );
32403246
32413247void cbm_run_go_lsp_cross (CBMArena * arena , const char * source , int source_len ,
3242- const char * module_qn , CBMLSPDef * defs , int def_count ,
3243- const char * * import_names , const char * * import_qns , int import_count ,
3244- TSTree * cached_tree , CBMResolvedCallArray * out ) {
3248+ const char * module_qn , const char * rel_path , CBMLSPDef * defs ,
3249+ int def_count , const char * * import_names , const char * * import_qns ,
3250+ int import_count , TSTree * cached_tree , CBMResolvedCallArray * out ) {
32453251 if (!source || source_len <= 0 )
32463252 return ;
32473253
@@ -3505,6 +3511,7 @@ void cbm_run_go_lsp_cross(CBMArena *arena, const char *source, int source_len,
35053511 // 4. Build LSP context and run
35063512 GoLSPContext ctx ;
35073513 go_lsp_init (& ctx , arena , source , source_len , & reg , module_qn , out );
3514+ ctx .rel_path = rel_path ;
35083515
35093516 for (int i = 0 ; i < import_count ; i ++ ) {
35103517 if (import_names [i ] && import_qns [i ]) {
@@ -3647,10 +3654,10 @@ CBMTypeRegistry *cbm_go_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, i
36473654}
36483655
36493656void cbm_run_go_lsp_cross_with_registry (CBMArena * arena , const char * source , int source_len ,
3650- const char * module_qn , CBMTypeRegistry * reg ,
3651- const char * * import_names , const char * * import_qns ,
3652- int import_count , TSTree * cached_tree ,
3653- CBMResolvedCallArray * out ) {
3657+ const char * module_qn , const char * rel_path ,
3658+ CBMTypeRegistry * reg , const char * * import_names ,
3659+ const char * * import_qns , int import_count ,
3660+ TSTree * cached_tree , CBMResolvedCallArray * out ) {
36543661 if (!source || source_len <= 0 || !reg )
36553662 return ;
36563663
@@ -3676,6 +3683,7 @@ void cbm_run_go_lsp_cross_with_registry(CBMArena *arena, const char *source, int
36763683
36773684 GoLSPContext ctx ;
36783685 go_lsp_init (& ctx , arena , source , source_len , reg , module_qn , out );
3686+ ctx .rel_path = rel_path ;
36793687 for (int i = 0 ; i < import_count ; i ++ ) {
36803688 if (import_names [i ] && import_qns [i ]) {
36813689 go_lsp_add_import (& ctx , import_names [i ], import_qns [i ]);
@@ -3825,8 +3833,8 @@ void cbm_batch_go_lsp_cross(CBMArena *arena, CBMBatchGoLSPFile *files, int file_
38253833
38263834 // Delegate to existing per-file function
38273835 cbm_run_go_lsp_cross (& file_arena , file -> source , file -> source_len , file -> module_qn ,
3828- file -> defs , file -> def_count , file -> import_names , file -> import_qns ,
3829- file -> import_count , file -> cached_tree , & file_out );
3836+ file -> rel_path , file -> defs , file -> def_count , file -> import_names ,
3837+ file -> import_qns , file -> import_count , file -> cached_tree , & file_out );
38303838
38313839 // Copy results to output arena (must outlive per-file arena)
38323840 if (file_out .count > 0 ) {
0 commit comments