Skip to content

Commit

Permalink
EXPERIMENT: Does a memoize cache fix the timeout?
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Monroe committed May 23, 2024
1 parent 452582d commit 7b94439
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/src/clojure_lsp/feature/diagnostics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

(set! *warn-on-reflection* true)

(def ^:dynamic *uri->filename* nil)

(def diagnostic-types-of-unnecessary-type
#{:clojure-lsp/unused-public-var
:redefined-var
Expand Down Expand Up @@ -43,7 +45,7 @@
(defn ^:private unused-public-var->finding [element kondo-config]
(let [keyword-def? (identical? :keyword-definitions (:bucket element))
kondo-config (if (:ns element)
(kondo-config-for-ns kondo-config (:ns element) (-> element :uri shared/uri->filename))
(kondo-config-for-ns kondo-config (:ns element) (-> element :uri *uri->filename*))
kondo-config)]
{:uri (:uri element)
:row (:name-row element)
Expand All @@ -59,7 +61,7 @@
:type :clojure-lsp/unused-public-var}))

(defn ^:private exclude-public-diagnostic-definition? [db kondo-config definition]
(let [kondo-config (kondo-config-for-ns kondo-config (:ns definition) (-> definition :uri shared/uri->filename))
(let [kondo-config (kondo-config-for-ns kondo-config (:ns definition) (-> definition :uri *uri->filename*))
excluded-syms-regex (get-in kondo-config [:linters :clojure-lsp/unused-public-var :exclude-regex] #{})
excluded-defined-by-syms-regex (get-in kondo-config [:linters :clojure-lsp/unused-public-var :exclude-when-defined-by-regex] #{})
excluded-metas (get-in kondo-config [:linters :clojure-lsp/unused-public-var :exclude-when-contains-meta] #{})
Expand Down Expand Up @@ -292,16 +294,17 @@
(different-aliases db-of-uris project-db kondo-config))))

(defn ^:private finalize-findings! [findings reg-finding!]
(let [uri->filename (memoize shared/uri->filename)]
(run! #(reg-finding! (assoc % :filename (uri->filename (:uri %)))) findings))
(run! #(reg-finding! (assoc % :filename (*uri->filename* (:uri %)))) findings)
nil)

(defn custom-lint-project!
[db {:keys [reg-finding! config]}]
(-> (findings-of-project db config)
(finalize-findings! reg-finding!)))
(binding [*uri->filename* (memoize shared/uri->filename)]
(-> (findings-of-project db config)
(finalize-findings! reg-finding!))))

(defn custom-lint-uris!
[uris db {:keys [reg-finding! config]}]
(-> (findings-of-uris uris db config)
(finalize-findings! reg-finding!)))
(binding [*uri->filename* (memoize shared/uri->filename)]
(-> (findings-of-uris uris db config)
(finalize-findings! reg-finding!))))

0 comments on commit 7b94439

Please sign in to comment.