MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / findSymbolByName

Function findSymbolByName

src/tools/ast/edit-symbol.ts:63–131  ·  view source on GitHub ↗
(
  rootNode: any,
  nodeTypes: string[],
  name: string,
  parentClassName?: string,
)

Source from the content-addressed store, hash-verified

61};
62
63function findSymbolByName(
64 rootNode: any,
65 nodeTypes: string[],
66 name: string,
67 parentClassName?: string,
68): FoundSymbol[] {
69 const matches: FoundSymbol[] = [];
70
71 function getSymbolName(node: any): string | null {
72 // Try common field names
73 for (const field of ['name']) {
74 const f = node.childForFieldName(field);
75 if (f) return f.text;
76 }
77 // Fallback: look for first identifier child
78 for (let i = 0; i < node.childCount; i++) {
79 const c = node.child(i);
80 if (c && (c.type === 'identifier' || c.type === 'property_identifier' || c.type === 'type_identifier')) {
81 return c.text;
82 }
83 }
84 return null;
85 }
86
87 function getEnclosingClassName(node: any): string | null {
88 let cur = node.parent;
89 while (cur) {
90 if (
91 cur.type === 'class_declaration' ||
92 cur.type === 'abstract_class_declaration' ||
93 cur.type === 'class_definition' ||
94 cur.type === 'struct_item' ||
95 cur.type === 'class' // generic
96 ) {
97 return getSymbolName(cur);
98 }
99 cur = cur.parent;
100 }
101 return null;
102 }
103
104 function visit(node: any) {
105 if (nodeTypes.includes(node.type)) {
106 const symName = getSymbolName(node);
107 if (symName === name) {
108 const enclosing = getEnclosingClassName(node);
109 if (!parentClassName || enclosing === parentClassName) {
110 matches.push({
111 name,
112 kind: node.type,
113 startIndex: node.startIndex,
114 endIndex: node.endIndex,
115 startRow: node.startPosition.row,
116 endRow: node.endPosition.row,
117 startColumn: node.startPosition.column,
118 endColumn: node.endPosition.column,
119 });
120 }

Callers 1

executeMethod · 0.85

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected