1- import { SyntaxKind } from "ts-morph"
2- import { Commons } from "./commons"
1+ import { TreeNode } from "../process/prepare/processor/core/treeNode"
32import { 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
346export 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,
0 commit comments