Fork me on GitHub
#polylith
<
2023-10-13
>
jasonjckn05:10:13

Trying to help out our IntelliJ users, i'm getting a lot of unresolved references like here's 2 examples. In both cases the code for this is in bases/foo/src and the dependency for each of these is listed in bases/foo/deps.edn

tengstrand06:10:54

Maybe you can ask in the #C0744GXCJ channel?

👍 1
jasonjckn06:10:11

will do, i'm close to figuring this out anyways.

👍 1
jasonjckn06:10:58

By design IntelliJ treats every instance deps.edn as a separate module, with its own dependency list, and because we don't specify in inter-component dependencies (e.g. :local/root in one component to another), some of the symbols won't resolve.... when working in components/*/src Unless i've missed something. I may have a workaround, but it's patching the intellij XML project files.

jasonjckn06:10:50

if you add the inter dependencies like so, that solves it, but tedious to do in the UI

furkan3ayraktar07:10:56

I’ve not used Intellij for a long while now, so I do not know what the exact issue is. @U1G0HH87L, you still use Intellij, do you have any ideas? @U0J3J79FE, there are these two issues that might be related to this: https://github.com/cursive-ide/cursive/issues/2554 https://github.com/cursive-ide/cursive/issues/2828

👍 1
tengstrand07:10:49

I don't have these issues. To be honest, I'm not very good at these kind of stuff. The closest to expert I know is @U08BJGV6E.

jasonjckn07:10:14

is what i was missing, i had checked the box before, hoping it was the solution I needed, but it was glitching for me, i had to restart IDE to see effect.

jasonjckn07:10:26

hopefully this wasn't too obvious mistake, i searched all your docs for intellij instructions

jasonjckn07:10:23

search is broken for me on cljdoc 😕

tengstrand08:10:47

This is the new clj-doc based documentation that we are currently working on, which matches what's in the master branch. It hasn't been released yet as 0.2.18 (as you already know @U2BDZ9JG3).

furkan3ayraktar11:10:26

Yeah, I shared the snapshot version of the doc but I agree the search on cljdoc didn’t find anything when I search Intellij. Luckily I knew where it was 😂

😃 1
imre12:10:03

There can still be glitches with poly support in Cursive, I think this one I reported last week is somewhat related to Colin's work on poly support https://clojurians.slack.com/archives/C0744GXCJ/p1696509602605699

👍 1
lread15:10:41

Yeah, I shared the snapshot version of the doc but I agree the search on cljdoc didn’t find anything when I search Intellij. Luckily I knew where it wasI'm not yet sure what is going on here. I know the search index is cached client-side for a max of 1 day... but... I think that text has been there for a while. I've created an issue for cljdoc https://github.com/cljdoc/cljdoc/issues/847 @U2BDZ9JG3 and @U0J3J79FE, are any cljdoc searches within clj-poly 0.2.18-SNAPSHOT working for you?

seancorfield18:10:18

@UE21H2HHD Seems to work for me:

lread19:10:40

Thanks @U04V70XH6! If anybody notices any search issues for clj-poly on cljdoc, please do let me know here or over at #C8V0BQ0M6.

jasonjckn09:10:24

I created a script to patch the IntelliJ project *.iml file, it's not as necessary as I thought it was going to be, but still going to help with new users getting setup. It configures mainly the 'Mark as Sources/Test/Resources Root' and exclusions Here it is if anyone wants it, your mileage will vary. I put this in our build.clj file.

jasonjckn09:10:27

(ns build
  (:require
   [clojure.core.match :refer [match]]
   [clojure.data.xml :as xml]
   [clojure.walk :as walk]
   [clojure.string :as str]
   [clojure.tools.build.api :as b])
  (:import
   (java.nio.file Paths)
   (java.net URI)))


(defn aliases->paths [aliases re]
  {:pre [(set? aliases)]}
  (disj (->> (b/create-basis {:project "deps.edn", :aliases aliases})
             (all-paths )
             (filter #(re-matches re %))
             (map (fn [p]
                    (if (str/starts-with? p "/")
                      (.relativize
                        (Paths/get (URI. (str "file://" (System/getProperty "user.dir"))))
                        (Paths/get (URI. (str "file://" p))))
                      p)))
             (into #{}))
        "src"))



(defn patch-intellij-module-iml
  "Patches intellij *.iml file and automatically annotates/marks which folders are 'Sources Root' and 'Test Sources Root'."
  [_]
  (->> (xml/parse (java.io.StringReader. (slurp "NAME_OF_PROJECT.iml")))
       (walk/postwalk
         (fn [form]
           (match form
                  {:tag :content, :attrs {:url "file://$MODULE_DIR$"}, :content _}
                  {:tag     :content
                   :attrs   {:url "file://$MODULE_DIR$"}
                   :content (interpose "\n"
                                       (concat
                                         (for [p (aliases->paths #{:dev :+repl} #".*src$")]
                                           {:tag   :sourceFolder,
                                            :attrs {:url          (str "file://$MODULE_DIR$/" p)
                                                    :isTestSource "false"}})
                                         (for [p (aliases->paths #{:dev :+repl} #".*resources$")]
                                           {:tag   :sourceFolder,
                                            :attrs {:url  (str "file://$MODULE_DIR$/" p)
                                                    :type "java-resource"}})
                                         (for [p (aliases->paths #{:test} #".*src$")]
                                           {:tag   :sourceFolder,
                                            :attrs {:url          (str "file://$MODULE_DIR$/" p)
                                                    :isTestSource "true"}})
                                         (for [p (aliases->paths #{:test} #".*resources$")]
                                           {:tag   :sourceFolder,
                                            :attrs {:url  (str "file://$MODULE_DIR$/" p)
                                                    :type "java-test-resource"}})

                                         ;; excluded
                                         (for [p (concat
                                                   [
                                                    "/.clj-kondo/"
                                                    "/.cpcache/"
                                                    "/.dir-locals.el"
                                                    "/.dockerignore"
                                                    "/.gitignore"
                                                    "/.gitlab/"
                                                    "/.ignore"
                                                    "/.lsp/"
                                                    "/.nrepl-port"
                                                    "/.projectile"
                                                    ])]
                                           {:tag   :excludeFolder,
                                            :attrs {:url (str "file://$MODULE_DIR$" p)}})))}
                  ;;
                  :else
                  form)))

       (xml/indent-str)
       (str/split-lines)
       (remove (comp empty? str/trim))
       (map (fn [s] (str/replace s "/>" " />")))
       (interpose "\n")
       (apply str)
       (spit "NAME_OF_PROJECT.iml")))

tengstrand10:10:54

Nice that you were able to solve it, and thanks for sharing!

👍 1