From ca0a9a21d55372dab1313446c59df6864d32f775 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 29 Aug 2021 18:15:59 +0300 Subject: [PATCH] [Git Formats] highlight diffs in Git Log syntax for `git show` (#2989) * [Git Formats] highlight diffs in Git Log syntax for `git show` * [Git Formats] Improvements to Git Log from PR review * [Git Formats] Scope the extended patch headers in Git Log syntax * [Git Formats] use variables for escape patterns in Git Log syntax * [Git Formats] apply a meta scope to the extended diff headers in Git Log * [Git Formats] Rework Git Link syntax to avoid meta.mapping.value scope when referencing the path context from another syntax * [Git Formats] Remove .link scope suffix from generic path scopes in Git Link syntax * [Git Formats] Remove erroneous dot from Git Link path terminator punctuation * [Git Formats] remove unnecessary punctuation.terminator scope at EOL --- Git Formats/Git Link.sublime-syntax | 27 +++++---- Git Formats/Git Log.sublime-syntax | 62 +++++++++++++++++-- Git Formats/tests/syntax_test_git_link | 83 +++++++++++++------------- Git Formats/tests/syntax_test_git_log | 83 ++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 59 deletions(-) diff --git a/Git Formats/Git Link.sublime-syntax b/Git Formats/Git Link.sublime-syntax index b26919ac146..1b5cbfd8ce2 100644 --- a/Git Formats/Git Link.sublime-syntax +++ b/Git Formats/Git Link.sublime-syntax @@ -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 diff --git a/Git Formats/Git Log.sublime-syntax b/Git Formats/Git Log.sublime-syntax index 5cd70052d66..52c893f042d 100644 --- a/Git Formats/Git Log.sublime-syntax +++ b/Git Formats/Git Log.sublime-syntax @@ -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: @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/Git Formats/tests/syntax_test_git_link b/Git Formats/tests/syntax_test_git_link index 6302ea4aa5c..a442c22715a 100644 --- a/Git Formats/tests/syntax_test_git_link +++ b/Git Formats/tests/syntax_test_git_link @@ -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 diff --git a/Git Formats/tests/syntax_test_git_log b/Git Formats/tests/syntax_test_git_log index 6e5d06035a2..2e2a9d5793e 100644 --- a/Git Formats/tests/syntax_test_git_log +++ b/Git Formats/tests/syntax_test_git_log @@ -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 +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 +--- 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 +#^^^^^^^^ 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 = (someValue).length; // + // ^^^^^^^^ meta.assertion - meta.tag + // ^^^^^^^^^ comment - meta.tag ++ ++ () => {}; ++// ^^^^^^^^^^^ 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 \ No newline at end of file