Is this an identifier-like node that represents a reference?
| 51 | |
| 52 | // Is this an identifier-like node that represents a reference? |
| 53 | static bool is_reference_node(TSNode node, CBMLanguage lang) { |
| 54 | const char *kind = ts_node_type(node); |
| 55 | |
| 56 | /* Python's attribute node and its terminal identifier describe the same |
| 57 | * source occurrence. For a direct callable-value argument, keep the leaf |
| 58 | * as the raw carrier (so unresolved cases retain a useful short-name |
| 59 | * USAGE) and stamp it with the full attribute span below. Receivers remain |
| 60 | * independent value references. */ |
| 61 | if (lang == CBM_LANG_PYTHON && strcmp(kind, "attribute") == 0 && |
| 62 | !ts_node_is_null(python_direct_callable_attribute_site(node))) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /* A Rust scoped_identifier owns the complete path occurrence. Its nested |
| 67 | * path/identifier children are grammar structure, not additional value |
| 68 | * references; keeping them would let a short-name fallback bind a decoy. */ |
| 69 | if (lang == CBM_LANG_RUST && |
| 70 | (strcmp(kind, "identifier") == 0 || strcmp(kind, "scoped_identifier") == 0)) { |
| 71 | TSNode parent = ts_node_parent(node); |
| 72 | if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "scoped_identifier") == 0) { |
| 73 | return false; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /* Some grammars expose the sigil/scope as a named wrapper around a generic |
| 78 | * identifier. Keep exactly one occurrence: the wrapper carries the source |
| 79 | * spelling that resolution needs (`$watched`, `a:watched`). |
| 80 | * |
| 81 | * The language gate MUST precede the parent fetch: ts_node_parent descends |
| 82 | * from the root (O(depth)), and fetching it for every identifier in every |
| 83 | * language made deep-nesting extraction quadratic across the board (the |
| 84 | * stack_overflow deep tests went 0-1s -> 39-119s and blew the suite |
| 85 | * budget on every non-M4 venue). */ |
| 86 | if ((lang == CBM_LANG_PUPPET || lang == CBM_LANG_VIMSCRIPT) && |
| 87 | strcmp(kind, "identifier") == 0) { |
| 88 | TSNode parent = ts_node_parent(node); |
| 89 | if (!ts_node_is_null(parent) && |
| 90 | ((lang == CBM_LANG_PUPPET && strcmp(ts_node_type(parent), "variable") == 0) || |
| 91 | (lang == CBM_LANG_VIMSCRIPT && strcmp(ts_node_type(parent), "argument") == 0))) { |
| 92 | return false; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Common identifier types across languages |
| 97 | if (strcmp(kind, "identifier") == 0 || strcmp(kind, "simple_identifier") == 0 || |
| 98 | strcmp(kind, "type_identifier") == 0) { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | // Language-specific reference types |
| 103 | switch (lang) { |
| 104 | case CBM_LANG_JAVASCRIPT: |
| 105 | case CBM_LANG_TYPESCRIPT: |
| 106 | case CBM_LANG_TSX: |
| 107 | case CBM_LANG_ARKTS: |
| 108 | case CBM_LANG_QML: |
| 109 | case CBM_LANG_CFSCRIPT: |
| 110 | return strcmp(kind, "property_identifier") == 0 || |
no test coverage detected