]> git.eshelyaron.com Git - emacs.git/commitdiff
lisp/progmodes/csharp-mode.el: Improve string-interpolation
authorJostein Kjønigsen <jostein@kjonigsen.net>
Sat, 1 Feb 2025 21:16:36 +0000 (22:16 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Feb 2025 08:45:12 +0000 (09:45 +0100)
Correctly fontify expressions inside string-interpolations.
(Bug#75580)

(cherry picked from commit 535eec814484c437443051e0b6d2d654eef9b7e0)

lisp/progmodes/csharp-mode.el

index 9d19456179bd5d64e099b0d485a055ef5ada073c..b26ce4e34a5c27141dca7523ee984bf252ab7955 100644 (file)
@@ -736,6 +736,12 @@ compilation and evaluation time conflicts."
     (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
@@ -830,10 +836,12 @@ compilation and evaluation time conflicts."
      (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)