Skip to content

Invalidate cache when config.edn changes #2083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions lib/src/clojure_lsp/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)]
Expand Down
5 changes: 5 additions & 0 deletions lib/src/clojure_lsp/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions lib/src/clojure_lsp/shared.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))))
5 changes: 5 additions & 0 deletions lib/src/clojure_lsp/startup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
(merge (select-keys db-cache [:classpath
:analysis-checksums
:project-hash
:config-hash
:kondo-config-hash
:dependency-scheme
:stubs-generation-namespaces]))
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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*))
Expand Down
Loading
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