diff --git a/src/display/context.rs b/src/display/context.rs index 74148758e7..b8472e2fb9 100644 --- a/src/display/context.rs +++ b/src/display/context.rs @@ -143,7 +143,7 @@ fn matched_lines_from_unchanged( for mp in mps { let opposite_line = match &mp.kind { MatchKind::UnchangedToken { opposite_pos, .. } - | MatchKind::NovelLinePart { opposite_pos, .. } => { + | MatchKind::UnchangedPartOfNovelItem { opposite_pos, .. } => { if let Some(highest_opposite_side) = highest_opposite_line { opposite_pos .iter() @@ -344,7 +344,7 @@ pub(crate) fn opposite_positions( opposite_lines.insert(opposite_span.line); } } - MatchKind::NovelLinePart { + MatchKind::UnchangedPartOfNovelItem { opposite_pos, self_pos, .. @@ -837,7 +837,7 @@ mod tests { fn test_all_lines() { let mps = [ MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Delimiter, self_pos: SingleLineSpan { line: 0.into(), diff --git a/src/display/json.rs b/src/display/json.rs index 2dc867dee1..f0a10498c8 100644 --- a/src/display/json.rs +++ b/src/display/json.rs @@ -255,7 +255,7 @@ impl Highlight { MatchKind::UnchangedToken { highlight, .. } => highlight, MatchKind::Novel { highlight, .. } => highlight, MatchKind::NovelWord { highlight, .. } => highlight, - MatchKind::NovelLinePart { highlight, .. } => highlight, + MatchKind::UnchangedPartOfNovelItem { highlight, .. } => highlight, }; match highlight { diff --git a/src/display/style.rs b/src/display/style.rs index 7beb5d3fef..8f31db145d 100644 --- a/src/display/style.rs +++ b/src/display/style.rs @@ -393,7 +393,7 @@ pub(crate) fn color_positions( style = style.italic(); } } - MatchKind::NovelLinePart { highlight, .. } => { + MatchKind::UnchangedPartOfNovelItem { highlight, .. } => { style = novel_style(style, side, background); if syntax_highlight && matches!(highlight, TokenKind::Atom(AtomKind::Comment)) { style = style.italic(); diff --git a/src/line_parser.rs b/src/line_parser.rs index f2ed5cd335..b546294a7e 100644 --- a/src/line_parser.rs +++ b/src/line_parser.rs @@ -192,7 +192,7 @@ pub(crate) fn change_positions(lhs_src: &str, rhs_src: &str) -> Vec rhs_lp.from_region(rhs_offset, rhs_offset + rhs_word.len()); mps.push(MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Normal), self_pos: lhs_pos[0], opposite_pos: rhs_pos, diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index 1f08333457..ab2cafcc6a 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -598,15 +598,33 @@ pub(crate) enum MatchKind { }, /// A novel token in an AST diff. Novel { highlight: TokenKind }, - /// When doing a textual line-based diff, the part of a novel line - /// that exists on both sides. - NovelLinePart { + /// When we have a novel item, we often want to highlight novel + /// words more prominently. UnchangedPartOfNovelItem represents + /// the parts that don't get this special highlighting. + /// + /// For example, line-based diffs we want to highlight `a` and `b` + /// differently to `foo` here. + /// + /// foo a + /// foo b + /// + /// Whereas for syntactic diffs, we want to do the same thing for + /// strings and comments. + /// + /// "foo a" + /// "foo b" + /// + /// The whole string is a distinct value, but the `a` and `b` are + /// the most interesting parts. + UnchangedPartOfNovelItem { highlight: TokenKind, self_pos: SingleLineSpan, opposite_pos: Vec, }, - /// When doing a textual line-based diff, the part of a novel line - /// that is actually novel. E.g. the newly added word on a line. + /// The novel part of the novel item. For line-based diffs, this + /// is the words that are unique to this line. + /// + /// See the discussion in `UnchangedPartOfNovelItem`. NovelWord { highlight: TokenKind }, /// A syntactic token that was ignored by the AST diff (e.g. when /// ignoring comments for diffing). @@ -617,7 +635,9 @@ impl MatchKind { pub(crate) fn is_novel(&self) -> bool { matches!( self, - MatchKind::Novel { .. } | MatchKind::NovelWord { .. } | MatchKind::NovelLinePart { .. } + MatchKind::Novel { .. } + | MatchKind::NovelWord { .. } + | MatchKind::UnchangedPartOfNovelItem { .. } ) } } @@ -700,7 +720,7 @@ fn split_atom_words( ); mps.push(MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(kind), self_pos: word_pos, opposite_pos: opposite_word_pos, @@ -1184,7 +1204,7 @@ mod tests { res, vec![ MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Comment), self_pos: SingleLineSpan { line: 0.into(), @@ -1204,7 +1224,7 @@ mod tests { } }, MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Comment), self_pos: SingleLineSpan { line: 0.into(), @@ -1224,7 +1244,7 @@ mod tests { } }, MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Comment), self_pos: SingleLineSpan { line: 0.into(), @@ -1244,7 +1264,7 @@ mod tests { } }, MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Comment), self_pos: SingleLineSpan { line: 0.into(), @@ -1264,7 +1284,7 @@ mod tests { } }, MatchedPos { - kind: MatchKind::NovelLinePart { + kind: MatchKind::UnchangedPartOfNovelItem { highlight: TokenKind::Atom(AtomKind::Comment), self_pos: SingleLineSpan { line: 0.into(),