MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractStruct

Method extractStruct

src/extraction/tree-sitter.ts:1869–1909  ·  view source on GitHub ↗

* Extract a struct

(node: SyntaxNode)

Source from the content-addressed store, hash-verified

1867 * Extract a struct
1868 */
1869 private extractStruct(node: SyntaxNode): void {
1870 if (!this.extractor) return;
1871
1872 // Skip forward declarations and type references (no body = not a definition)
1873 // — EXCEPT C# positional records (`record struct M(decimal Amount);`),
1874 // complete definitions with no body block. (#831)
1875 const body = getChildByField(node, this.extractor.bodyField);
1876 if (!body && node.type !== 'record_declaration') return;
1877
1878 const name = extractName(node, this.source, this.extractor);
1879 const docstring = getPrecedingDocstring(node, this.source);
1880 const visibility = this.extractor.getVisibility?.(node);
1881 const isExported = this.extractor.isExported?.(node, this.source);
1882
1883 const structNode = this.createNode('struct', name, node, {
1884 docstring,
1885 visibility,
1886 isExported,
1887 });
1888 if (!structNode) return;
1889
1890 // Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable)
1891 this.extractInheritance(node, structNode.id);
1892
1893 // C# primary-constructor parameter dependencies (`struct P(int x)`, and
1894 // `record struct M(decimal Amount)` which the grammar nests here).
1895 this.extractCsharpPrimaryCtorParamRefs(node, structNode.id);
1896
1897 // Push to stack for field extraction (bodiless positional records have
1898 // no members to visit)
1899 if (body) {
1900 this.nodeStack.push(structNode.id);
1901 for (let i = 0; i < body.namedChildCount; i++) {
1902 const child = body.namedChild(i);
1903 if (child) {
1904 this.visitNode(child);
1905 }
1906 }
1907 this.nodeStack.pop();
1908 }
1909 }
1910
1911 /**
1912 * Extract an enum

Callers 2

visitNodeMethod · 0.95

Calls 7

createNodeMethod · 0.95
extractInheritanceMethod · 0.95
visitNodeMethod · 0.95
getChildByFieldFunction · 0.90
getPrecedingDocstringFunction · 0.90
extractNameFunction · 0.85

Tested by

no test coverage detected