cursive
cursive copied to clipboard
Use clj-kondo config for `resolve as` when available
Recently many projects are adopting clj-kondo, would be nice if Cursive could pick up the :lint-as
configurations and use those from clj-kondo config, so users wouldn't have to configure on each machine.
This code reads the configs recursively and emits XML for Cursive.
(require
'[clojure.xml :as xml]
'[clojure.edn :as edn])
(defn get-lint-as
"Returns the :lint-as map from a config. Follows config-paths recursivly and merges the results."
[path-to-config]
(if-let [config (edn/read-string (slurp path-to-config))]
(let [{:keys [config-paths lint-as] :or {config-paths [], lint-as {}}} config]
(->> config-paths
(pmap (fn [config-path] (get-lint-as (str ".clj-kondo/" config-path "/config.edn"))))
(reduce merge lint-as)))
{}))
(defn lint-as->cursive-resolve-settings
"Emits a XML for Cursive.
Does not escape special symbols like `>`"
[lint-as-map]
(xml/emit
{:tag :project
:attrs {:verison 4}
:content
[{:tag :component
:attrs {:name "ClojureProjectResolveSettings"}
:content
(conj
(for [[k resolve-as] lint-as-map]
{:tag :item
:attrs {:key (str k) :resolve-as (str resolve-as)}})
{:tag :currentScheme
:content ["PROJECT"]})}]}))
(lint-as->cursive-resolve-settings (get-lint-as ".clj-kondo/config.edn"))
Link to the discussion in Slack: https://app.slack.com/client/T03RZGPFR/C0744GXCJ/thread/C0744GXCJ-1649982190.489009