From 082700c8225b23ed292edf8877472183ac5f8101 Mon Sep 17 00:00:00 2001 From: Quentin Burgess Date: Fri, 27 Jun 2025 14:53:57 +0200 Subject: [PATCH 1/3] fix(chroma/make): huge delay on big units --- "\342\206\222chroma/-make.ch" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\342\206\222chroma/-make.ch" "b/\342\206\222chroma/-make.ch" index 18c6841..33f46bf 100644 --- "a/\342\206\222chroma/-make.ch" +++ "b/\342\206\222chroma/-make.ch" @@ -73,7 +73,7 @@ local -a __lines_list reply2 __wrd="${(Q)__wrd}" if [[ -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" ]] && \ - make -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" -pn | .fast-make-targets + make -f "${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]}" -Rrpq | awk '/^[a-zA-Z0-9][^$#\t=]*:/' | .fast-make-targets then if [[ "${reply2[(r)$__wrd]}" ]]; then (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}") From 0f149c9e03347574147b086bca10d4b2eb3089ee Mon Sep 17 00:00:00 2001 From: Quentin Burgess Date: Mon, 30 Jun 2025 18:25:17 +0200 Subject: [PATCH 2/3] fix(fast-make): code-style indentation --- .fast-make-targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fast-make-targets b/.fast-make-targets index e2cbd32..e78e205 100644 --- a/.fast-make-targets +++ b/.fast-make-targets @@ -18,7 +18,7 @@ local -a TARGETS rest=${rest[3,-1]} continue ;; - (\() # Variable of the form $(foobar) + (\() # Variable of the form $(foobar) open='(' close=')' ;; From 0e8d0ea493557d0f2ef6a32ea0e7e87a9370bc71 Mon Sep 17 00:00:00 2001 From: Quentin Burgess Date: Mon, 30 Jun 2025 18:25:50 +0200 Subject: [PATCH 3/3] feat(fast-make): allow shared cache One may enable the shared cache by setting the following prior to loading the fast-synthax-highlighting module ```sh typeset -gA FAST_HIGHLIGHT FAST_HIGHLIGHT[chroma-make-cache-global]=1 ``` This new implementation change the way the cached makefile' parsed content are expired. Prior to this commit, cached item expired after 7s. The new implementation get ride of the timer limit and replace it with a good old "is my file content's different" --- .fast-make-targets | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/.fast-make-targets b/.fast-make-targets index e78e205..10f8d0a 100644 --- a/.fast-make-targets +++ b/.fast-make-targets @@ -87,10 +87,44 @@ local -a TARGETS done } -if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then - .make-parseMakefile - FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS" - FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}" +# Cache generated parsing for 1sec per session or globally if configured, per Makefile path. +if [[ -n "${FAST_HIGHLIGHT[chroma-make-cache-global]}" ]]; then + # Determine Makefile path. + # TODO: find a way to expand path and resolve alias - this cause deduplicated cache file. + local makefile_path + makefile_path=${FAST_HIGHLIGHT[chroma-make-custom-dir]%/}/${FAST_HIGHLIGHT[chroma-make-custom-file]} + + # If not absolute, resolve to absolute path + [[ $makefile_path != /* ]] && makefile_path="$PWD/$makefile_path" + + # Generate a safe hash for the cache file name using sha1sum + local makefile_hash + makefile_hash=$(print -n -- "$makefile_path" | sha1sum | awk '{print $1}') + + # Generate a sha1sum hash from the input variable + local input var val target dep TAB=$'\t' tmp IFS= + local input_hash + input_hash=$(print -n -- "$input" | sha1sum | awk '{print $1}') + + # Generate the cache file path. + local cache_file + cache_file="/tmp/fast-highlight-make-cache-${makefile_hash}-${input_hash}" + + if [[ ! -f $cache_file ]]; then + # Clean up old cache files. + rm -rf /tmp/fast-highlight-make-cache-${makefile_hash}-* + # Generate new cache file. + .make-parseMakefile "$input" + print -r -- "${(j:;:)TARGETS}" >| "$cache_file" + fi + FAST_HIGHLIGHT[chroma-make-cache]="$(<$cache_file)" + FAST_HIGHLIGHT[chroma-make-cache-born-at]="0" +else + if [[ -z "${FAST_HIGHLIGHT[chroma-make-cache]}" || $(( EPOCHSECONDS - FAST_HIGHLIGHT[chroma-make-cache-born-at] )) -gt 7 ]]; then + .make-parseMakefile + FAST_HIGHLIGHT[chroma-make-cache-born-at]="$EPOCHSECONDS" + FAST_HIGHLIGHT[chroma-make-cache]="${(j:;:)TARGETS}" + fi fi reply2=( "${(s:;:)FAST_HIGHLIGHT[chroma-make-cache]}" )