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

Method extractStruct

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

* Extract a struct

(node: SyntaxNode)

Source from the content-addressed store, hash-verified

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