| 13923 | } |
| 13924 | |
| 13925 | static char *handle_get_code_snippet(cbm_mcp_server_t *srv, const char *args) { |
| 13926 | char *qn = cbm_mcp_get_string_arg(args, "qualified_name"); |
| 13927 | char *project = get_project_arg(args); |
| 13928 | bool include_neighbors = cbm_mcp_get_bool_arg(args, "include_neighbors"); |
| 13929 | |
| 13930 | if (!qn) { |
| 13931 | free(project); |
| 13932 | return cbm_mcp_text_result("qualified_name is required", true); |
| 13933 | } |
| 13934 | |
| 13935 | cbm_store_t *store = resolve_store(srv, project); |
| 13936 | if (!store) { |
| 13937 | char *_err = build_project_list_error("project not found or not indexed"); |
| 13938 | char *_res = cbm_mcp_text_result(_err, true); |
| 13939 | free(_err); |
| 13940 | free(qn); |
| 13941 | free(project); |
| 13942 | return _res; |
| 13943 | } |
| 13944 | |
| 13945 | char *not_indexed = verify_project_indexed(store, project); |
| 13946 | if (not_indexed) { |
| 13947 | free(qn); |
| 13948 | free(project); |
| 13949 | return not_indexed; |
| 13950 | } |
| 13951 | |
| 13952 | /* Default to current project (same as all other tools) */ |
| 13953 | const char *effective_project = project ? project : srv->current_project; |
| 13954 | |
| 13955 | /* Tier 1: Exact QN match */ |
| 13956 | cbm_node_t node = {0}; |
| 13957 | int rc = cbm_store_find_node_by_qn(store, effective_project, qn, &node); |
| 13958 | if (rc == CBM_STORE_OK) { |
| 13959 | char *result = build_snippet_response(srv, &node, NULL, include_neighbors, NULL, 0, args); |
| 13960 | free_node_contents(&node); |
| 13961 | free(qn); |
| 13962 | free(project); |
| 13963 | return result; |
| 13964 | } |
| 13965 | |
| 13966 | /* Tier 1b: a bare base QN names every signature-qualified overload of it |
| 13967 | * (#2061). Finds nothing for QNs without a callable identity suffix. */ |
| 13968 | cbm_node_t *tier_nodes = NULL; |
| 13969 | int tier_count = 0; |
| 13970 | cbm_store_find_nodes_by_qn_base(store, effective_project, qn, false, &tier_nodes, &tier_count); |
| 13971 | char *result = |
| 13972 | snippet_from_tier(srv, tier_nodes, tier_count, qn, "base", include_neighbors, args); |
| 13973 | |
| 13974 | /* Tier 2: Suffix match — handles partial QNs ("main.HandleRequest") |
| 13975 | * and short names ("ProcessOrder") via LIKE '%.X'. */ |
| 13976 | if (!result) { |
| 13977 | tier_nodes = NULL; |
| 13978 | tier_count = 0; |
| 13979 | cbm_store_find_nodes_by_qn_suffix(store, effective_project, qn, &tier_nodes, &tier_count); |
| 13980 | result = |
| 13981 | snippet_from_tier(srv, tier_nodes, tier_count, qn, "suffix", include_neighbors, args); |
| 13982 | } |
no test coverage detected