]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve fontification of docker-files
authorJostein Kjønigsen <jostein@kjonigsen.net>
Fri, 21 Feb 2025 12:59:26 +0000 (13:59 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 23 Feb 2025 08:21:15 +0000 (09:21 +0100)
Add support for fontifying the following grammar-elements:
- image-declarations (image-name, image-tag & image alias)
- strings in more general terms
- string-expansion statements
- treat path-values as strings
- identifiers names for ENV and ARG statements
- argument values for ENV and ARG statements
* lisp/progmodes/dockerfile-ts-mode.el (dockerfile-ts-mode)
(dockerfile-ts-mode--font-lock-settings): Improve fontification.
(Bug#76481)

(cherry picked from commit 2044f6d9592cdec3a916c0d3c0a8a079c479db61)

lisp/progmodes/dockerfile-ts-mode.el

index 1594c93451b6fb763a2480b4a738cf6b8412211d..016bb2f7272b53fbcad6849d731a93a55c7ba441 100644 (file)
@@ -97,7 +97,9 @@ continuation to the previous entry."
 
    :language 'dockerfile
    :feature 'image-spec
-   '((image_spec) @font-lock-constant-face)
+   '((image_name)  @font-lock-function-name-face
+     (image_tag)   @font-lock-function-name-face
+     (image_alias) @font-lock-function-name-face)
 
    :language 'dockerfile
    :feature 'keyword
@@ -113,7 +115,29 @@ continuation to the previous entry."
 
    :language 'dockerfile
    :feature 'string
-   '((double_quoted_string) @font-lock-string-face)
+   '((single_quoted_string) @font-lock-string-face
+     (double_quoted_string) @font-lock-string-face
+     (json_string) @font-lock-string-face
+     (path) @font-lock-string-face
+     (arg_instruction
+      default: (unquoted_string) @font-lock-string-face)
+     (env_pair
+      value: (unquoted_string) @font-lock-string-face))
+
+   :language 'dockerfile
+   :feature 'string-expansion
+   :override t
+   '((expansion
+      (["$" "{" "}"] @font-lock-variable-name-face))
+     (expansion
+      (variable) @font-lock-variable-name-face))
+
+   :language 'dockerfile
+   :feature 'identifiers
+   '((arg_instruction
+      name: (unquoted_string) @font-lock-variable-name-face)
+     (env_pair
+      name: (unquoted_string) @font-lock-variable-name-face))
 
    :language 'dockerfile
    :feature 'error
@@ -164,7 +188,7 @@ Return nil if there is no name or if NODE is not a stage node."
                 dockerfile-ts-mode--font-lock-settings)
     (setq-local treesit-font-lock-feature-list
                 '((comment)
-                  (keyword string)
+                  (keyword string string-expansion identifiers)
                   (image-spec number)
                   (bracket delimiter error operator)))