From 03488bbcacab7a097837d83425f4efcdc70fe12c Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 9 Jan 2025 18:20:01 +0100 Subject: [PATCH] [Diff] Improve conflict markers This commit... 1. adds more detailed scopes to conflict markers 2. adds conflicting blocks to symbol list 3. removes some multi-push and lookaheads 4. adds support for indented fenced diff code blocks (allow markers to be preceded by whitespace) --- Diff/Diff.sublime-syntax | 75 ++++++++++------------ Diff/Symbol List - Conflicts.tmPreferences | 18 ++++++ Diff/tests/syntax_test_diff.diff | 22 +++---- Diff/tests/syntax_test_diff.md | 25 ++++++++ 4 files changed, 87 insertions(+), 53 deletions(-) create mode 100644 Diff/Symbol List - Conflicts.tmPreferences create mode 100644 Diff/tests/syntax_test_diff.md diff --git a/Diff/Diff.sublime-syntax b/Diff/Diff.sublime-syntax index ea3a8e190d..d2c1e2603c 100644 --- a/Diff/Diff.sublime-syntax +++ b/Diff/Diff.sublime-syntax @@ -245,63 +245,54 @@ contexts: # Utility context for other files to use conflict-markers: - - match: ^({{conflict_any}})\s*({{conflict_identifier}})\s*{{eol}} + - match: ^({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^({{conflict_base}}|{{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.separator.diff captures: 1: punctuation.section.block.diff 2: entity.name.section.diff conflicts: - - match: ^(?={{conflict_begin}}) - push: - - conflict - - conflict-marker-start - - conflict: - - meta_scope: meta.block.conflict.diff - - match: '' - pop: 1 - - conflict-marker-start: - - match: '{{conflict_begin}}' - scope: punctuation.section.block.begin.diff - - match: (?:({{conflict_identifier}})\s*)?{{eol}} + - match: ^\s*({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.begin.diff captures: - 1: entity.name.section.diff - set: conflict-deleted-lines + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + push: conflict-deleted-lines - conflict-base-marker-start: - - match: '{{conflict_base}}' - scope: punctuation.section.block.diff - - match: (?:({{conflict_identifier}})\s*)?{{eol}} + conflict-deleted-lines: + - meta_content_scope: meta.block.conflict.diff markup.deleted.diff + - match: ^\s*({{conflict_base}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.separator.diff captures: - 1: entity.name.section.diff + 1: punctuation.section.block.diff + 2: entity.name.section.diff set: conflict-base-lines + - include: conflict-base-lines - conflict-split-marker-start: - - match: '{{conflict_split}}' - scope: punctuation.section.block.diff - - match: (?:({{conflict_identifier}})\s*)?{{eol}} + conflict-base-lines: + - meta_content_scope: meta.block.conflict.diff comment.block.diff + - match: ^\s*({{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.separator.diff captures: - 1: entity.name.section.diff + 1: punctuation.section.block.diff + 2: entity.name.section.diff set: conflict-new-lines - - conflict-deleted-lines: - - meta_content_scope: markup.deleted.diff - - match: ^(?={{conflict_base}}) - set: conflict-base-marker-start - - match: ^(?={{conflict_split}}) - set: conflict-split-marker-start - - include: invalid-conflict-marker - - conflict-base-lines: - - meta_content_scope: comment.block.diff - - match: ^(?={{conflict_split}}) - set: conflict-split-marker-start - include: invalid-conflict-marker conflict-new-lines: - - meta_content_scope: markup.inserted.diff - - match: ^({{conflict_end}})\s*(?:({{conflict_identifier}})\s*)?{{eol}} + - meta_content_scope: meta.block.conflict.diff markup.inserted.diff + - match: ^\s*({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}} + scope: meta.block.conflict.end.diff captures: 1: punctuation.section.block.end.diff 2: entity.name.section.diff diff --git a/Diff/Symbol List - Conflicts.tmPreferences b/Diff/Symbol List - Conflicts.tmPreferences new file mode 100644 index 0000000000..69593880da --- /dev/null +++ b/Diff/Symbol List - Conflicts.tmPreferences @@ -0,0 +1,18 @@ + + + + scope + meta.block.conflict.begin.diff entity.name.section + settings + + showInSymbolList + 1 + symbolTransformation + s/^/Conflict: / + showInIndexedSymbolList + 0 + showInIndexedReferenceList + 0 + + + diff --git a/Diff/tests/syntax_test_diff.diff b/Diff/tests/syntax_test_diff.diff index 582560a4f3..1147da7032 100644 --- a/Diff/tests/syntax_test_diff.diff +++ b/Diff/tests/syntax_test_diff.diff @@ -407,7 +407,7 @@ Index: added-file https://www.gnu.org/software/diffutils/manual/diffutils.html#Marking-Conflicts-1 <<<<<<< A -\^^^^^^^^^ meta.block.conflict.diff - meta.block meta.block - markup +\^^^^^^^^^ meta.block.conflict.begin.diff - meta.block meta.block - markup \^^^^^^ punctuation.section.block.begin.diff \ ^ - entity - punctuation \ ^ entity.name.section.diff @@ -415,12 +415,12 @@ https://www.gnu.org/software/diffutils/manual/diffutils.html#Marking-Conflicts-1 lines from A \^^^^^^^^^^^^ meta.block.conflict.diff markup.deleted.diff - meta.block meta.block ======= -\^^^^^^^ meta.block.conflict.diff - meta.block meta.block - markup +\^^^^^^^ meta.block.conflict.separator.diff - meta.block meta.block - markup \^^^^^^ punctuation.section.block.diff lines from B \^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff >>>>>>> B -\^^^^^^^^^ meta.block.conflict.diff - meta.block meta.block - markup +\^^^^^^^^^ meta.block.conflict.end.diff - meta.block meta.block - markup \^^^^^^ punctuation.section.block.end.diff \ ^ - entity \ ^ entity.name.section.diff @@ -431,7 +431,7 @@ context context <<<<<<< A lines from A ||||||| B -\^^^^^^^^^ meta.block.conflict.diff - meta.block meta.block - markup +\^^^^^^^^^ meta.block.conflict.separator.diff - meta.block meta.block - markup \^^^^^^ punctuation.section.block.diff \ ^ - entity - punctuation \ ^ entity.name.section.diff @@ -439,7 +439,7 @@ lines from A lines from B \^^^^^^^^^^^^ meta.block.conflict.diff comment.block.diff - meta.block meta.block - markup ======= -\^^^^^^ meta.block.conflict.diff punctuation.section.block.diff - meta.block meta.block - markup +\^^^^^^ meta.block.conflict.separator.diff punctuation.section.block.diff - meta.block meta.block - markup > \ <- meta.block.conflict.diff markup.inserted.diff - punctuation - invalid < @@ -536,30 +536,30 @@ hello() \ https://git-scm.com/docs/rerere.html#_nested_conflicts <<<<<<< HEAD -\^^^^^^^^^^^^ meta.block.conflict.diff +\^^^^^^^^^^^^ meta.block.conflict.begin.diff \^^^^^^ punctuation.section.block.begin.diff \ ^^^^ entity.name.section.diff 111 \^^ meta.block.conflict.diff markup.deleted.diff ======= -\^^^^^^^ meta.block.conflict.diff +\^^^^^^^ meta.block.conflict.separator.diff \^^^^^^ punctuation.section.block.diff <<<<<<< HEAD -\^^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict.diff +\^^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict.begin.diff \^^^^^^ punctuation.section.block.begin.diff \ ^^^^ entity.name.section.diff 333 \^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict.diff markup.deleted.diff ======= -\^^^^^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict punctuation.section.block.diff +\^^^^^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict.separator.diff punctuation.section.block.diff 222 \^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict markup.inserted.diff >>>>>>> branch-2 -\^^^^^^^^^^^^^^^ meta.block.conflict markup.inserted.diff meta.block.conflict.diff +\^^^^^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff meta.block.conflict.end.diff \^^^^^^ punctuation.section.block.end.diff \ ^^^^^^^^ entity.name.section.diff >>>>>>> branch-3~ -\^^^^^^^^^^^^^^^^ meta.block.conflict.diff +\^^^^^^^^^^^^^^^^ meta.block.conflict.end.diff \^^^^^^ punctuation.section.block.end.diff \ ^^^^^^^^^ entity.name.section.diff diff --git a/Diff/tests/syntax_test_diff.md b/Diff/tests/syntax_test_diff.md new file mode 100644 index 0000000000..6427ced6b0 --- /dev/null +++ b/Diff/tests/syntax_test_diff.md @@ -0,0 +1,25 @@ +\ SYNTAX TEST "Packages/Diff/Diff.sublime-syntax" + +1. list item with diff fenced code block + + ```diff + <<<<<<< A + \^^^^^^^^^ meta.block.conflict.begin.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.begin.diff + \ ^ - entity - punctuation + \ ^ entity.name.section.diff + \ ^ - entity + lines from A + \^^^^^^^^^^^^ meta.block.conflict.diff markup.deleted.diff - meta.block meta.block + ======= + \^^^^^^^ meta.block.conflict.separator.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.diff + lines from B + \^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff + >>>>>>> B + \^^^^^^^^^ meta.block.conflict.end.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.end.diff + \ ^ - entity + \ ^ entity.name.section.diff + \ ^ - entity + ```