Skip to content

Commit fe569f1

Browse files
committed
Fixed issues in relating nodes with each other
1 parent 6bc3ceb commit fe569f1

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

rocket-chatter-ingestion-server/src/process/prepare/processor/core/treeNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class TreeNode {
4141
}
4242

4343
getID(): string {
44-
return `${this.sourceFileRelativePath}:${this.name}:${this.type}`
44+
return `${this.sourceFileRelativePath}:${this.name}`
4545
}
4646

4747
pushUse(...uses: { name: string; type: string }[]) {

rocket-chatter-ingestion-server/src/process/prepare/processor/file.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,34 @@ export class FileProcessor implements IFileProcessor {
5959
.filter((node: any) => node.source.value.startsWith(".")) // Filter out all library/non-relative imports
6060
for (const i of imports) {
6161
const importName = (i as any).specifiers[0].local.name
62+
const relativePath = (i as any).source.value
6263

63-
const projectPath = sourceFile.getProjectPath()
64-
const targetFileAbsolutePath = path
65-
.resolve(path.join(sourceFile.getFullPath(), (i as any).source.value))
66-
.replace(/\\/g, "/")
67-
const targetFileRelativePath = targetFileAbsolutePath.slice(
68-
projectPath.length
69-
)
64+
const currentFileDirectory = sourceFile
65+
.getFullPath()
66+
.slice(0, sourceFile.getFullPath().lastIndexOf("/"))
67+
console.log(currentFileDirectory)
7068

71-
parsedImports.set(importName, targetFileRelativePath)
69+
let finalPath = ""
70+
const backSteps = relativePath.match(/\.\.\//g)
71+
if (backSteps) {
72+
const backStepsCount = backSteps.length
73+
const currentFileDirectoryParts = currentFileDirectory.split("/")
74+
const finalPathParts = currentFileDirectoryParts.slice(
75+
0,
76+
currentFileDirectoryParts.length - backStepsCount
77+
)
78+
finalPath = path
79+
.join(...finalPathParts, relativePath)
80+
.replaceAll("\\", "/")
81+
} else {
82+
finalPath = path
83+
.join(currentFileDirectory, relativePath)
84+
.replaceAll("\\", "/")
85+
}
86+
87+
console.log(relativePath, finalPath)
88+
89+
parsedImports.set(importName, finalPath)
7290
}
7391
}
7492

@@ -79,7 +97,7 @@ export class FileProcessor implements IFileProcessor {
7997
.filter((x) => x.name)
8098
.map((x) => {
8199
if (parsedImports.has(x.name)) {
82-
x.name = `${parsedImports.get(x.name)!}:${x.name}`
100+
x.name = `${parsedImports.get(x.name)!}.ts:${x.name}`
83101
}
84102
return x
85103
})
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { insertDataIntoDB } from "./process/ingest/ingest"
12
import { Codebase } from "./process/prepare/codebase"
23
import { FileProcessor } from "./process/prepare/processor/file"
34

45
async function main() {
5-
const codebase = new Codebase("./project2", new FileProcessor(), 1)
6+
const codebase = new Codebase("./project", new FileProcessor(), 1)
67
await codebase.process()
7-
// await codebase.embed()
8+
await codebase.embed()
89

9-
// insertDataIntoDB(codebase.embeddingsDirPath, 1)
10+
insertDataIntoDB(codebase.embeddingsDirPath, 1)
1011
}
1112

1213
main()

0 commit comments

Comments
 (0)