@@ -108,19 +108,34 @@ fn parse_meta_filter(s: &str) -> BTreeMap<String, String> {
108108 map
109109}
110110
111+ fn strip_mode_annotation < ' a > (
112+ trimmed : & ' a str ,
113+ prefix : & str ,
114+ keyword : & str ,
115+ use_lsp : bool ,
116+ ) -> Option < & ' a str > {
117+ let common_prefix = format ! ( "{}{}: " , prefix, keyword) ;
118+ if let Some ( rest) = trimmed. strip_prefix ( common_prefix. as_str ( ) ) {
119+ return Some ( rest) ;
120+ }
121+
122+ let mode = if use_lsp { "lsp" } else { "no_lsp" } ;
123+ let mode_prefix = format ! ( "{}{}_{}: " , prefix, keyword, mode) ;
124+ trimmed. strip_prefix ( mode_prefix. as_str ( ) )
125+ }
126+
111127#[ derive( Debug , Clone ) ]
112128struct AbsentAnnotation {
113129 node_type : NodeType ,
114130 name : String ,
115131 file_suffix : String ,
116132}
117133
118- fn parse_absent_annotations ( source : & str , prefix : & str ) -> Vec < AbsentAnnotation > {
119- let absent_prefix = format ! ( "{}absent: " , prefix) ;
134+ fn parse_absent_annotations ( source : & str , prefix : & str , use_lsp : bool ) -> Vec < AbsentAnnotation > {
120135 let mut result = Vec :: new ( ) ;
121136 for line in source. lines ( ) {
122137 let trimmed = line. trim ( ) ;
123- if let Some ( rest) = trimmed . strip_prefix ( absent_prefix . as_str ( ) ) {
138+ if let Some ( rest) = strip_mode_annotation ( trimmed , prefix , "absent" , use_lsp ) {
124139 let toks = parse_quoted_tokens ( rest) ;
125140 if toks. len ( ) >= 3 {
126141 if let Some ( nt) = parse_node_type ( & toks[ 0 ] ) {
@@ -139,15 +154,16 @@ fn parse_absent_annotations(source: &str, prefix: &str) -> Vec<AbsentAnnotation>
139154fn parse_file_annotations (
140155 source : & str ,
141156 prefix : & str ,
157+ use_lsp : bool ,
142158) -> Vec < ( NodeType , String , BTreeMap < String , String > , Vec < EdgeAnnotation > ) > {
143159 let mut result = Vec :: new ( ) ;
144160 let mut current: Option < ( NodeType , String , BTreeMap < String , String > , Vec < EdgeAnnotation > ) > =
145161 None ;
146162
147163 for line in source. lines ( ) {
148164 let trimmed = line. trim ( ) ;
149- if let Some ( rest ) = trimmed. strip_prefix ( prefix) {
150- if let Some ( node_rest) = rest . strip_prefix ( "node: " ) {
165+ if trimmed. strip_prefix ( prefix) . is_some ( ) {
166+ if let Some ( node_rest) = strip_mode_annotation ( trimmed , prefix , "node" , use_lsp ) {
151167 if let Some ( prev) = current. take ( ) {
152168 result. push ( prev) ;
153169 }
@@ -158,7 +174,7 @@ fn parse_file_annotations(
158174 current = Some ( ( nt, toks[ 1 ] . clone ( ) , subject_meta, Vec :: new ( ) ) ) ;
159175 }
160176 }
161- } else if let Some ( edge_rest) = rest . strip_prefix ( "edge: " ) {
177+ } else if let Some ( edge_rest) = strip_mode_annotation ( trimmed , prefix , "edge" , use_lsp ) {
162178 if let Some ( ( _, _, _, ref mut edges) ) = current {
163179 let toks = parse_quoted_tokens ( edge_rest) ;
164180 if toks. len ( ) >= 5 {
@@ -199,9 +215,9 @@ fn annotation_prefix_for_ext(ext: &str, default: &'static str) -> &'static str {
199215 }
200216}
201217
202- pub fn verify_file ( source : & str , file_suffix : & str , graph : & impl Graph , prefix : & str ) -> ( Vec < String > , BTreeMap < NodeType , usize > ) {
203- let groups = parse_file_annotations ( source, prefix) ;
204- let absent = parse_absent_annotations ( source, prefix) ;
218+ pub fn verify_file ( source : & str , file_suffix : & str , graph : & impl Graph , prefix : & str , use_lsp : bool ) -> ( Vec < String > , BTreeMap < NodeType , usize > ) {
219+ let groups = parse_file_annotations ( source, prefix, use_lsp ) ;
220+ let absent = parse_absent_annotations ( source, prefix, use_lsp ) ;
205221 let mut failures: Vec < String > = Vec :: new ( ) ;
206222 let mut counts: BTreeMap < NodeType , usize > = BTreeMap :: new ( ) ;
207223
@@ -296,12 +312,12 @@ pub fn verify_file(source: &str, file_suffix: &str, graph: &impl Graph, prefix:
296312 ( failures, counts)
297313}
298314
299- pub fn walk_and_verify ( fixture_dir : & Path , root : & Path , graph : & impl Graph , lang : & Language ) -> Vec < String > {
315+ pub fn walk_and_verify ( fixture_dir : & Path , root : & Path , graph : & impl Graph , lang : & Language , use_lsp : bool ) -> Vec < String > {
300316 let mut failures = Vec :: new ( ) ;
301317 let mut counts: BTreeMap < NodeType , usize > = BTreeMap :: new ( ) ;
302318 let exts: Vec < & str > = lang. exts ( ) ;
303319 let skip_dirs: Vec < & str > = lang. skip_dirs ( ) ;
304- walk_impl ( fixture_dir, root, graph, & mut failures, & mut counts, & exts, & skip_dirs, lang) ;
320+ walk_impl ( fixture_dir, root, graph, & mut failures, & mut counts, & exts, & skip_dirs, lang, use_lsp ) ;
305321 for ( node_type, expected) in & counts {
306322 let actual = graph
307323 . find_nodes_by_type ( node_type. clone ( ) )
@@ -327,6 +343,7 @@ fn walk_impl(
327343 exts : & [ & str ] ,
328344 skip_dirs : & [ & str ] ,
329345 lang : & Language ,
346+ use_lsp : bool ,
330347) {
331348 let Ok ( read) = std:: fs:: read_dir ( dir) else {
332349 return ;
@@ -341,7 +358,7 @@ fn walk_impl(
341358 if skip_dirs. contains ( & dir_name) {
342359 continue ;
343360 }
344- walk_impl ( & path, root, graph, failures, counts, exts, skip_dirs, lang) ;
361+ walk_impl ( & path, root, graph, failures, counts, exts, skip_dirs, lang, use_lsp ) ;
345362 } else {
346363 let ext = path. extension ( ) . and_then ( |e| e. to_str ( ) ) . unwrap_or ( "" ) ;
347364 if !exts. contains ( & ext) {
@@ -358,7 +375,7 @@ fn walk_impl(
358375 . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
359376 . unwrap_or_else ( |_| path. to_string_lossy ( ) . to_string ( ) ) ;
360377 let file_prefix = annotation_prefix_for_ext ( ext, lang. annotation_prefix ( ) ) ;
361- let ( file_failures, file_counts) = verify_file ( & src, & suffix, graph, file_prefix) ;
378+ let ( file_failures, file_counts) = verify_file ( & src, & suffix, graph, file_prefix, use_lsp ) ;
362379 failures. extend ( file_failures) ;
363380 for ( nt, n) in file_counts {
364381 * counts. entry ( nt) . or_insert ( 0 ) += n;
@@ -371,11 +388,20 @@ pub async fn run_fixture_test<G: Graph + Sync>(
371388 subdir : & str ,
372389 lang : & str ,
373390 annotation_lang : Language ,
391+ ) -> Result < ( ) > {
392+ run_fixture_test_with_lsp :: < G > ( subdir, lang, annotation_lang, false ) . await
393+ }
394+
395+ pub async fn run_fixture_test_with_lsp < G : Graph + Sync > (
396+ subdir : & str ,
397+ lang : & str ,
398+ annotation_lang : Language ,
399+ use_lsp : bool ,
374400) -> Result < ( ) > {
375401 let repo = Repo :: new (
376402 subdir,
377403 Lang :: from_str ( lang) . unwrap ( ) ,
378- false ,
404+ use_lsp ,
379405 Vec :: new ( ) ,
380406 Vec :: new ( ) ,
381407 )
@@ -385,7 +411,7 @@ pub async fn run_fixture_test<G: Graph + Sync>(
385411 graph. analysis ( ) ;
386412 let fixture_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( subdir) ;
387413 let root = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
388- let failures = walk_and_verify ( & fixture_dir, root, & graph, & annotation_lang) ;
414+ let failures = walk_and_verify ( & fixture_dir, root, & graph, & annotation_lang, use_lsp ) ;
389415 if !failures. is_empty ( ) {
390416 for f in & failures {
391417 eprintln ! ( "{}" , f) ;
0 commit comments