GNU bug report logs - #61913
java-ts-mode query error for string highlight, due to recent commit in tree-sitter-java.

Previous Next

Package: emacs;

Reported by: Vincenzo Pupillo <v.pupillo <at> gmail.com>

Date: Thu, 2 Mar 2023 12:22:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Vincenzo Pupillo <v.pupillo <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>, Theodor Thornhill <theo <at> thornhill.no>
Cc: casouri <at> gmail.com, 61913 <at> debbugs.gnu.org
Subject: bug#61913: java-ts-mode query error for string highlight, due to recent commit in tree-sitter-java.
Date: Thu, 9 Mar 2023 19:08:14 +0200
On 09/03/2023 18:49, Vincenzo Pupillo wrote:
> treesit-query-validate calls treesit-query-capture which is defined in treesit.c.
> It's a wrapper for interactive use, I guess it's not faster.

Fair point, but there is a certain difference: treesit-query-validate 
creates a temporary buffer to run treesit-query-capture in. Whereas, in 
your patch, treesit-query-capture is called in the current buffer, 
whichever buffer is current when the code is loaded, I suppose.

If the buffer is large, that might take a non-negligible amount of time.

So okay, reusing treesit-query-validate is not a good idea, but we could 
use the same pattern here, or try treesit-query-string which also uses a 
temp buffer:

diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index fca00cdce4f..0db6c9822ed 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -148,13 +148,13 @@ java-ts-mode--operators
   "Java operators for tree-sitter font-locking.")

 (defun java-ts-mode--string-highlight-helper ()
-"Returns, for strings, a query based on what is supported by
+  "Returns, for strings, a query based on what is supported by
 the available version of Tree-sitter for java."
   (condition-case nil
-      (progn (treesit-query-capture 'java '((text_block) 
@font-lock-string-face))
+      (progn (treesit-query-string "" '((text_block) 
@font-lock-string-face) 'java)
 	     `((string_literal) @font-lock-string-face
 	       (text_block) @font-lock-string-face))
-    (error
+    (treesit-query-error
      `((string_literal) @font-lock-string-face))))

 (defvar java-ts-mode--font-lock-settings







This bug report was last modified 2 years and 74 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.