unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: casouri@gmail.com, Eli Zaretskii <eliz@gnu.org>,
	63086@debbugs.gnu.org, Jimmy Wong <wyuenho@gmail.com>
Subject: bug#63086: 29.0.90; go-ts-mode treesit-query-error during jit-lock
Date: Tue, 02 May 2023 00:29:43 +0000	[thread overview]
Message-ID: <rZAjDGFLwSfFTiROkh5YIfTsXZNiykanwOSaIBZQ57jK0XOH4kW6QB_ayBMJAnuhd4AUYv5k5p19SxvLuoWa88FL9iLYOzdYpGhwJEU4Xjc=@rjt.dev> (raw)
In-Reply-To: <9b01dbad-e337-a23c-2341-2a0ca89792dc@gutov.dev>

[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]

On Friday, April 28th, 2023 at 06:05, Dmitry Gutov <dmitry@gutov.dev> wrote:
> On 28/04/2023 04:35, Randy Taylor wrote:
> 
> > Maybe I'm missing something, but doesn't treesit-query-string with an empty string do nothing and always error, since it queries on whatever string you pass in?
> 
> 
> It would return nil, not error (querying an empty buffer). And we should
> be checking for error.
> 
> This is the part that java-ts-mode--string-highlight-helper got right, BTW.

Sorry, I was operating under false assumptions and somehow convinced myself that treesit-query-string with an empty string returning nil meant the query wasn't supported, hence me thinking it achieved nothing. I am no longer under such delusions :).

> 
> go-ts-mode--iota-query-supported-p in your patch relies on the condition
> that the file, at the time the mode is enabled, already contains at
> least one "iota" node.

Good point. I've attached a patch using treesit-query-string with an empty string. It now works properly when iota is missing but inserted later.

> 
> > In that case, wouldn't using treesit-query-capture directly be the best? I don't understand why it's not from reading that thread. If it isn't, then treesit-query-validate is the only option, right?
> 
> 
> treesit-query-validate pops a new buffer interactively in the case of
> failure, so it's not something we should use here.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-go-ts-mode-Use-iota-query-only-if-supported-Bug-6308.patch --]
[-- Type: text/x-patch; name=0001-go-ts-mode-Use-iota-query-only-if-supported-Bug-6308.patch, Size: 1757 bytes --]

From b1175773f8a8aa0cacf0b0ecdd6d0d1b3d7ef505 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Wed, 26 Apr 2023 11:15:45 -0400
Subject: [PATCH] go-ts-mode: Use iota query only if supported (Bug#63086)

iota query support was added on January 5, 2022.  To support older
versions of the tree-sitter-go grammar (like the latest tagged version,
v0.19.1, which was released on March 3, 2021), check if the query is
supported before trying to use it.

* lisp/progmodes/go-ts-mode.el (go-ts-mode--iota-query-supported-p): New
function.
(go-ts-mode--font-lock-settings): Use it.
---
 lisp/progmodes/go-ts-mode.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 77c97ffac11..f32a2d75775 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -105,6 +105,12 @@ go-ts-mode--operators
     ">>" "%=" ">>=" "--" "!"  "..."  "&^" "&^=" "~")
   "Go operators for tree-sitter font-locking.")
 
+(defun go-ts-mode--iota-query-supported-p ()
+  "Returns t if the iota query is supported by the current version of
+the tree-sitter-go grammar."
+  (ignore-errors
+    (or (treesit-query-string "" '((iota) @font-lock-constant-face) 'go) t)))
+
 (defvar go-ts-mode--font-lock-settings
   (treesit-font-lock-rules
    :language 'go
@@ -117,7 +123,9 @@ go-ts-mode--font-lock-settings
 
    :language 'go
    :feature 'constant
-   '([(false) (iota) (nil) (true)] @font-lock-constant-face
+   `([(false) (nil) (true)] @font-lock-constant-face
+     ,@(when (go-ts-mode--iota-query-supported-p)
+         '((iota) @font-lock-constant-face))
      (const_declaration
       (const_spec name: (identifier) @font-lock-constant-face)))
 
-- 
2.40.1


  reply	other threads:[~2023-05-02  0:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 10:00 bug#63086: 29.0.90; go-ts-mode treesit-query-error during jit-lock Jimmy Yuen Ho Wong
2023-04-26 10:36 ` Eli Zaretskii
2023-04-26 11:07   ` Jimmy Wong
2023-04-26 12:38     ` Randy Taylor
2023-04-26 13:26       ` Jimmy Wong
2023-04-26 13:38         ` Eli Zaretskii
2023-04-26 13:44           ` Jimmy Wong
2023-04-26 14:05             ` Randy Taylor
2023-04-26 15:40               ` Randy Taylor
2023-04-27  6:36                 ` Jimmy Wong
2023-04-28  0:16               ` Dmitry Gutov
2023-04-28  1:35                 ` Randy Taylor
2023-04-28 10:05                   ` Dmitry Gutov
2023-05-02  0:29                     ` Randy Taylor [this message]
2023-05-03 21:58                       ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='rZAjDGFLwSfFTiROkh5YIfTsXZNiykanwOSaIBZQ57jK0XOH4kW6QB_ayBMJAnuhd4AUYv5k5p19SxvLuoWa88FL9iLYOzdYpGhwJEU4Xjc=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=63086@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    --cc=wyuenho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).