Skip to content

Syntax highlighting does not use git.commentchar for highlighting comments  #45

Open

Description

@alewis001

Currently, syntax highlighting assumes # is the comment character used in Git Commit messages. The comment character used in Git Commit messages can be configured using core.commentChar in .gitconfig. That functionality is commonly used to change the comment character to something else such that an issue tracker number can be used at the beginning of the commit message such as: #123: Some changes.

If possible, the syntax highlighting would read the configuration to determine the comment character instead of assuming # and highlight comments based on the configured character.

Activity

  1. gbprod commented on Jul 27, 2023

    @gbprod
    Owner

    Hey, that's really interesting !
    I don't know if it's possible to do that with tree-sitter but I will do some research.

    I don't have much time right now but I'll work on it 😅

  2. alewis001 commented on Jul 27, 2023

    @alewis001
    Author

    That's all I can and would ask for 😄 and thank you for any time you can spend looking at this.

    I'll try to do some digging myself. Neovim, treesitter, etc. are somewhat new to me so don't hold your breath though 😄

  3. alewis001 commented on Jul 27, 2023

    @alewis001
    Author

    I'm probably only telling you what you already know but, just in case this helps at all... https://tree-sitter.github.io/tree-sitter/creating-parsers#external-scanners

    It says...

    Many languages have some tokens whose structure is impossible or inconvenient to describe with a regular expression

    ...and...

    ..in order to add custom logic for recognizing certain tokens.

    So, I'm hoping those statements mean that this could be used to in some way read the commentchar config and then detect the comment token without affecting the rest of the parser too heavily.

  4. iliekturtles commented on Jul 31, 2025

    @iliekturtles

    I reported the same issue at the-mikedavis/tree-sitter-git-commit#16 before Helix switched to using this fork of tree-sitter-git-commit. Rather than parse commentChar, another solution is to use a fixed list of comment characters, which is what Neovim appears to do: https://github.com/neovim/neovim/blob/2b21c9c23f889555dd93ba508a0f787b25ed9bb4/runtime/ftplugin/gitcommit.vim#L21. #;@!$%^&|: are all allowed.

  5. gbprod commented on Jul 31, 2025

    @gbprod
    Owner

    Interesting, I'll try to implements this. Not sure that I'll can do that this month but a PR is welcome :)

  6. iliekturtles commented on Jul 31, 2025

    @iliekturtles

    I started an implementation in the other fork the-mikedavis/tree-sitter-git-commit#17, but never finished before it was archived. Will keep you updated if I find time to submit a PR here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions