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 Files] Add Git Files package #1126

Merged
merged 106 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
b44fe8f
Add git package
ryboe Aug 27, 2017
d802d3a
[Git] Commit: rename source.gitcommit to source.git.commit
deathaxe Sep 16, 2017
9ad0f06
[Git] Commit: Sort blocks by top-down
deathaxe Sep 17, 2017
ea2ac5a
[Git] Commit: Refactor commit message
deathaxe Sep 17, 2017
f257c68
[Git] Commit: Refactor changed files list
deathaxe Sep 17, 2017
43e11f3
[Git] Commit: Refactor branch-line
deathaxe Sep 17, 2017
d97a1ab
[Git] Commit: Refactor date line
deathaxe Sep 17, 2017
9404e60
[Git] Commit: Add scopes for username and issue references
deathaxe Sep 17, 2017
d01adf5
[Git] Commit: scope email addresses
deathaxe Sep 17, 2017
2a119a9
[Git] Link: Add syntax for .git files
deathaxe Sep 17, 2017
f938bd1
[Git] Link: rename syntax file to achieve unique names
deathaxe Sep 17, 2017
ec509be
[Git] Commit: rename syntax file to achieve unique names
deathaxe Sep 17, 2017
16cf43b
[Git] Commit: fix syntax_test file headers
deathaxe Sep 18, 2017
bff54a5
[Git] Rebase: Rename .gitrebase top-level scope to .git.rebase
deathaxe Sep 18, 2017
9dc50fb
[Git] Rebase: Add illegal syntax check to commit command lines
deathaxe Sep 18, 2017
98116c9
[Git] Rebase: Update rebase message to highlight commands
deathaxe Sep 18, 2017
3863bf2
[Git] Rebase: Resort rebase code to put associated blocks together
deathaxe Sep 18, 2017
27363ca
[Git] Rebase: Scope some rebase comment lines as headlines
deathaxe Sep 18, 2017
1e6d44d
[Git] Rebase: Match comments at line start only
deathaxe Sep 18, 2017
13897a1
[Git] Rebase: rename syntax file to achieve unique names
deathaxe Sep 18, 2017
2ecbf9e
[Git] Rebase: Add issue/user/email reference highlighting
deathaxe Sep 18, 2017
4752d69
[Git] Commit: Add support for git translations
deathaxe Sep 19, 2017
28d8bb2
Add git package
ryboe Aug 27, 2017
a69b86d
Refactor [section] contexts
ryboe Sep 16, 2017
cacce71
[Git] Commit: Fix syntax tests to match translations
deathaxe Sep 19, 2017
4d7b60e
[Git] Commit: Rename source.git.commit to text.git.commit
deathaxe Sep 19, 2017
92763c4
[Git] Rebase: Rename source.git.rebase to text.git.rebase
deathaxe Sep 19, 2017
52343d1
[Git] Link: Rename source.git.link to text.git.link
deathaxe Sep 19, 2017
f35380e
[Git] Commit: Remove text.plain.message scope
deathaxe Sep 20, 2017
9596e7c
Refactor and simplify commit syntax
ryboe Sep 20, 2017
86efdd6
[Git] Config: Sort sections from top-to down
deathaxe Sep 21, 2017
940d1bf
[Git] Config: Merge some unique atomic sections with their parents
deathaxe Sep 21, 2017
c4d6758
[Git] Config: Disallow any string after section header
deathaxe Sep 21, 2017
16fb208
[Git] Config: Reduce pattern repetitions
deathaxe Sep 21, 2017
a8be2f0
[Git] Config: Simplify constant patterns
deathaxe Sep 21, 2017
0f5fd79
[Git] Commit: Add support for squashed commit messages.
deathaxe Sep 22, 2017
9b22879
Refactor and simplify commit syntax
ryboe Sep 20, 2017
9c6f12a
[Git] Commit: Rename syntax definition file
deathaxe Sep 23, 2017
f952391
[Git] Link: Rename git link.sublime-syntax to gitlink.sublime-syntax
deathaxe Sep 23, 2017
99da69a
[Git] Rebase: rename git rebase.sublime-syntax to gitrebase.sublime-s…
deathaxe Sep 23, 2017
937c7de
[Git] Commit: Add general purpose headline
deathaxe Sep 23, 2017
d4d952d
[Git] Commit: Merge squash into commit syntax tests
deathaxe Sep 23, 2017
83f303b
[Git] Commit: Highlight recent commands in rebase commits
deathaxe Sep 23, 2017
3cc7a7b
Merge branch 'pr/git-commit' into add_gitconfig_pkg
deathaxe Sep 23, 2017
161b6a7
[Git] Rebase: Extend syntax name
deathaxe Sep 23, 2017
437c532
[Git] Rebase: Simplify scopes of command help
deathaxe Sep 24, 2017
dda56a0
[Git] Commit: Update reference scope names
deathaxe Sep 24, 2017
ec25ba2
[Git] Commit: Remove path from SYNTAX TEST header
deathaxe Sep 24, 2017
918e1de
[Git] Commit: Add Signed-off-by keyword and fix email-reference
deathaxe Sep 24, 2017
01320be
[Git] Commit: Use entity.name.reference for references
deathaxe Sep 24, 2017
ce37d63
[Git] Commit: Less strict empty 2nd line checks
deathaxe Sep 24, 2017
a4d64f3
[Git] Commit: Improve re-usability
deathaxe Sep 24, 2017
09c90ce
[Git] Commit: Support git diff
deathaxe Sep 24, 2017
d068d7d
Merge pull request #2 from deathaxe/pr/git-commit
Sep 25, 2017
4195122
[Git] Rebase: Reduce comment stack push/pops
deathaxe Sep 25, 2017
d1d2dd7
[Git] Rebase: Prepare for common reference scopes
deathaxe Sep 25, 2017
bf92620
[Git] Rebase: Use meta.subject to identify commit subject
deathaxe Sep 25, 2017
cbfbe7e
[Git] Rebase: Remove path from SYNTAX TEST header
deathaxe Sep 25, 2017
cc7df2f
Merge branch 'pr/git-rebase' into add_gitconfig_pkg
deathaxe Sep 25, 2017
c6a2a70
Merge pull request #1 from deathaxe/pr/git
Sep 30, 2017
b901cc8
[Git] Config: Highlight invalid escapes in section names
deathaxe Oct 1, 2017
a81f4e3
[Git] Rename git config base scope
deathaxe Sep 26, 2017
25b3658
Resolve conflicts with add_gitconfig_pkg
deathaxe Oct 1, 2017
1d17e49
Merge pull request #3 from deathaxe/pr/gitlink
Oct 12, 2017
689b737
Merge pull request #4 from deathaxe/pr/git-config
Oct 15, 2017
23e9200
[Git] Rename files to satisfy ST naming conventions
deathaxe Sep 25, 2017
bf103aa
[Git] Fix some scopes to satisfy new file names
deathaxe Sep 26, 2017
1a920e1
[Git] Create a hidden file with common scopes
deathaxe Sep 25, 2017
92dff27
[Git] Add Git Log syntax highlighting
deathaxe Sep 25, 2017
f97ebd3
[Git] Add .gitignore and .gitattributes syntax highlighting
deathaxe Oct 1, 2017
1a077a3
[Git] Link: Tweak path scoping along the lines of fnmatch
deathaxe Oct 10, 2017
942d62e
[Git] Config: Fix section snippet
deathaxe Oct 16, 2017
462873a
[Git] Config: Rename Symbol List
deathaxe Oct 21, 2017
7e2fd09
[Git] Rebase: Update comments
deathaxe Oct 21, 2017
2d9b9f9
[Git] Rebase: Use common line-end rule
deathaxe Oct 21, 2017
20445ee
[Git] Highlight fully qualified rebase message only
deathaxe Oct 21, 2017
aeb786b
[Git] Rebase: Rename commit-message to commit-section
deathaxe Oct 21, 2017
965b015
[Git] Commit: Add some comments as separators
deathaxe Oct 21, 2017
4896438
[Git] Commit: Typo
deathaxe Oct 21, 2017
b19e70c
[Git] Config: Don't mix escapes and trailing-slash
deathaxe Oct 21, 2017
9a78289
[Git] Config: Use escaped quotation marks
deathaxe Oct 21, 2017
ed8c6e7
[Git] Config: Udate/fix some syntax tests
deathaxe Oct 21, 2017
6bd9ada
Merge pull request #5 from deathaxe/pr/add_git_files
Oct 21, 2017
731e25f
[Git] Config: Remove format-escapes
deathaxe Nov 1, 2017
d30a0aa
Merge pull request #6 from deathaxe/pr/add_git_files
Nov 6, 2017
c8d8dee
[Git Files] Config: Allow single quoted value strings
deathaxe Dec 18, 2017
7e41d5b
[Git Files] Config: embed ShellScript
deathaxe Dec 18, 2017
0bcb500
[Git Files] Rebase: Scope all commit operations separately
deathaxe Dec 18, 2017
26f8095
[Git Files] Config: Remove single-quoted strings
deathaxe Jan 2, 2018
1701313
[Git Files] Config: Fix section header must not span multiple rows
deathaxe Jan 2, 2018
a8d5928
[Git Files] Config: Add support for legacy section headers
deathaxe Jan 2, 2018
6af5bfe
[Git Files] Config: Flatten section header rules
deathaxe Jan 2, 2018
0485882
[Git Files] Config: Add some divider comments
deathaxe Jan 2, 2018
c783cc9
[Git Files] Config: Increase performance by 13%
deathaxe Jan 2, 2018
85116e0
[Git Files] Config: Simplify 'escape' rule
deathaxe Jan 2, 2018
a987aff
[Git Files] Config: Improve meta.mapping scopes
deathaxe Jan 2, 2018
7aa5ffc
[Git Files] Config: Respect shellscript's line continuation
deathaxe Jan 2, 2018
b38ad96
[Git Files] Config: Hardening quoted shell script escape
deathaxe Jan 3, 2018
4de96c7
[Git Files] Config: Fix typo
deathaxe Jan 3, 2018
7c10705
Merge pull request #7 from deathaxe/add_gitconfig_pkg
Jan 4, 2018
00e10a8
[Git Files] Config: Capture eol if available
deathaxe Jan 21, 2018
bcd2798
[Git Files] Config: Add indention rules
deathaxe Jan 21, 2018
065536f
[Git Files] Config: Fix multiline shellscript with double quotes
deathaxe Feb 5, 2018
c2fee71
Merge pull request #8 from deathaxe/add_gitconfig_pkg
Feb 8, 2018
a255364
[Git Files] Config: Move Indention Rules to correct path
deathaxe Feb 10, 2018
758cc44
Merge pull request #9 from deathaxe/add_gitconfig_pkg
Feb 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Git/Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.gitcommit, source.gitconfig, source.gitrebase</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string># </string>
</dict>
</array>
</dict>
</dict>
</plist>
9 changes: 9 additions & 0 deletions Git/Snippets/section.sublime-snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<snippet>
<content><![CDATA[
[${1:section}]
$0
]]></content>
<tabTrigger>section</tabTrigger>
<scope>source.gitconfig</scope>
<description>[section]</description>
</snippet>
14 changes: 14 additions & 0 deletions Git/Symbol List.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Symbol List</string>
<key>scope</key>
<string>meta.brackets.gitconfig</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
</dict>
</dict>
</plist>
81 changes: 81 additions & 0 deletions Git/commit.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
%YAML 1.2
---
# Highlight regular git commits, merge commits, and tags.

name: Git Commit
file_extensions:
- COMMIT_EDITMSG
- MERGE_MSG
- TAG_EDITMSG
scope: source.gitcommit

contexts:
prototype:
- include: comments
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including comments as prototype is useless as they must only start at the beginning of a line and must not be matched within a commit message line. Therefore the following construct is enough:

main:
    - include: comments
    - include: commit-message


main:
- include: commit-message

branch-line:
- match: \bOn branch\s+(.*)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to handle localized comments? I just saw git for linux presenting my the comment in german language. So highlighting fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there aren't that many translation files: https://github.com/git/git/tree/master/po

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FichteFoll: The _( in _("On branch ") tells you the text will be translated by gettext before being displayed on the console or printed to COMMIT_EDITMSG.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my first line is the search string to look for in the .po files. Unfortunately, github's own search doesn't produce any useful results for these.

captures:
1: support.type.branch-name.gitcommit

change:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting context, but can be improved. For example, highlight the ++++++------ lines accordingly. Take a look at how GitSavvy does it.

- match: (new file|modified|deleted)\s*(:)\s*(.*)
captures:
1: keyword.change-list.change.gitcommit
2: punctuation.separator.change.gitcommit
3: keyword.change-list.file.gitcommit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather tend to scope that as normal string.unquoted. It is not a keyword but a value.

The whole construct could be handled as key-value pair in general, I think.


change-list:
- include: change-list-header
- include: change

change-list-header:
- match: '\bChanges to be committed\s*(:)'
scope: keyword.change-list.heading.gitcommit
captures:
1: punctuation.separator.change-list.gitcommit

comments:
- match: '#'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about this?

[foosection]
bar = baz#qux
one = two #three

Does bar have the value baz or does it have the value baz#qux?

Copy link
Contributor Author

@ryboe ryboe Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Hmm, currently it's matching as a value, ever since I changed this match from \S to \S+.

comment_or_value

I'm not sure if this is the correct behavior, or if it should match as a comment. If it should be a comment, I could change \S+ to [^#;\s]+.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and tested this here (git version 2.11). With

[x]
    a = b#c

the output of

git config --get x.a

is

b

Copy link
Contributor

@rwols rwols Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover,

"b#c"    ---> b#c
\"b#c\"  ---> "b
\"       ---> "

scope: punctuation.definition.comment.gitcommit
push:
- meta_scope: comment.line.gitcommit
- match: \n
pop: true
- include: change-list
- include: branch-line
- include: date-line

commit-message:
# this absurd regex is necessary to:
# 1. match comments in the subject line
# 2. only style the first 50 chars in the subject line
- match: ([^#\n]{,50})[^#\n]*((#).*$)?
Copy link
Collaborator

@deathaxe deathaxe Sep 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see from a couple of git commit -m "My message # with hash # tags #" a commit message can contain # anywhere without matching them as comment. Therefore I am wondering what made you create this regex?

I'd rather check for the first occurrence of # at the beginning of a line and expect comments only from this point on as a commit message should not be split by comments.

The commit message in EDIT_COMMITMSG says: "Lines starting with '#' will be ignored"

Furthermore why do you style the 50 characters only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I only styled the first 50 characters because this is what vim does. I was trying to replicate vim's behavior as closely as possible. I believe 50 character subject lines are a git best practice that vim tries to encourage.

  2. Good catch about # not being a comment unless it's the first character in the line! That's a big bug.

captures:
1: string.unquoted.subject-line.gitcommit markup.heading.gitcommit
2: comment.line.gitcommit
3: punctuation.definition.comment.gitcommit
push:
# enforce empty line following subject line
- match: \n
push:
- match: \n
pop: true
- match: '.+$'
scope: invalid.missing-newline.gitcommit
# everything left that isn't a comment is the commit message
- match: '[^#]*'
scope: text.plain.commit-message.gitcommit
push:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we pop from this push?

Copy link
Contributor Author

@ryboe ryboe Sep 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! This is kinda hacky. The goal is to enforce the empty-line-after-subject rule This is done with the previous match: \n context, which matches text between two newlines. This will actually highlight all even-numbered lines bright red. But we only want to highlight the second line red (if there's any text there). The solution I came up with is to push a context on the stack that matches all remaining text in the commit message, before match: \n has a chance to match again. To ensure that match: \n can't match any more text, I push a context on the stack and never pop it. I actually use this trick in the parent context too, which is also never popped.

If there's a better, less hacky, way of achieving this, please let me know!

vim's highlighting of commits

vim_commit

- match: '[^#]*'
scope: text.plain.commit-message.gitcommit

# apply a meta scope to the commit date
date-line:
- match: \bDate\s*(:)\s*(.*)
captures:
1: punctuation.separator.date.gitcommit
2: meta.commit-date.gitcommit
165 changes: 165 additions & 0 deletions Git/config.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
%YAML 1.2
---
# Syntax based on documentation here:
# https://git-scm.com/docs/git-config#_syntax

name: Git Config
file_extensions:
- gitconfig # /etc/gitconfig
- .gitconfig # ~/.gitconfig
first_line_match: ^\[core\] # .git/config files always start with [core]
scope: source.gitconfig

variables:
section_name: '[\w.-]+(?=[\s\]])'
space_or_eol: (?=(?:\s|$)) # makes values on very last line match properly
variable_name: '[a-zA-Z][\w-]*'

contexts:
prototype:
- include: comments

main:
- include: section
- include: key-value-pair

boolean:
# 0 and 1 omitted due to mismatches (e.g. "log -1", "HEAD~1"). will be
# matched as unquoted strings instead
- match: \b(?:yes|true|on|off|no|false){{space_or_eol}}
scope: constant.language.gitconfig

color-attribute:
- match: \b(?:no-?)?(?:ul|strike|reverse|italic|dim|bold|blink){{space_or_eol}}
scope: support.constant.color-attribute.gitconfig

color-hex:
- match: (#)\h{6}
captures:
0: constant.other.color.rgb-value.gitconfig
1: punctuation.definition.constant.gitconfig

color-named:
- match: \b(?:yellow|white|red|normal|magenta|green|cyan|blue|black|auto){{space_or_eol}}
scope: support.constant.color.gitconfig

comments:
- match: '[#;]'
scope: punctuation.definition.comment.gitconfig
push:
- meta_scope: comment.line.gitconfig
- match: $\n? # consume newline so completions aren't shown at end of line when typing comments
pop: true

# '\b', '\n', '\t', '\"', '\\'
escape:
- match: \\[\\"bnt]
scope: constant.character.escape.gitconfig

illegal-newline:
- match: \n
scope: invalid.illegal.gitconfig
pop: true

# key = val
key-value-pair:
- match: ^\s*({{variable_name}})\s*(\=)
captures:
1: variable.other.readwrite.gitconfig
2: keyword.operator.assignment.gitconfig
push:
# Hex colors like #efefef will be matched as comments unless we lower
# the precedence of comments. Here we disable the comments prototype and
# match comments after color-hex in the value rule.
- meta_include_prototype: false
- meta_scope: meta.key-value-pair.gitconfig
- meta_content_scope: meta.value.gitconfig
- match: '(?=^\s*{{variable_name}}\s*\=)' # next key-value pair
pop: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match+pop is a bit weird.

[x]
    a = b
        c
    d = e
    f =
~> git config --get x.a
b
~> git config --get x.d
e
~> git config --get x.c
   # (this prints a newline (empty string?))
~> git config --get x.asdf
~> # (prints nothing)
~> git config --get x.f
   # (this prints a newline (empty string?))
~>

It seems values really end when a newline is encountered. Except of course when we're in a quoted string. But the syntax now suggests that c is (part of) a value while it seems to be a key for an empty value according to git. So my suggestion is to pop once a new-line is encountered inside the value context and to remove this match+pop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be resolved by my latest push.

- match: (?=\[) # start of new section
pop: true
- include: value

# [section-name "subsection"]
section:
- match: \[
scope: punctuation.definition.section.begin.gitconfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with punctuation.definition if you think it suits better.

push:
- meta_scope: meta.brackets.gitconfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe someone could help clarify the definition.section stuff here?

  1. In an INI file a section is the whole block under the [section_name] construct.
  2. Per convention (PackageDev completions) I can use punctuation.definition. ... or punctuation.section. ... but not punctuation.definition.section.
  3. ST3 documentation / Scope Naming says, if you use meta.brackets you need to / should use punctuation.section.brackets. (begin | end)

All of that is quite mixed up here.

I'd suggest to handle a INI file section the same way as JSON object (meta.mapping) in general.
The question then is how to correctly scope its "headline"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the scope from punctuation.definition.section to punctuation.definition.brackets to follow the Scope Naming docs more closely. I also have the section context matching the [header] and the whole block underneath it.

- match: \]
scope: punctuation.definition.section.end.gitconfig
pop: true
- include: illegal-newline # complain if '[' and ']' on separate lines
- include: section-name
- include: string-double # subsection
- include: stray-bracket

section-name:
- match: '{{section_name}}'
scope: entity.name.gitconfig

stray-bracket:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a general question about the structure of syntax files:

Is it really useful to split the rules in such little parts, that we end up in single such simple once used matches?

With such rules being used several times, I'd answer YES, but why doing so for uniquely used matches. The scope-name already tells us its usage "stray-bracket" and a comment would do so, too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For code, having functions for self-documenting code is usually good practice, but as you mentioned, the scope name is very self-documenting in syntax definitions as well, so that doesn't really hold here.

- match: \]
scope: punctuation.definition.section.end.gitconfig invalid.illegal.stray-bracket.gitconfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything after the closing bracket of a section line is illegal, not only a stray bracket, isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deathaxe Does that include comments?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it does not. Git allows comments at the end of each line. Comments are handled as prototype in the syntax file and thus should apply first. Any other character should then be scoped as illegal.

The rule should than just look like - match: \S


string:
- include: string-double-escaped-quotes
- include: string-double
- include: string-single-escaped-quotes
- include: string-single

string-double:
- match: '"'
scope: punctuation.definition.string.begin.gitconfig
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.gitconfig
- match: '"'
scope: punctuation.definition.string.end.gitconfig
pop: true
- include: escape

# some values use escaped quotes, e.g. --pretty=format:\"%h %ad | %s%d [%an]\"
string-double-escaped-quotes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this context.

Copy link
Contributor Author

@ryboe ryboe Sep 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, I'm not sure how to do that without increasing the potential for mismatches. With values (everything to the right of the = sign), I'm matching strings separately, at a high precedence. That way string text doesn't get mismatched as a color or boolean.

[foo]
    boolVar = true  <- match as bool
    color   = blue  <- match as color
    bar     = --flag=\"true blue\"  <- don't want to match as bool or color

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see your point and I also see that it's been changed to an unquoted string so I'm happy. On the other hand, can something like this happen?

[foosection]
bar = \"  # a string of length one consisting of a double-quote character.

- match: \\"
scope: punctuation.definition.string.begin.gitconfig
push:
- meta_include_prototype: false
- meta_scope: string.unquoted.gitconfig
- match: \\"
scope: punctuation.definition.string.end.gitconfig
pop: true
- include: escape

string-single:
- match: "'"
scope: punctuation.definition.string.begin.gitconfig
push:
- meta_include_prototype: false
- meta_scope: string.quoted.single.gitconfig
- match: "'"
scope: punctuation.definition.string.end.gitconfig
pop: true
- include: escape

# \'foo\'
string-single-escaped-quotes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this context too.

- match: \\'
scope: punctuation.definition.string.begin.gitconfig
push:
- meta_include_prototype: false
- meta_scope: string.unquoted.gitconfig
- match: \\'
scope: punctuation.definition.string.end.gitconfig
pop: true
- include: escape

value:
- include: color-hex # match #efefef as hex color not comment
- include: comments
- include: string # match 09 in --format='%09' as string not int
- include: color-named # red, blue, green
- include: color-attribute # bold, italic, underline
- include: boolean # true, yes, on, 1
- match: '\S+' # match most values
scope: string.unquoted.value.gitconfig
58 changes: 58 additions & 0 deletions Git/rebase.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%YAML 1.2
---
# Highlight interactive rebase text (git rebase -i).

name: Git Rebase
file_extensions:
- git-rebase-todo
first_line_match: '^(?:pick|squash|reword|fixup|exec|edit|drop) \h{7,} '
scope: source.gitrebase

variables:
hash: \h{7,}

contexts:
prototype:
- include: comments

main:
- include: commit

comments:
- match: '#'
scope: punctuation.definition.comment.gitrebase
push:
- meta_scope: comment.line.gitrebase
- match: \n
pop: true
- include: rebase-msg

# e.g. pick d284bb2 Initial commit
commit:
- match: ^\s*(squash|reword|pick|fixup|exec|edit|drop|x|s|r|p|f|e|d)[\t ]
captures:
1: storage.type.edit.gitrebase
push:
- meta_scope: meta.commit.gitrebase
- match: \n
pop: true
- match: \b({{hash}})\s # e.g. d284bb2
captures:
1: constant.numeric.hex.hash.gitrebase
push:
- meta_content_scope: text.plain.commit-msg.gitrebase
- match: $
pop: true

# e.g. Rebase 9e73d21..6746220 onto 9e73d21 (2 commands)
# highlight the hashes in this comment
rebase-msg:
- match: '\bRebase\s+'
push:
- meta_scope: meta.rebase-msg.gitrebase
- match: '$'
pop: true
- match: '\b{{hash}}\b'
scope: constant.numeric.hex.hash.gitrebase
- match: \.\.
scope: keyword.operator.commit-range.gitrebase
Loading