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

tree-sitter-hl-mode doesn't honor the :extend font face in single line comments #266

Open
mlabbe opened this issue Jan 3, 2024 · 1 comment

Comments

@mlabbe
Copy link

mlabbe commented Jan 3, 2024

In many, if not all supported languages, tree-sitter-hl-mode's font locking does not honor the :extend attribute of a face. The :extend face attribute is used to send a highlight past the newline character in a line.

The easiest way to see this is to produce a // comment in a mode that supports it, such as c-mode. Set the font-lock-comment-face and tree-sitter-hl-face:comment :background to a color other than the default background. Then, observe as comments stop at the newline instead of the end of the frame.

tree-sitter-hl-mode Disabled (no bug)

disabled

tree-sitter-hl-mode Enabled (bug)

enabled

To reproduce this issue:

  1. launch emacs 29.1 with emacs -q --load repro.el (code is below).
  2. Create a blank c file, ensuring c-mode is set. Add a // comment to any line and hit enter.
  3. Observe the comment terminates at the newline (before the right side of the frame).
  4. Type M-x tree-sitter-hl-mode. Observe the comment goes to the right side of the frame.

Languages this bug exists in

Not a complete list, but:

  • c
  • c++
  • javascript
  • rust (via rustic)
  • bash
  • python
  • ruby

repro.el

;;
;; repro.el

(custom-set-faces
 '(font-lock-comment-face ((t (:background "darkblue" :foreground "yellow" :extend t)))))

(custom-set-faces
 '(tree-sitter-hl-face:comment ((t (:inherit font-lock-comment-face)))))

;; comments look like this

;;
;; tree-sitter
;;

(defvar bootstrap-version)
(setq straight-repository-branch "master")
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(require 'package)
(use-package tree-sitter
    :straight t
    :config
    (global-tree-sitter-mode)
    :hook ((python-mode
            rustic-mode
            c-mode cc-mode
            go-mode
            typescript-mode
            javascript-mode) . tree-sitter-hl-mode)
    )
    
(use-package tree-sitter-langs
    :straight t
    :ensure t
    :after tree-sitter
    )

(require 'tree-sitter-hl)



Note that the same bug was also reported at emacs-tree-sitter/tree-sitter-langs#302. Apologies for the inconvenience of a double-report: I am finding it a little challenging to track down the maintainer of tree-sitter-hl.el for the report, on github.

@jcs090218
Copy link
Member

Have you tried customize faces in tree-sitter-hl.el? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants