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> { | ||||
|         let mut diagnostics = Vec::new(); | ||||
|         let mut rules = Vec::new(); | ||||
|         let mut seen_rules = HashSet::new(); | ||||
| 
 | ||||
|         for (line_idx, line) in source.lines().enumerate() { | ||||
|             let line_num = line_idx as u32; | ||||
|  | @ -1011,8 +1011,8 @@ impl SemanticAnalyzer { | |||
|                 || trimmed.contains(" drop") | ||||
|                 || trimmed.contains(" reject") | ||||
|             { | ||||
|                 for (existing_idx, existing_rule) in rules.iter().enumerate() { | ||||
|                     if existing_rule == &trimmed { | ||||
|                 // Check if rule already exists in the HashSet
 | ||||
|                 if seen_rules.contains(trimmed) { | ||||
|                     let range = Range::new( | ||||
|                         Position::new(line_num, 0), | ||||
|                         Position::new(line_num, line.len() as u32), | ||||
|  | @ -1021,17 +1021,14 @@ impl SemanticAnalyzer { | |||
|                         range, | ||||
|                         DiagnosticSeverity::Warning, | ||||
|                         DiagnosticCode::RedundantRule, | ||||
|                             format!( | ||||
|                                 "Duplicate rule found (first occurrence at line {})", | ||||
|                                 existing_idx + 1 | ||||
|                             ), | ||||
|                         "Duplicate rule found".to_string(), | ||||
|                     ); | ||||
|                     diagnostics.push(diagnostic); | ||||
|                         break; | ||||
|                 } else { | ||||
|                     // Add the rule to the HashSet if it's not a duplicate
 | ||||
|                     seen_rules.insert(trimmed.to_string()); | ||||
|                 } | ||||
|             } | ||||
|                 rules.push(trimmed.to_string()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         diagnostics | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue