Skip to content

Commit

Permalink
[Diff] Improve conflict markers
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
deathaxe committed Jan 9, 2025
1 parent 4ee85d3 commit 03488bb
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 53 deletions.
75 changes: 33 additions & 42 deletions Diff/Diff.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions Diff/Symbol List - Conflicts.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>meta.block.conflict.begin.diff entity.name.section</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
<key>symbolTransformation</key>
<string>s/^/Conflict: /</string>
<key>showInIndexedSymbolList</key>
<integer>0</integer>
<key>showInIndexedReferenceList</key>
<integer>0</integer>
</dict>
</dict>
</plist>
22 changes: 11 additions & 11 deletions Diff/tests/syntax_test_diff.diff
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,20 @@ 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
\ ^ - entity
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
Expand All @@ -431,15 +431,15 @@ 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
\ ^ - entity
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
<
Expand Down Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions Diff/tests/syntax_test_diff.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 03488bb

Please sign in to comment.