From 13c33f67d365f4d2c6c7fd69112980c6b55bf61a Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 18 Dec 2024 12:03:09 +0100 Subject: [PATCH] [Diff] Hunks and ranges This commit... 1. scopes `,` in ranges `punctuation.separator.range` as numbers before and after denote beginning and end of modified content range, but no sequence of arbitrary numbers. 2. scopes diff3 hunks `meta.hunk` 3. scope whole diff3 change markers `meta.range` to achieve same segmentation as for `@@ ... @@` range markers in unified diffs. 4. add diff3 modifications to toc-list Scope change markers `meta.toc-list`. Exclude eol to correctly separate them in symbol list. --- Diff/Diff.sublime-syntax | 31 +++++++++------ Diff/tests/syntax_test_diff.diff | 67 ++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 20 deletions(-) diff --git a/Diff/Diff.sublime-syntax b/Diff/Diff.sublime-syntax index 11188066ac..1eb3b8371a 100644 --- a/Diff/Diff.sublime-syntax +++ b/Diff/Diff.sublime-syntax @@ -91,7 +91,7 @@ contexts: - match: ( (-) )(.* (={4})){{eol}} captures: 1: meta.header.diff - 2: punctuation.separator.sequence.diff + 2: punctuation.separator.range.diff 3: meta.diff.header.to-file meta.header.to-file.diff 4: punctuation.definition.to-file.diff pop: 1 @@ -130,9 +130,9 @@ contexts: - match: ^\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}} scope: meta.diff.range.normal meta.range.normal.diff captures: - 1: punctuation.separator.sequence.diff + 1: punctuation.separator.range.diff 2: support.function.diff - 3: punctuation.separator.sequence.diff + 3: punctuation.separator.range.diff # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context - match: ^(-){3}(?= .+ -{4}{{eol}}) @@ -177,21 +177,25 @@ contexts: # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal diff3-normal: - - match: ^====[1-3]?{{eol}} - scope: punctuation.section.block.diff + - match: ^====([1-3]?){{eol}} + scope: meta.hunk.diff punctuation.section.hunk.diff + captures: + 1: constant.numeric.from-file.diff - - match: ^([1-3])(:)(\d+(a)|\d+(?:(,)\d+)?(c)){{eol}} - scope: meta.mapping.diff + - match: ^(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}} + scope: meta.diff.range.normal meta.range.normal.diff captures: - 1: meta.mapping.key.diff meta.number.integer.decimal.diff constant.numeric.value.diff - 2: punctuation.separator.key-value.diff - 3: meta.mapping.value.diff meta.diff.range.normal meta.range.normal.diff + 1: meta.toc-list.hunk.diff + 2: constant.numeric.from-file.diff + 3: punctuation.separator.file.diff 4: support.function.diff - 5: punctuation.separator.sequence.diff + 5: punctuation.separator.range.diff 6: support.function.diff push: diff3-normal-change diff3-normal-change: + - meta_scope: meta.hunk.diff + - meta_content_scope: meta.block.diff - match: ^(?:\t| ) push: line-changed - match: ^ @@ -218,18 +222,21 @@ contexts: push: diff3-edit-changed diff3-edit-inserted: + - meta_scope: meta.hunk.diff - meta_content_scope: meta.block.diff markup.inserted.diff - include: diff3-edit-end diff3-edit-deleted: + - meta_scope: meta.hunk.diff - meta_content_scope: meta.block.diff markup.deleted.diff - include: diff3-edit-end diff3-edit-changed: + - meta_scope: meta.hunk.diff - meta_content_scope: meta.block.diff markup.changed.diff - include: diff3-edit-end diff3-edit-end: - match: ^\.$ - scope: punctuation.section.block.end.diff + scope: punctuation.terminator.hunk.diff pop: 1 diff --git a/Diff/tests/syntax_test_diff.diff b/Diff/tests/syntax_test_diff.diff index 51bc99fc42..246f10901f 100644 --- a/Diff/tests/syntax_test_diff.diff +++ b/Diff/tests/syntax_test_diff.diff @@ -115,18 +115,38 @@ Index: lao Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Normal 1,2d0 +\ <- meta.diff.range.normal meta.range.normal.diff +\^^^^ meta.diff.range.normal meta.range.normal.diff +\^ punctuation.separator.range.diff +\ ^ support.function.diff < The Way that can be told of is not the eternal Way; < The name that can be named is not the eternal name. 4c2,3 +\ <- meta.diff.range.normal meta.range.normal.diff +\^^^^ meta.diff.range.normal meta.range.normal.diff +\^ support.function.diff +\ ^ punctuation.separator.range.diff < The Named is the mother of all things. +\ <- markup.deleted.diff punctuation.definition.deleted.diff +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff +\^ punctuation.definition.deleted.diff --- +\ <- meta.separator.diff punctuation.separator.block.diff +\^^ meta.separator.diff punctuation.separator.block.diff > The named is the mother of all things. > \^ - meta.whitespace 11a11,13 +\ <- meta.diff.range.normal meta.range.normal.diff +\^^^^^^^ meta.diff.range.normal meta.range.normal.diff +\ ^ support.function.diff +\ ^ punctuation.separator.range.diff > They both may be called deep and profound. > Deeper and more profound, > The door of all subtleties! +\ <- markup.inserted.diff punctuation.definition.inserted.diff +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff +\^ punctuation.definition.inserted.diff Context Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context @@ -231,12 +251,30 @@ Unified Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Exam Diff3 Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal ====2 +\ <- meta.hunk.diff punctuation.section.hunk.diff +\^^^^^ meta.hunk.diff punctuation.section.hunk.diff +\ ^ constant.numeric.from-file.diff 1:1,2c +\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff +\^^^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff +\^ punctuation.separator.file.diff +\ ^ punctuation.separator.range.diff +\ ^ support.function.diff +\ ^ - meta.toc-list 3:1,2c The Way that can be told of is not the eternal Way; The name that can be named is not the eternal name. +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff 2:0a +\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff +\^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff +\^ punctuation.separator.file.diff +\ ^ support.function.diff +\ ^ - meta.toc-list ====1 +\ <- meta.hunk.diff punctuation.section.hunk.diff +\^^^^^ meta.hunk.diff punctuation.section.hunk.diff +\ ^ constant.numeric.from-file.diff 1:4c The Named is the mother of all things. 2:2,3c @@ -244,12 +282,22 @@ Diff3 Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html The named is the mother of all things. ====3 +\ <- meta.hunk.diff punctuation.section.hunk.diff +\^^^^^ meta.hunk.diff punctuation.section.hunk.diff +\ ^ constant.numeric.from-file.diff 1:8c +\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff +\^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff +\^ punctuation.separator.file.diff +\ ^ support.function.diff +\ ^ - meta.toc-list 2:7c so we may see their outcome. 3:9c so we may see their result. ==== +\ <- meta.hunk.diff punctuation.section.hunk.diff +\^^^^ meta.hunk.diff punctuation.section.hunk.diff 1:11a 2:11,13c They both may be called deep and profound. @@ -258,33 +306,36 @@ Diff3 Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html 3:13,14c -- The Way of Lao-Tzu, tr. Wing-tsit Chan +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff Diff3 Edit Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Selecting-Which-Changes-to-Incorporate 11a -\ <- meta.diff.range.normal meta.range.normal.diff +\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff +\^^^ meta.hunk.diff \^ meta.diff.range.normal meta.range.normal.diff \ ^ support.function.diff -- The Way of Lao-Tzu, tr. Wing-tsit Chan -\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.inserted.diff +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.inserted.diff . -\ <- punctuation.section.block.end.diff +\ <- meta.hunk.diff punctuation.terminator.hunk.diff 8c -\ <- meta.diff.range.normal meta.range.normal.diff +\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff +\^^ meta.hunk.diff \^ support.function.diff so we may see their result. -\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.changed.diff +\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff . -\ <- punctuation.section.block.end.diff +\ <- meta.hunk.diff punctuation.terminator.hunk.diff 24d \ <- meta.diff.range.normal meta.range.normal.diff \^ meta.diff.range.normal meta.range.normal.diff \ ^ support.function.diff This is removed content -\^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.deleted.diff +\^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.deleted.diff . -\ <- punctuation.section.block.end.diff +\ <- meta.hunk.diff punctuation.terminator.hunk.diff SVN sample https://svnbook.red-bean.com/en/1.7/svn-book.html#idm10685