bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#61913: java-ts-mode query error for string highlight, due to recent


From: Dmitry Gutov
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
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1

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








reply via email to

[Prev in Thread] Current Thread [Next in Thread]