From 2fe73b6bfc084ef22897e94e3c06becf294bf8e9 Mon Sep 17 00:00:00 2001 From: Paul Butcher Date: Sun, 29 Jun 2025 21:28:02 +0100 Subject: [PATCH 1/3] Invalidate cache when config.edn changes --- CHANGELOG.md | 1 + lib/src/clojure_lsp/classpath.clj | 9 +++------ lib/src/clojure_lsp/config.clj | 5 +++++ lib/src/clojure_lsp/shared.clj | 6 ++++++ lib/src/clojure_lsp/startup.clj | 5 +++++ 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41eb272d2..5c5695622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - New feature: Add `clojure-lsp/cyclic-dependencies` linter to detect cyclic dependencies between namespaces in the project. - New optional `:kondo-config-dir` setting to configure clj-kondo execution. - Parallelize and log the time spent on built-in linters execution. + - Fix caching issue when :source-aliases changes. #2081 ## 2025.06.13-20.45.44 diff --git a/lib/src/clojure_lsp/classpath.clj b/lib/src/clojure_lsp/classpath.clj index 7a4b0bae6..3d159a534 100644 --- a/lib/src/clojure_lsp/classpath.clj +++ b/lib/src/clojure_lsp/classpath.clj @@ -11,8 +11,7 @@ [clojure.set :as set] [clojure.string :as string]) (:import - (java.io ByteArrayOutputStream) - (java.security MessageDigest))) + (java.io ByteArrayOutputStream))) (set! *warn-on-reflection* true) @@ -23,10 +22,8 @@ (with-open [xin (io/input-stream file) xout (ByteArrayOutputStream.)] (io/copy xin xout) - (.toByteArray xout)) - algorithm (MessageDigest/getInstance "MD5") - raw (.digest algorithm bytes')] - (format "%032x" (BigInteger. 1 raw)))) + (.toByteArray xout))] + (shared/md5 bytes'))) (defn ^:private valid-project-spec? [root-path {:keys [project-path]}] (let [project-file (shared/to-file root-path project-path)] diff --git a/lib/src/clojure_lsp/config.clj b/lib/src/clojure_lsp/config.clj index ca59fe391..fc43c9adb 100644 --- a/lib/src/clojure_lsp/config.clj +++ b/lib/src/clojure_lsp/config.clj @@ -79,6 +79,11 @@ (resolve-global-config global-lsp-config-file)) project-configs)))) +(defn settings-hash [project-settings] + (-> (str project-settings) + (.getBytes) + (shared/md5))) + (defn ^:private jar-file->config [^java.io.File file config-paths] (with-open [jar (JarFile. file)] diff --git a/lib/src/clojure_lsp/shared.clj b/lib/src/clojure_lsp/shared.clj index 450115d4b..0828a031d 100644 --- a/lib/src/clojure_lsp/shared.clj +++ b/lib/src/clojure_lsp/shared.clj @@ -16,6 +16,7 @@ URLDecoder] [java.nio.charset StandardCharsets] [java.nio.file Paths] + [java.security MessageDigest] [java.util.regex Matcher])) (set! *warn-on-reflection* true) @@ -602,3 +603,8 @@ (def severity->level (set/map-invert level->severity)) + +(defn md5 [bytes] + (let [algorithm (MessageDigest/getInstance "MD5") + raw (.digest algorithm bytes)] + (format "%032x" (BigInteger. 1 raw)))) diff --git a/lib/src/clojure_lsp/startup.clj b/lib/src/clojure_lsp/startup.clj index 60f04f01d..134200a90 100644 --- a/lib/src/clojure_lsp/startup.clj +++ b/lib/src/clojure_lsp/startup.clj @@ -187,6 +187,7 @@ (merge (select-keys db-cache [:classpath :analysis-checksums :project-hash + :config-hash :kondo-config-hash :dependency-scheme :stubs-generation-namespaces])) @@ -196,6 +197,7 @@ (defn ^:private build-db-cache [db] (-> db (select-keys [:project-hash + :config-hash :kondo-config-hash :dependency-scheme :project-analysis-type @@ -255,10 +257,12 @@ (publish-task-progress producer (:finding-cache task-list) progress-token) (load-db-cache! root-path db*) (let [project-hash (classpath/project-specs->hash root-path settings) + config-hash (config/settings-hash project-settings) kondo-config-hash (lsp.kondo/config-hash (str root-path)) dependency-scheme (:dependency-scheme settings) dependency-scheme-changed? (not= dependency-scheme (:dependency-scheme @db*)) use-db-analysis? (and (= (:project-hash @db*) project-hash) + (= (:config-hash @db*) config-hash) (= (:kondo-config-hash @db*) kondo-config-hash) (not dependency-scheme-changed?)) fast-startup? (or use-db-analysis? @@ -276,6 +280,7 @@ (when-let [classpath (classpath/scan-classpath! components)] (swap! db* assoc :project-hash project-hash + :config-hash config-hash :kondo-config-hash kondo-config-hash :analysis-checksums (if dependency-scheme-changed? nil (:analysis-checksums @db*)) :analysis (if dependency-scheme-changed? nil (:analysis @db*)) From 23299368073f6631b0f806e253a0958d096ac652 Mon Sep 17 00:00:00 2001 From: Paul Butcher Date: Mon, 30 Jun 2025 09:50:04 +0100 Subject: [PATCH 2/3] config-hash -> settings-hash --- lib/src/clojure_lsp/startup.clj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/clojure_lsp/startup.clj b/lib/src/clojure_lsp/startup.clj index 134200a90..a2bc63d40 100644 --- a/lib/src/clojure_lsp/startup.clj +++ b/lib/src/clojure_lsp/startup.clj @@ -187,7 +187,7 @@ (merge (select-keys db-cache [:classpath :analysis-checksums :project-hash - :config-hash + :settings-hash :kondo-config-hash :dependency-scheme :stubs-generation-namespaces])) @@ -197,7 +197,7 @@ (defn ^:private build-db-cache [db] (-> db (select-keys [:project-hash - :config-hash + :settings-hash :kondo-config-hash :dependency-scheme :project-analysis-type @@ -257,12 +257,12 @@ (publish-task-progress producer (:finding-cache task-list) progress-token) (load-db-cache! root-path db*) (let [project-hash (classpath/project-specs->hash root-path settings) - config-hash (config/settings-hash project-settings) + settings-hash (config/settings-hash project-settings) kondo-config-hash (lsp.kondo/config-hash (str root-path)) dependency-scheme (:dependency-scheme settings) dependency-scheme-changed? (not= dependency-scheme (:dependency-scheme @db*)) use-db-analysis? (and (= (:project-hash @db*) project-hash) - (= (:config-hash @db*) config-hash) + (= (:settings-hash @db*) settings-hash) (= (:kondo-config-hash @db*) kondo-config-hash) (not dependency-scheme-changed?)) fast-startup? (or use-db-analysis? @@ -280,7 +280,7 @@ (when-let [classpath (classpath/scan-classpath! components)] (swap! db* assoc :project-hash project-hash - :config-hash config-hash + :settings-hash settings-hash :kondo-config-hash kondo-config-hash :analysis-checksums (if dependency-scheme-changed? nil (:analysis-checksums @db*)) :analysis (if dependency-scheme-changed? nil (:analysis @db*)) From 067594fb8f45ba603e2fd5bd0eab9de51493de31 Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Mon, 30 Jun 2025 12:30:24 -0300 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f1c67c1..1eeb85bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,6 @@ - New feature: Add `clojure-lsp/cyclic-dependencies` linter to detect cyclic dependencies between namespaces in the project. - New optional `:kondo-config-dir` setting to configure clj-kondo execution. - Parallelize and log the time spent on built-in linters execution. - - Fix caching issue when :source-aliases changes. #2081 - Fix #1851: Error when source files have non-ASCII characters in their path or name - Fix caching issue when :source-aliases changes. #2081 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy