Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add suggestion application logic

Akshay dfcdaf91 e8f5ed3a

+22
+22
lib/src/lib.rs
··· 49 49 .flat_map(|d| Some(d.suggestion.as_ref()?.at)) 50 50 .reduce(|acc, next| acc.cover(next)) 51 51 } 52 + /// Unsafe but handy replacement for above 53 + pub fn range(&self) -> TextRange { 54 + self.total_suggestion_range().unwrap() 55 + } 56 + /// Apply all diagnostics. Assumption: diagnostics do not overlap 57 + pub fn apply(&self, src: &mut String) { 58 + for d in self.diagnostics.iter() { 59 + d.apply(src); 60 + } 61 + } 52 62 } 53 63 54 64 /// Mapping from a bytespan to an error message. ··· 77 87 suggestion: Some(suggestion), 78 88 } 79 89 } 90 + /// Apply a diagnostic to a source file 91 + pub fn apply(&self, src: &mut String) { 92 + if let Some(s) = &self.suggestion { 93 + s.apply(src); 94 + } 95 + } 80 96 } 81 97 82 98 /// Suggested fix for a diagnostic, the fix is provided as a syntax element. ··· 94 110 at, 95 111 fix: fix.into(), 96 112 } 113 + } 114 + /// Apply a suggestion to a source file 115 + pub fn apply(&self, src: &mut String) { 116 + let start = usize::from(self.at.start()); 117 + let end = usize::from(self.at.end()); 118 + src.replace_range(start..end, &self.fix.to_string()) 97 119 } 98 120 } 99 121