WIP: allow using nff as a diagnostics source #1
					 1 changed files with 17 additions and 20 deletions
				
			
		diagnostics: reduce complexity of redundant rule checks
				commit
				
					
					
						9791296634
					
				
			
		|  | @ -1000,7 +1000,7 @@ impl SemanticAnalyzer { | ||||||
| 
 | 
 | ||||||
|     fn check_for_redundant_rules(&self, source: &str) -> Vec<Diagnostic> { |     fn check_for_redundant_rules(&self, source: &str) -> Vec<Diagnostic> { | ||||||
|         let mut diagnostics = Vec::new(); |         let mut diagnostics = Vec::new(); | ||||||
|         let mut rules = Vec::new(); |         let mut seen_rules = HashSet::new(); | ||||||
| 
 | 
 | ||||||
|         for (line_idx, line) in source.lines().enumerate() { |         for (line_idx, line) in source.lines().enumerate() { | ||||||
|             let line_num = line_idx as u32; |             let line_num = line_idx as u32; | ||||||
|  | @ -1011,26 +1011,23 @@ impl SemanticAnalyzer { | ||||||
|                 || trimmed.contains(" drop") |                 || trimmed.contains(" drop") | ||||||
|                 || trimmed.contains(" reject") |                 || trimmed.contains(" reject") | ||||||
|             { |             { | ||||||
|                 for (existing_idx, existing_rule) in rules.iter().enumerate() { |                 // Check if rule already exists in the HashSet
 | ||||||
|                     if existing_rule == &trimmed { |                 if seen_rules.contains(trimmed) { | ||||||
|                         let range = Range::new( |                     let range = Range::new( | ||||||
|                             Position::new(line_num, 0), |                         Position::new(line_num, 0), | ||||||
|                             Position::new(line_num, line.len() as u32), |                         Position::new(line_num, line.len() as u32), | ||||||
|                         ); |                     ); | ||||||
|                         let diagnostic = Diagnostic::new( |                     let diagnostic = Diagnostic::new( | ||||||
|                             range, |                         range, | ||||||
|                             DiagnosticSeverity::Warning, |                         DiagnosticSeverity::Warning, | ||||||
|                             DiagnosticCode::RedundantRule, |                         DiagnosticCode::RedundantRule, | ||||||
|                             format!( |                         "Duplicate rule found".to_string(), | ||||||
|                                 "Duplicate rule found (first occurrence at line {})", |                     ); | ||||||
|                                 existing_idx + 1 |                     diagnostics.push(diagnostic); | ||||||
|                             ), |                 } else { | ||||||
|                         ); |                     // Add the rule to the HashSet if it's not a duplicate
 | ||||||
|                         diagnostics.push(diagnostic); |                     seen_rules.insert(trimmed.to_string()); | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|                 } |                 } | ||||||
|                 rules.push(trimmed.to_string()); |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue