Skip to content

Commit 5fb94de

Browse files
authored
Fix/csharp extraction file tree (#102)
Fixed filesystem for unusual project architectures
1 parent 7633db7 commit 5fb94de

File tree

1 file changed

+22
-1
lines changed
  • packages/cli/src/symbolExtractor/csharp

1 file changed

+22
-1
lines changed

packages/cli/src/symbolExtractor/csharp/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import {
99
import { DependencyManifest } from "@nanoapi.io/shared";
1010
import { DotNetProject } from "../../languagePlugins/csharp/projectMapper/index.js";
1111

12+
/**
13+
* Extracts C# symbols from the given files.
14+
* @param files - A map of file paths to their content.
15+
* @param dependencyManifest - The dependency manifest.
16+
* @param symbolsToExtract - A map of symbols to extract, where the key is the symbol name and the value is an object containing the file path and a set of symbols.
17+
* @param napiConfig - The NAPI configuration.
18+
* @returns - A map of extracted files, where the key is the file path and the value is an object containing the file path and content.
19+
*/
1220
export function extractCSharpSymbols(
1321
files: Map<string, { path: string; content: string }>,
1422
dependencyManifest: DependencyManifest,
@@ -20,9 +28,11 @@ export function extractCSharpSymbols(
2028
const extractor = new CSharpExtractor(files, dependencyManifest);
2129
const symbols: string[] = [];
2230
const extractedFiles: ExtractedFile[] = [];
31+
// Flatten the symbolsToExtract map
2332
for (const symbolSet of symbolsToExtract.values()) {
2433
symbols.push(...Array.from(symbolSet.symbols));
2534
}
35+
// Extract symbols from the files
2636
for (const symbol of symbols) {
2737
const extractedFile = extractor.extractSymbolByName(symbol);
2838
if (extractedFile) {
@@ -36,14 +46,25 @@ export function extractCSharpSymbols(
3646
if (!subprojects.includes(subproject)) {
3747
subprojects.push(subproject);
3848
}
39-
const key = path.join(subproject.name, namespace, `${name}.cs`);
49+
// File path for the extracted file
50+
const fakeprojectpath = subproject.name.split(".").join(path.sep);
51+
const spindex = namespace.split(".").indexOf(subproject.name);
52+
const key = path.join(
53+
namespace
54+
.split(".")
55+
.slice(spindex !== -1 ? spindex : 0)
56+
.join(path.sep)
57+
.replace(fakeprojectpath, subproject.name),
58+
`${name}.cs`,
59+
);
4060
if (!extractedFilesMap.has(key)) {
4161
extractedFilesMap.set(key, {
4262
path: key,
4363
content: extractor.getContent(extractedFile),
4464
});
4565
}
4666
}
67+
// Add the .csproj and GlobalUsings.cs files for each subproject
4768
for (const subproject of subprojects) {
4869
const projectPath = path.join(subproject.name, `${subproject.name}.csproj`);
4970
const globalUsingPath = path.join(subproject.name, "GlobalUsings.cs");

0 commit comments

Comments
 (0)