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

add tree-sitter-git-config #1426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,7 @@
path = helix-syntax/languages/tree-sitter-make
url = https://github.com/alemuller/tree-sitter-make
shallow = true
[submodule "helix-syntax/languages/tree-sitter-git-config"]
path = helix-syntax/languages/tree-sitter-git-config
url = https://github.com/the-mikedavis/tree-sitter-git-config.git
shallow = true
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| elixir | ✓ | | | `elixir-ls` |
| fish | ✓ | ✓ | ✓ | |
| git-commit | ✓ | | | |
| git-config | ✓ | | | |
| git-diff | ✓ | | | |
| git-rebase | ✓ | | | |
| glsl | ✓ | | ✓ | |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-git-config
Submodule tree-sitter-git-config added at 0e4f0b
10 changes: 10 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,13 @@ scope = "source.regex"
injection-regex = "regex"
file-types = ["regex"]
roots = []

[[language]]
name = "git-config"
scope = "source.gitconfig"
roots = []
# TODO: allow specifying file-types as a regex so we can read directory names (e.g. `.git/config`)
file-types = [".gitmodules", ".gitconfig"]
Copy link
Contributor

@pickfire pickfire Jan 7, 2022

Choose a reason for hiding this comment

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

Is this a good idea? It could be .git/config as well. Not sure how we can do it here.

@archseer I think we might have to add support to check for the path as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm yeah I think if file-types could be a regex or a glob that'd work? We'd want to detect git-config for a few files where the containing directory/ies are important

Copy link
Contributor

Choose a reason for hiding this comment

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

For git it's actually a little more complicated. Git repositories don't have to be called .git. That is just the default for working trees. There many other possible variations. e.g bare repositories, submodules and git with multiple working trees (see git-worktree).

.git/modules/helix-syntax/languages/tree-sitter-c/config for example is probably a git config file in your helix working tree.

The best way afaik to detect git config files is to check for other items in the same directory. objects and refs for example.

I'm pretty sure other file types will be in a similar situation.

bat seems to have this figured out. Perhaps would be worth looking to see how they do it?

Copy link
Contributor

@pickfire pickfire Jan 8, 2022

Choose a reason for hiding this comment

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

I am thinking that's better done as plugin or some sort of check then. But right now the simplest would be regex on full path.

injection-regex = "git-config"
comment-token = "#"
indent = { tab-width = 4, unit = "\t" }
27 changes: 27 additions & 0 deletions runtime/queries/git-config/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
((section_name) @keyword.directive
(#eq? @keyword.directive "include"))

((section_header
(section_name) @keyword.directive
(subsection_name))
(#eq? @keyword.directive "includeIf"))

(section_name) @markup.heading
(variable (name) @variable.other.member)
[(true) (false)] @constant.builtin.boolean
(integer) @constant.numeric.integer

((string) @string.special.path
(#match? @string.special.path "^(~|./|/)"))

[(string) (subsection_name)] @string

[
"["
"]"
"\""
] @punctuation.bracket

"=" @punctuation.delimiter

(comment) @comment