Skip to content

Commit 7ff90c6

Browse files
authored
Export parent classes of nested classes (#126)
1 parent 9087f97 commit 7ff90c6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/cli/src/languagePlugins/csharp/extractor/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,15 @@ describe("CSharpExtractor", () => {
7676
subprojectUsingDirectives.includes("global using MyApp.Models;"),
7777
).toBe(true);
7878
});
79+
80+
test("should manage nested classes", () => {
81+
const extracted = extractor.extractSymbolFromFile(programpath, "Program");
82+
const symbols = extracted?.map((file) =>
83+
file.symbol.namespace !== ""
84+
? file.symbol.namespace + "." + file.symbol.name
85+
: file.symbol.name,
86+
);
87+
expect(symbols).not.toContain("OuterNamespace.OuterInnerClass");
88+
expect(symbols).toContain("OuterNamespace.OuterClass");
89+
});
7990
});

packages/cli/src/languagePlugins/csharp/extractor/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export class CSharpExtractor {
141141
const visitedSymbols = new Set<string>();
142142

143143
const addExtractedFile = (symbol: SymbolNode) => {
144+
// If the symbol is nested, we export the parent.
145+
while (symbol.parent) {
146+
symbol = symbol.parent;
147+
}
144148
if (!visitedSymbols.has(symbol.name)) {
145149
visitedSymbols.add(symbol.name);
146150
const subproject = this.projectMapper.findSubprojectForFile(

0 commit comments

Comments
 (0)