Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Git Formats] highlight diffs in Git Log syntax for git show #2989

Merged
merged 9 commits into from
Aug 29, 2021
27 changes: 15 additions & 12 deletions Git Formats/Git Link.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,50 @@ contexts:
- meta_scope: meta.mapping.git.link
- match: ':'
scope: punctuation.separator.mapping.key-value.git.link
set: expect-path
set: [mapping-value-meta, expect-path]
- match: \n
pop: true

expect-path:
- meta_content_scope: meta.mapping.value.git.link
- match: (?=\S) # path starts with the first none space character
- match: (?=\S) # path starts with the first non-space character
set: [path, path-start]
- match: \n
pop: true

mapping-value-meta:
- meta_content_scope: meta.mapping.value.git.link
- match: ''
pop: true

path:
- meta_content_scope: meta.mapping.value.git.link meta.path.git.link string.unquoted.git.link
- match: \.?\n
scope: meta.mapping.value.git.link punctuation.terminator.path.git.link
- meta_content_scope: meta.path.git string.unquoted.git
- match: $
pop: true
- match: '[\\/]'
scope: punctuation.separator.path.git.link
scope: punctuation.separator.path.git
push: path-dir-pattern
- match: '[*?]'
scope: invalid.illegal.path.git.link
scope: invalid.illegal.path.git

path-start:
# windows drive letter and separator
- match: '[A-Za-z](:)(?=[\\/])'
captures:
1: punctuation.separator.drive.git.link
1: punctuation.separator.drive.git
pop: true
# homedir tilde operator
- match: ~(?=/)
scope: variable.language.environment.home.git.link
scope: variable.language.environment.home.git
pop: true
# any other directory pattern
- include: path-dir-pattern

path-dir-pattern:
- match: \.\.(?=[\\/])
scope: constant.language.path.parent.git.link
scope: constant.language.path.parent.git
pop: true
- match: \.(?=[\\/])
scope: constant.language.path.self.git.link
scope: constant.language.path.self.git
pop: true
- match: ''
pop: true
62 changes: 58 additions & 4 deletions Git Formats/Git Log.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
---
name: Git Log
file_extensions:
- gitlog # no real extention but why not?
- gitlog # no real extension but why not?
first_line_match: ^commit\s+\h{7,}
scope: text.git.log
variables:
diff_begin: ^diff\s+--git\s
commit_begin: ^(commit)\s+(\h{7,})
commit_or_diff_begin: (?={{diff_begin}}|{{commit_begin}})

contexts:
prototype:
Expand All @@ -13,7 +17,7 @@ contexts:
main:
# 1st header line
# commit d9d9fb804f5d61c13ba2f8746af33a9f3c609075
- match: ^(commit)\s+(\h{7,})
- match: '{{commit_begin}}'
captures:
1: keyword.other.commit.git.log
2: constant.other.hash.git.log
Expand All @@ -23,7 +27,7 @@ contexts:
scope: meta.header.git.commit markup.raw.block.git.log
pop: true
embed: commit-header
escape: (?=^commit\s)
escape: '{{commit_or_diff_begin}}'
- match: (\()(HEAD)\s*(->)
captures:
1: punctuation.section.parens.begin.git.log
Expand All @@ -33,12 +37,17 @@ contexts:
- match: \)
scope: punctuation.section.parens.end.git.log
pop: true
- match: \bmaster\b
- match: \b(?:master|main)\b
scope: entity.other.branch-name.master.git.log
- match: (\w+)(?:(/)(\w+))?
scope: entity.other.branch-name.git.log
- match: ','
scope: punctuation.separator.sequence.git.log
- match: (?={{diff_begin}})
embed: scope:source.shell.bash
escape: $
- match: (?=^index\s)
push: extended-patch-headers

commit-header:
# All header attributes are mappings of `key: value` format.
Expand All @@ -59,3 +68,48 @@ contexts:
# https://github.com/SublimeTextIssues/Core/issues/2395
- match: ^
push: Git Commit.sublime-syntax

extended-patch-headers:
# https://git-scm.com/docs/git-show#_generating_patch_text_with_p
- meta_scope: meta.diff.header.extended.git.log
- match: ^(index)\s+
captures:
1: keyword.context.git.log
push: index
- match: ^((?:new|deleted)\s+file\s+)?(mode)\s+
captures:
1: keyword.context.git.log
2: keyword.context.git.log
push: mode
- match: ^((?:dis)?similarity\s+index)\s+
captures:
1: keyword.context.git.log
push: similarity-index
- match: ^((?:copy|move)\s+(?:from|to))\s+
captures:
1: keyword.context.git.log
push: copy-or-move
- match: ^
pop: true
embed: scope:source.diff
escape: '{{commit_or_diff_begin}}'

index:
- include: Git Common.sublime-syntax#commit
- include: mode

mode:
- include: Git Common.sublime-syntax#eol-pop
- match: ',|\.\.'
scope: punctuation.separator.sequence.git.log
- match: '[0-7]{6}'
scope: meta.number.integer.octal.git.log constant.numeric.value.git.log

similarity-index:
- include: Git Common.sublime-syntax#eol-pop
- match: \d+
scope: meta.number.integer.decimal.git.log constant.numeric.value.git.log

copy-or-move:
- include: Git Common.sublime-syntax#eol-pop
- include: Git Link.sublime-syntax#expect-path
83 changes: 40 additions & 43 deletions Git Formats/tests/syntax_test_git_link
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
# SYNTAX TEST "Git Link.sublime-syntax"
# <- text.git.link comment.line punctuation.definition.comment
gitdir: c:/data/sublime/packages/.git.
gitdir: c:/data/sublime/packages/.git
#^^^^^ meta.mapping.key.git.link - meta.mapping.value.git.link
# ^ meta.mapping.git.link - meta.mapping.key.git.link - meta.mapping.value.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^ - string.unquoted.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git.link
# ^ punctuation.separator.drive.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.separator.path.git.link
# ^ - string.unquoted.git.link
# ^ punctuation.terminator.path.git.link
gitdir: c:\data\sublime\packages\.git.
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^ - string.unquoted.git
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git
# ^ punctuation.separator.drive.git
# ^ punctuation.separator.path.git
# ^ punctuation.separator.path.git
# ^ punctuation.separator.path.git
# ^ - string.unquoted.git
gitdir: c:\data\sublime\packages\.git
#^^^^^ meta.mapping.key.git.link - meta.mapping.value.git.link
# ^ meta.mapping.git.link - meta.mapping.key.git.link - meta.mapping.value.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^ - string.unquoted.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git.link
# ^ punctuation.separator.drive.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.separator.path.git.link
# ^ - string.unquoted.git.link
# ^ punctuation.terminator.path.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^ - string.unquoted.git
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git
# ^ punctuation.separator.drive.git
# ^ punctuation.separator.path.git
# ^ punctuation.separator.path.git
# ^ - string.unquoted.git
gitdir: ~/../sub..li~me/./packages/.git
#^^^^^ meta.mapping.key.git.link - meta.mapping.value.git.link
# ^ meta.mapping.git.link - meta.mapping.key.git.link - meta.mapping.value.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# <- keyword.other.gitdir.git.link
#^^^^^ keyword.other.gitdir.git.link
# ^ punctuation.separator.mapping.key-value.git.link
# ^ - string.unquoted.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git.link
# ^ - string.unquoted.git.link
# ^ variable.language.environment.home.git.link
# ^ punctuation.separator.path.git.link
# ^^ constant.language.path.parent.git.link
# ^ punctuation.separator.path.git.link
# ^^ - constant.language.path.parent.git.link
# ^ - variable.language.environment.home.git.link
# ^ punctuation.separator.path.git.link
# ^ constant.language.path.self.git.link
# ^ punctuation.separator.path.git.link
# ^ - constant.language.path.self.git.link
gitdir invalid : ../data/s?bl*me/packages/.git.
# ^ - string.unquoted.git
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.git
# ^ - string.unquoted.git
# ^ variable.language.environment.home.git
# ^ punctuation.separator.path.git
# ^^ constant.language.path.parent.git
# ^ punctuation.separator.path.git
# ^^ - constant.language.path.parent.git
# ^ - variable.language.environment.home.git
# ^ punctuation.separator.path.git
# ^ constant.language.path.self.git
# ^ punctuation.separator.path.git
# ^ - constant.language.path.self.git
gitdir invalid : ../data/s?bl*me/packages/.git
#^^^^^^^^^^^^^^ meta.mapping.key.git.link - meta.mapping.value.git.link
# ^ meta.mapping.git.link - meta.mapping.key.git.link - meta.mapping.value.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.value.git.link - meta.mapping.key.git.link
# <- keyword.other.gitdir.git.link
#^^^^^ keyword.other.gitdir.git.link
# ^^^^^^^ invalid.illegal.separator-expected.git.link
# ^ punctuation.separator.mapping.key-value.git.link
# ^^ constant.language.path.parent.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.separator.path.git.link
# ^ invalid.illegal.path.git.link
# ^ invalid.illegal.path.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.separator.path.git.link
# ^ punctuation.terminator.path.git.link
# ^^ constant.language.path.parent.git
# ^ punctuation.separator.path.git
# ^ punctuation.separator.path.git
# ^ invalid.illegal.path.git
# ^ invalid.illegal.path.git
# ^ punctuation.separator.path.git
# ^ punctuation.separator.path.git
83 changes: 83 additions & 0 deletions Git Formats/tests/syntax_test_git_log
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,86 @@ Date: Thu Sep 21 22:53:04 2017 +0200
#^^^ keyword.other.header.git.log
# ^ punctuation.separator.mapping.pair.git.log - keyword.other.header.git.log
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.log

commit 344d003a330e244cc507d17c2f224bb295013511 (HEAD -> git_show, sublimehq/master, master)
Author: Thomas Smith <[email protected]>
Date: Tue Aug 24 13:44:17 2021 -0400

[TypeScript] [TSX] Fix arrow function type parameter tests for TSX. (#2987)

diff --git a/JavaScript/TypeScript.sublime-syntax b/JavaScript/TypeScript.sublime-syntax
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.shell
# ^ - source.shell
#^^^ source.shell meta.function-call.identifier variable.function
# ^^ punctuation.definition.parameter
# ^^^ variable.parameter.option
index ae1b1061..c1a585d0 100644
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
--- a/JavaScript/TypeScript.sublime-syntax
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.diff meta.diff.header meta.header.from-file
+++ b/JavaScript/TypeScript.sublime-syntax
@@ -551,26 +551,6 @@ contexts:
scope: keyword.operator.comparison.js
set: expression-begin

- # expression-begin:
- # - meta_prepend: true
- # - match: (?=\<(?!<))
- # pop: true
- # branch_point: ts-old-type-assertion
- # branch:
- # - ts-old-type-assertion
diff --git a/JavaScript/tests/syntax_test_typescript_not_tsx.ts b/JavaScript/tests/syntax_test_typescript_not_tsx.ts
#^^^ source.shell meta.function-call.identifier variable.function
index c90bfab4,c90bfab4..e9338c70 100644
#^^^^ keyword.context.git.log
# ^^^^^^^^ constant.other.hash
# ^ punctuation.separator.sequence.git.log
# ^^^^^^^^ constant.other.hash
# ^^ punctuation.separator.sequence.git.log
# ^^^^^^^^ constant.other.hash
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.diff.header.extended.git.log
mode 012345,676543..701532
#^^^ keyword.context.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
# ^ punctuation.separator.sequence.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
# ^^ punctuation.separator.sequence.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
new file mode 012345
#^^^^^^^^^^^^ keyword.context.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
deleted file mode 012345,676543
#^^^^^^^^^^^^^^^^ keyword.context.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
# ^ punctuation.separator.sequence.git.log
# ^^^^^^ meta.number.integer.octal.git constant.numeric.value.git.log
similarity index 983489374
#^^^^^^^^^^^^^^^ keyword.context.git.log
# ^^^^^^^^^ meta.number.integer.decimal.git constant.numeric.value.git.log
dissimilarity index 72637263
#^^^^^^^^^^^^^^^^^^ keyword.context.git.log
# ^^^^^^^^ meta.number.integer.decimal.git constant.numeric.value.git.log
copy from JavaScript/tests/syntax_test_typescript_not_tsx.ts
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
#^^^^^^^^ keyword.context.git.log
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.git string.unquoted.git
move to JavaScript/tests/syntax_test_typescript_not_tsx.ts
#^^^^^^ keyword.context.git.log
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.git string.unquoted.git
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.diff.header.extended.git.log
--- a/JavaScript/tests/syntax_test_typescript_not_tsx.ts
#<- - meta.diff.header.extended
+++ b/JavaScript/tests/syntax_test_typescript_not_tsx.ts
#^^ source.diff meta.diff.header meta.header.to-file punctuation.definition.to-file
@@ -25,3 +25,12 @@
let strLength: number = (<string>someValue).length; // </string>
// ^^^^^^^^ meta.assertion - meta.tag
// ^^^^^^^^^ comment - meta.tag
+
+ <T>() => {};
+// ^^^^^^^^^^^ meta.function
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.diff markup.inserted

commit e2077c6e006acfd2f060aef03c4ef8f89c4db362 (HEAD -> main, origin/main)
#^^^^^ meta.header.git.commit markup.raw.block.git keyword.other.commit.git - source.diff
# ^^^^ entity.other.branch-name.master.git.log