Skip to content

Commit aec26c1

Browse files
committed
chore: refactor nodetype labels
1 parent cfa0cec commit aec26c1

3 files changed

Lines changed: 42 additions & 51 deletions

File tree

ast/src/lang/asg.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,34 @@ impl FromStr for NodeType {
297297
}
298298
}
299299
}
300+
impl NodeType {
301+
pub fn all_labels() -> &'static [&'static str] {
302+
&[
303+
"Repository",
304+
"Package",
305+
"Language",
306+
"Directory",
307+
"File",
308+
"Import",
309+
"Library",
310+
"Class",
311+
"Trait",
312+
"Instance",
313+
"Function",
314+
"Endpoint",
315+
"Request",
316+
"Datamodel",
317+
"Feature",
318+
"Page",
319+
"Var",
320+
"UnitTest",
321+
"IntegrationTest",
322+
"E2etest",
323+
"Mock",
324+
]
325+
}
326+
}
327+
300328
impl std::fmt::Display for NodeType {
301329
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
302330
let s = match self {

ast/src/lang/graphs/neo4j/queries/edges.rs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,7 @@ pub fn find_dynamic_edges_for_file_query(file: &str) -> (String, BoltMap) {
292292
let mut params = BoltMap::new();
293293
boltmap_insert_str(&mut params, "file", file);
294294

295-
let static_types = vec![
296-
"Repository",
297-
"Package",
298-
"Language",
299-
"Directory",
300-
"File",
301-
"Import",
302-
"Library",
303-
"Class",
304-
"Trait",
305-
"Instance",
306-
"Function",
307-
"Endpoint",
308-
"Request",
309-
"Datamodel",
310-
"Feature",
311-
"Page",
312-
"Var",
313-
"UnitTest",
314-
"IntegrationTest",
315-
"E2etest",
316-
];
317-
318-
let static_labels = static_types
295+
let static_labels = NodeType::all_labels()
319296
.iter()
320297
.map(|t| format!("source:{}", t))
321298
.collect::<Vec<_>>()
@@ -336,30 +313,7 @@ pub fn find_dynamic_edges_for_file_query(file: &str) -> (String, BoltMap) {
336313
pub fn find_all_dynamic_edges_query() -> (String, BoltMap) {
337314
let params = BoltMap::new();
338315

339-
let static_types = vec![
340-
"Repository",
341-
"Package",
342-
"Language",
343-
"Directory",
344-
"File",
345-
"Import",
346-
"Library",
347-
"Class",
348-
"Trait",
349-
"Instance",
350-
"Function",
351-
"Endpoint",
352-
"Request",
353-
"Datamodel",
354-
"Feature",
355-
"Page",
356-
"Var",
357-
"UnitTest",
358-
"IntegrationTest",
359-
"E2etest",
360-
];
361-
362-
let static_labels = static_types
316+
let static_labels = NodeType::all_labels()
363317
.iter()
364318
.map(|t| format!("source:{}", t))
365319
.collect::<Vec<_>>()

ast/src/lang/graphs/neo4j/queries/nodes.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,21 @@ pub fn get_muted_nodes_for_files_query(files: &[String]) -> (String, BoltMap) {
500500
.collect::<Vec<_>>();
501501
boltmap_insert_list(&mut params, "files", files_list);
502502

503-
let query = "MATCH (n:Data_Bank)
503+
let labels_list = NodeType::all_labels()
504+
.iter()
505+
.map(|t| format!("'{}'", t))
506+
.collect::<Vec<_>>()
507+
.join(", ");
508+
509+
let query = format!(
510+
"MATCH (n:Data_Bank)
504511
WHERE n.file IN $files
505512
AND (n.is_muted = true OR n.is_muted = 'true')
506-
WITH n, [label IN labels(n) WHERE label IN ['Function', 'Class', 'DataModel', 'Endpoint', 'Request', 'File', 'Directory', 'Repository', 'Language', 'Library', 'Import', 'Instance', 'Page', 'Var', 'UnitTest', 'IntegrationTest', 'E2eTest', 'Trait']][0] as node_type
513+
WITH n, [label IN labels(n) WHERE label IN [{}]][0] as node_type
507514
WHERE node_type IS NOT NULL
508-
RETURN node_type, n.name as name, n.file as file".to_string();
515+
RETURN node_type, n.name as name, n.file as file",
516+
labels_list
517+
);
509518

510519
(query, params)
511520
}

0 commit comments

Comments
 (0)