Subject: bug#59833: 29.0.60; json-ts-mode fontifies everything as string

From: Theodor Thornhill <[email-masked]>
Date: Mon, 05 Dec 2022 16:03:43 +0100

Jostein Kjønigsen <[email-masked]> writes:

> On 05.12.2022 15:42, Randy Taylor wrote:
>>
>> Thanks, I meant just the treesit-font-lock-feature-list variable :) (so moving pair before string).
>>
>> Having the font-lock settings alphabetized too is great, but I remember running into some highlighting issues depending on the order of things.
>> For example, since error is above number, the number face will not be highlighted as error when an error occurs.
>>
>> Try:
>> {
>>    "test": 2
>> }
>>
>> and remove the colon. Before your patch, the entire line is red. After, only "test" is red.
>>
>> So in general, I think we should stick all :overrides at the bottom
>> of that list (with error being the ultimate one), and keep everything
>> above and below alphabetized, but separately, which is how I
>> organized json-ts-mode.
> Good observation. Agreed.

Yes ok ok ;-)

>>
>> Are you guys talking about the json-mode package? Jostein mentioned
>> "Emacs still defaults to json-mode", but when I open a JSON file I
>> get js-json-mode, which is what I assumed he meant. js-json-mode is
>> what I was trying to match in json-ts-mode.
>
> I've never heard of js-json-mode until today. I always use json-mode 
> (which AFAIK) is still the default for json-files, unless overridden in 
> your own .emacs setup.
>
> I can see that in Emacs git right now, json-ts-mode behaves closely to 
> js-json-mode. I honestly expected it to match the Emacs-default 
> json-mode though, and found the current highlighting ... somewhat 
> unexpected.
>
> IMO, yes the keys are technically speaking strings, but the are 
> predominantly and semantically keys, and IMO should be highlighted as 
> such. Just like json-mode does.
>
> I realise this is somewhat subjective and preferential, but as far as my 
> preference goes, I clearly prefer json-mode over js-json-mode, and as 
> such also prefer the current patch-sets for json-ts-mode which Theo has 
> submitted.
>
> (On my part we can avoid side-tracking related to why there are multiple 
> json-modes, unless has a deep need to contextualize these changes 
> related to those ;) )
>

Yeah js-json-mode is a lot simpler, and is imo too simple. The json-mode
is not infact default in emacs, but there are two, one in melpa and one
in elpa, IIRC.

Anyway, last patch for now - are you both satisfied with this one?

Theo

>From ff88a7ca0d331b25579b5bbd7f90e2a7e31d109f Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Mon, 5 Dec 2022 15:59:41 +0100
Subject: [PATCH] Add back in font-locking for pair in json-ts-mode

* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Add back in removed pair font-lock code.  Also alphabetize features.
(json-ts-mode): Use the new feature.

(bug#59833)
---
 lisp/progmodes/json-ts-mode.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el
index 101e873cf6..440ffb3128 100644
--- a/lisp/progmodes/json-ts-mode.el
+++ b/lisp/progmodes/json-ts-mode.el
@@ -93,6 +93,10 @@ json-ts-mode--font-lock-settings
    :override t
    '((escape_sequence) @font-lock-escape-face)
    :language 'json
+   :feature 'pair
+   :override t
+   `((pair key: (_) @font-lock-variable-name-face))
+   :language 'json
    :feature 'error
    :override t
    '((ERROR) @font-lock-warning-face))
@@ -156,7 +160,7 @@ json-ts-mode
   ;; Font-lock.
   (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings)
   (setq-local treesit-font-lock-feature-list
-              '((constant number string)
+              '((constant number pair string)
                 (escape-sequence)
                 (bracket delimiter error)))
 
-- 
2.34.1