summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2023-01-23 08:35:55 -0800
committerWilfred Hughes <me@wilfred.me.uk>2023-01-24 21:46:35 -0800
commit45113af15c45b7c08c105844f7521f6c343123e3 (patch)
tree11a8d86e4381b8e15b370521d069d0fea5cabedb
parent3c4ee1dd2f383d05e88c95ba447bcca00a5a9255 (diff)
WIP UnchangedSyntaxLinemerge_comment_blocks
-rw-r--r--src/diff/changes.rs2
-rw-r--r--src/diff/graph.rs16
-rw-r--r--src/parse/syntax.rs22
-rw-r--r--src/parse/tree_sitter_parser.rs2
4 files changed, 40 insertions, 2 deletions
diff --git a/src/diff/changes.rs b/src/diff/changes.rs
index 5844b9c77..07623a986 100644
--- a/src/diff/changes.rs
+++ b/src/diff/changes.rs
@@ -4,7 +4,7 @@ use std::num::NonZeroU32;
use rustc_hash::FxHashMap;
-use crate::parse::syntax::Syntax;
+use crate::{parse::syntax::Syntax};
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum ChangeKind<'a> {
diff --git a/src/diff/graph.rs b/src/diff/graph.rs
index d17209ccb..b43ff49d5 100644
--- a/src/diff/graph.rs
+++ b/src/diff/graph.rs
@@ -802,6 +802,22 @@ pub fn populate_change_map<'a, 'b>(
let lhs = v.lhs_syntax.unwrap();
let rhs = v.rhs_syntax.unwrap();
+ let lhs_content = match lhs {
+ Syntax::List { .. } => todo!(),
+ Syntax::Atom { content, .. } => content,
+ };
+ let rhs_content = match rhs {
+ Syntax::List { .. } => todo!(),
+ Syntax::Atom { content, .. } => content,
+ };
+
+ for (lhs_line, rhs_line) in lhs_content.lines().zip(rhs_content.lines()) {
+ if lhs_line == rhs_line {
+ } else {
+ break;
+ }
+ }
+
if *levenshtein_pct > 40 {
change_map.insert(lhs, ChangeKind::ReplacedComment(lhs, rhs));
change_map.insert(rhs, ChangeKind::ReplacedComment(rhs, lhs));
diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs
index 4460083dc..b42ae8bfe 100644
--- a/src/parse/syntax.rs
+++ b/src/parse/syntax.rs
@@ -709,6 +709,11 @@ pub enum MatchKind {
self_pos: Vec<SingleLineSpan>,
opposite_pos: Vec<SingleLineSpan>,
},
+ UnchangedSyntaxLine {
+ highlight: TokenKind,
+ self_pos: SingleLineSpan,
+ opposite_pos: SingleLineSpan,
+ },
Novel {
highlight: TokenKind,
},
@@ -854,6 +859,23 @@ impl MatchedPos {
} => (content, position),
};
+ let mut res = vec![];
+ for (lhs_line, rhs_line) in this_content.lines().zip(opposite_content.lines()) {
+ if lhs_line == rhs_line {
+ let kind = MatchKind::UnchangedSyntaxLine {
+ highlight,
+ self_pos: pos.to_vec(),
+ opposite_pos,
+ };
+ } else {
+ break;
+ }
+ }
+
+ if res.len() > 0 {
+ return res;
+ }
+
split_comment_words(
this_content,
// TODO: handle the whole pos here.
diff --git a/src/parse/tree_sitter_parser.rs b/src/parse/tree_sitter_parser.rs
index 8cd628f3b..2cc375bd8 100644
--- a/src/parse/tree_sitter_parser.rs
+++ b/src/parse/tree_sitter_parser.rs
@@ -13,8 +13,8 @@ use crate::{
};
use super::syntax;
-use super::syntax::MatchedPos;
use super::syntax::merge_adjacent_comments;
+use super::syntax::MatchedPos;
/// A language may contain certain nodes that are in other languages
/// and should be parsed as such (e.g. HTML <script> nodes containing