From a0d3cd71820b4deb6894ab41c43d530651f724c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jostein=20Kj=C3=B8nigsen?= Date: Fri, 21 Feb 2025 13:59:26 +0100 Subject: [PATCH] Improve fontification of docker-files 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 | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/dockerfile-ts-mode.el b/lisp/progmodes/dockerfile-ts-mode.el index 1594c93451b..016bb2f7272 100644 --- a/lisp/progmodes/dockerfile-ts-mode.el +++ b/lisp/progmodes/dockerfile-ts-mode.el @@ -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))) -- 2.39.5