Use underline suggestions for purely 'additive' replacements
This commit is contained in:
committed by
Jubilee Young
parent
6dfeab5c9e
commit
b480a9214a
@@ -230,6 +230,17 @@ impl SubstitutionPart {
|
||||
!self.snippet.is_empty() && self.replaces_meaningful_content(sm)
|
||||
}
|
||||
|
||||
/// Whether this is a replacement that overwrites source with a snippet
|
||||
/// in a way that isn't a superset of the original string. For example,
|
||||
/// replacing "abc" with "abcde" is not destructive, but replacing it
|
||||
/// it with "abx" is, since the "c" character is lost.
|
||||
pub fn is_destructive_replacement(&self, sm: &SourceMap) -> bool {
|
||||
self.is_replacement(sm)
|
||||
&& !sm
|
||||
.span_to_snippet(self.span)
|
||||
.is_ok_and(|snippet| self.snippet.trim_start().starts_with(snippet.trim_start()))
|
||||
}
|
||||
|
||||
fn replaces_meaningful_content(&self, sm: &SourceMap) -> bool {
|
||||
sm.span_to_snippet(self.span)
|
||||
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
|
||||
|
||||
Reference in New Issue
Block a user