-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add syntax highlight code for ignore files #3104
Conversation
I like the idea but I would reconsider the syntax groups. The current colors seem a bit weird because files are not statements, wildcards are not identifiers, and negated files are definitely not errors. Maybe using |
runtime/syntax/ignore.yaml
Outdated
- error: "^\\!.*" # negated | ||
|
||
- special: '/' | ||
- identifier: '!|\*|\[.*]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- identifier: '!|\*|\[.*]' | |
- symbol.operator: '^!' | |
- identifier: '\?|\*|\[.*?\]' | |
- constant.specialChar: "\\\\." |
!
should only match when it's the first character on the line (exclamation mark in the middle of a file name has no special meaning)?
in .gitignore matches any single character except backslash- The regex
.*
is greedy so it wouldn't work if you have something likedir[a-z]/file[a-z]
. Changing it to.*?
makes it non-greedy so it only matches until the next]
. - Add highlighting for escaped characters like
\?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your suggestions I thought of something like this, what do you think?
---
filetype: ignore
detect:
filename: .*ignore$
rules:
- statement: .*$ # files
- constant.string: .*/$ # diretories
- diff-deleted: '^!.*' # negated
- special: /
- identifier: '^!|\?|\*|\[.*?]|\\.'
- comment: '#.*$'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the colors strange?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rules seem to work alright for common patterns but some of the weirder cases are not highlighted correctly.
The relationship was based on colors because of the existing identifiers I did not find any related to the ignore file patterns. diff-added and diff-deleted are also not nominally related. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you commit the changes from #3104 (comment) it looks good to me
@Andriamanitra Applied |
Adding ignore file support by default so you don't need to install the language-ignore plugin.