Skip to content

Commit 4d92b81

Browse files
committed
Updated DBNode in accordance to the new TreeNode
1 parent 3c3142f commit 4d92b81

File tree

3 files changed

+20
-71
lines changed

3 files changed

+20
-71
lines changed

rocket-chatter-ingestion-server/src/core/dbNode.ts

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,14 @@
1-
import { SyntaxKind } from "ts-morph"
2-
import { Commons } from "./commons"
1+
import { TreeNode } from "../process/prepare/processor/core/treeNode"
32
import { LLM } from "./llm"
4-
import { TreeNode } from "./treeNode"
53

6-
const DBNODE_NAMES_MAP: Record<string, string> = {
7-
File: "File",
8-
FunctionDeclaration: "Function",
9-
10-
Parameter: "Variable",
11-
BindingElement: "Variable",
12-
VariableDeclaration: "Variable",
13-
VariableStatement: "Variable",
14-
15-
EnumDeclaration: "Enum",
16-
ClassDeclaration: "Class",
17-
TypeAliasDeclaration: "Type",
18-
InterfaceDeclaration: "Interface",
19-
NamespaceDeclaration: "Namespace",
20-
21-
MethodDeclaration: "Member",
22-
PropertyDeclaration: "Member",
23-
GetAccessor: "Member",
24-
SetAccessor: "Member",
25-
26-
ImportDeclaration: "Import",
27-
ExpressionStatement: "Variable",
28-
29-
ModuleDeclaration: "Module",
30-
}
31-
32-
export type DBNodeRelation = "USED_IN" | "IN_FILE" | "CALLED_BY" | "LOCAL_OF"
4+
export type DBNodeRelation = "IN_FILE" | "USES"
335

346
export class DBNode {
357
id: string
368
name: string
37-
kind: string
389
type: string
3910

4011
code: string
41-
comments: string[]
4212

4313
filePath: string
4414
relations: { target: string; relation: DBNodeRelation }[]
@@ -52,10 +22,8 @@ export class DBNode {
5222
constructor(node: {
5323
id: string
5424
name: string
55-
kind: string
5625
type: string
5726
code: string
58-
comments: string[]
5927
filePath: string
6028
relations: { target: string; relation: DBNodeRelation }[]
6129
nameEmbeddings: number[]
@@ -66,11 +34,9 @@ export class DBNode {
6634
}) {
6735
this.id = node.id
6836
this.name = node.name
69-
this.kind = node.kind
7037
this.type = node.type
7138

7239
this.code = node.code
73-
this.comments = node.comments
7440

7541
this.filePath = node.filePath
7642
this.relations = node.relations
@@ -83,41 +49,25 @@ export class DBNode {
8349
}
8450

8551
static fromTreeNode(node: TreeNode): DBNode {
86-
let name = node.getName()
87-
const contents =
88-
node.isFile ||
89-
[
90-
SyntaxKind.SourceFile,
91-
SyntaxKind.ModuleDeclaration,
92-
SyntaxKind.ModuleDeclaration,
93-
SyntaxKind.ClassDeclaration,
94-
].includes(node.getKind())
95-
? ""
96-
: node.node.getText().trim()
97-
const comments =
98-
node.node.getFullText().match(/\/\*[\s\S]*?\*\/|\/\/.*/g) || []
99-
100-
const n: DBNode = new DBNode({
52+
return new DBNode({
10153
id: node.getID(),
102-
relations: [],
54+
name: node.name,
55+
type: node.type,
10356

104-
nameEmbeddings: [],
105-
codeEmbeddings: [],
57+
code: node.body,
10658

107-
name: name,
108-
kind: node.getKindName(),
109-
type: node.getType().replace(Commons.getProjectPath(), ""),
59+
filePath: node.sourceFileRelativePath,
60+
relations: node.uses.map((use) => ({
61+
target: use.name,
62+
relation: "USES",
63+
})),
11064

111-
code: contents,
112-
comments: comments.map((c) => c.trim()),
113-
114-
filePath: node.getFilePath(),
65+
nameEmbeddings: [],
66+
codeEmbeddings: [],
11567

116-
isFile: node.isFile,
68+
isFile: false,
11769
descriptor: "Node",
11870
})
119-
120-
return n
12171
}
12272

12373
static async fillEmbeddings(node: DBNode): Promise<DBNode> {
@@ -128,7 +78,7 @@ export class DBNode {
12878
}
12979

13080
getNodeName(): string {
131-
return DBNODE_NAMES_MAP[this.kind] || "Node"
81+
return this.name
13282
}
13383

13484
getDBInsertQuery(): string {
@@ -137,10 +87,9 @@ export class DBNode {
13787
CREATE (n:${this.descriptor} {
13888
id: $id,
13989
name: $name,
140-
kind: $kind,
14190
type: $type,
91+
14292
code: $code,
143-
comments: $comments,
14493
filePath: $filePath,
14594
14695
nameEmbeddings: $nameEmbeddings,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class TreeNode {
55

66
lineNumber: number
77
columnNumber: number
8-
sourceFilePath: string
8+
sourceFileRelativePath: string
99

1010
uses: {
1111
name: string
@@ -25,15 +25,15 @@ export class TreeNode {
2525
this.body = body
2626
this.lineNumber = lineNumber
2727
this.columnNumber = columnNumber
28-
this.sourceFilePath = sourceFilePath
28+
this.sourceFileRelativePath = sourceFilePath
2929
}
3030

3131
toString() {
3232
return `${this.name} (${this.type})`
3333
}
3434

3535
getID(): string {
36-
return `${this.sourceFilePath}:${this.name}:${this.type}:${this.lineNumber}:${this.columnNumber}`
36+
return `${this.sourceFileRelativePath}:${this.name}:${this.type}:${this.lineNumber}:${this.columnNumber}`
3737
}
3838

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class FileProcessor implements IFileProcessor {
6767

6868
// Replace import names with absolute paths
6969
for (const treeNode of treeNodes) {
70-
treeNode.sourceFilePath = sourceFile.getFullPath()
70+
treeNode.sourceFileRelativePath = sourceFile.getFullPath()
7171
treeNode.uses = treeNode.uses
7272
.filter((x) => x.name)
7373
.map((x) => {

0 commit comments

Comments
 (0)