Subject: bug#75580: 30.0.93; statements inside string interpolation for csharp modes are fontified incorrectly

From: Jostein Kjønigsen <[email-masked]>
Date: Sat, 1 Feb 2025 22:20:54 +0100

On 2/1/25 13:06, Jostein Kjønigsen wrote:
> I don’t remember exactly why things ended up the way they did to be honest.
>
> I tried tweaking around with the rules to see if I could get better results, but ended up with different kinds of regressions.

I had time for a little effort. :)

Attached is a pretty minimal patch which seems to work for me. I've 
guarded the changes behind a grammar-check, but I must admit I'm not 
sure if that is needed or not.

Basically I remove the override, and add more specific rules for the 
parts which goes "missing" without it.

Anyone have any opinions on the form of patch? Anyone want to do any 
additional testing?

Let me know! If not, I guess Eli you can install this at your own leisure.

--
Jostein
From 168fb11e4bad985a282effcb9fe56fc49d24dc53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <[email-masked]>
Date: Sat, 1 Feb 2025 22:16:36 +0100
Subject: [PATCH] lisp/progmodes/csharp-mode.el: Improve string-interpolation

Correctly fontify expressions inside string-interpolations.
---
 lisp/progmodes/csharp-mode.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3e07da40cdd..939a4ed409b 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -736,6 +736,12 @@ csharp-ts-mode--test-interpolated-string-text
     (treesit-query-compile 'c-sharp "(interpolated_string_text)" t)
     t))
 
+(defun csharp-ts-mode--test-string-content ()
+  "Return non-nil if (interpolated_string_text) is in the grammar."
+  (ignore-errors
+    (treesit-query-compile 'c-sharp "(string_content)" t)
+    t))
+
 (defun csharp-ts-mode--test-type-constraint ()
   "Return non-nil if (type_constraint) is in the grammar."
   (ignore-errors
@@ -824,10 +830,12 @@ csharp-ts-mode--font-lock-settings
      (boolean_literal) @font-lock-constant-face)
 
    :language 'c-sharp
-   :override t
    :feature 'string
    `([(string_literal)
       (verbatim_string_literal)
+      ,@ (when (csharp-ts-mode--test-string-content)
+           '((string_content)
+             "\""))
       ,@(if (csharp-ts-mode--test-interpolated-string-text)
             '((interpolated_string_text)
               (interpolated_verbatim_string_text)
-- 
2.39.5