Fork me on GitHub
#cursive
<
2022-04-15
>
tony.kay00:04:07

Running Cursive 1.12.2-2021-3 and I’m seeing a new, somewhat annoying behavior: If a ns is required twice with different options (unfortunately happens frequently), then Cursive is now ignoring the first one completely. E.g.

(:require
  [a :refer [b]]
  [a :as A])
results in b being shown as undefined in the source, even though this works fine in Clojure and was fine in prior versions of Cursive. Is there a setting or something I accidentally changed?

cfleming00:04:03

Hmm, I’ll check that, thanks. The ns parsing did change in the latest version, I have a couple of things to fix. I’ll get a new version out ASAP.

tony.kay00:04:18

hopefully on the road to a “refactor -> Move function to new ns” that works with CLJC? 😄

1
cfleming00:04:47

Yes, that’s all hopefully coming soon after the new NS rewriting stuff is complete - that was the major missing piece.

cfleming00:04:07

BTW is there a reason that you can’t combine the two of those into one require?

tony.kay00:04:43

none at all…it’s one of those things where other ppl on the team don’t check for it, and auto-fix a missing alias and accidentally dupe a require

tony.kay00:04:09

so there are hundreds of files in this work project where that has happened, and now with this cursive release I suddenly have LOTs of error indicators and an inability to jump to the things without first patching all these ns decls. I’m personally one of those guys that sorts the nses so I can easily see dupes…but not everyone is so…meticulous 😄

cfleming01:04:24

So you’d be happy for optimise imports to fix that up?

tony.kay08:04:49

Assuming it doesn't break things in cljc files, and doesn't remove unused automatically... Yes that would be swell. The other problem though is that sometimes there are two requires that alias to different names... So conflict resolution would have to pick one and refactor the uses of the other.

cfleming09:04:25

So you might have something like (:require [abc :as a] [abc :as b]) with uses of both a/something and b/something?

tony.kay15:04:16

Yep. Unfortunately

cfleming21:04:16

And that used to work in Cursive? I’m genuinely surprised!

cfleming23:04:58

Fix for this is out in 1.12.3-eap1.

👍 1
Björn Ebbinghaus00:04:10

So… Macros defining symbols don't work any more… They are flagged as "cannot be resolved". I have warnings all over my code, won't get autocompletion or navigation to symbols. And if I use only symbols defined by these macros, that namespace gets flagged as an "unused require" and deleted by "optimize imports". I had this problem in the past a few times, that the Quick Fix "Resolve as…" didn't do anything. (see https://github.com/cursive-ide/cursive/issues/2640 ) I just invalidated caches and restarted, and it didn't do anything. Any hints what's going on?

Björn Ebbinghaus00:04:12

1.12.2-2022.1 with IntelliJ 2022.1

cfleming00:04:28

Sorry for the hassle, can you give me an example of something that’s failing? Are these macros which you have used “Resolve as…” with?

Björn Ebbinghaus00:04:39

Symbols defined by`mount.core/defstate` in my own project. Symbols defined by com.fulcrologic.guardrails/>defn in a dependency, in my project or even defined in the same file. I don't seem to get autocompletion for macros, when in a CLJS file, in general. But once I type it out manually, I can navigate to the symbol.

aratare00:04:15

@U4VT24ZM3 So I also had this problem. And I found that if I resolve it as something else, then resolve back to the original then my code is happy again. Perhaps you can try the same?

Björn Ebbinghaus00:04:25

I have the following entry in my ClojureProjectResolveSettings.xml:

<item key="com.fulcrologic.guardrails.core/>defn" resolves-as="clojure.core/defn" />
I removed that line from the config, and used the Quick Fix Menu to add it again. Now the problem is gone for things defined by >defn I did the same for defstate. Just removing and readding the line to the file manually didn't seem to work. Using the Quick Fix did work, but the defstate line is not back in the file.

aratare00:04:48

So for >defn I tried resolving it to def then back to defn and it's happy. Same for pretty much all other macros I use.

Björn Ebbinghaus00:04:03

@U013F1Q1R7G Yes. Something like that seemed to help...

Björn Ebbinghaus00:04:46

Weird… As I did reindex and invalidated caches and reloaded deps, a few times and nothing seems to fix it…

aratare00:04:26

Yeah this one is a bit persistent. I tried all of them, and even removing .idea and reimport the entire project, still nothing could fix it.

Björn Ebbinghaus00:04:17

Oh, no… it is broken again, for defstate. Maybe it was still indexing when I looked before…

Björn Ebbinghaus00:04:03

I have to look into this tomorrow. It's way too late for this..

cfleming01:04:59

Several people have mentioned that symbols that they have customised with Resolve as… sometimes lose their customisation. Usually changing the customisation and then changing it back will fix it, but I’ve never heard anyone saying it is that persistent. Unfortunately I’ve never managed to reproduce it since it seems to be a transient problem. I’ll pick over the code and see if I can figure it out.

aratare01:04:46

@U0567Q30W sorry I don’t mean “persistent” in the sense that it happens all the time. I mean that it survives even between cache invalidation.

cfleming01:04:41

Yes, it doesn’t seem to be a problem with the caches. It’s a really weird problem, since the config seems to remain in place. I can’t think of anything that would make it sporadic.

aratare01:04:47

It is indeed very weird since it happens at random and I can’t figure out what triggers it, e.g. whether I’ve made a booboo somewhere. I just had the entire project filled with “cannot resolve” errors a few days ago and it happened out of nowhere, i.e. everything was perfectly fine the previous day.

aratare01:04:56

Re-resolving all the macros is my current workaround, and luckily it only happens every blue moon so not that big of deal. Just the amount of macros I have to go through each time is a bit problematic 😅

cfleming01:04:47

Just to be clear, does it suddenly happen to a lot of macros at once?

aratare01:04:22

Yep. I have things like mount’s defstate, fulcro’s defresolver or defmutation (just to name a few) and suddenly they all started throwing errors

cfleming01:04:36

Does restarting the IDE help? Just in case you tried that.

aratare01:04:06

So I tried restarting the IDEA, invalidating the cache, refreshing deps via the Clojure Deps tool, removing the project and reimporting it again, hard removing the project (remove .idea) and reimporting it

aratare01:04:26

Re-resolve was my last resort (more like last hoorah 😂), and it worked

🎉 1
cfleming01:04:36

That’s…. a comprehensive list of attempts 🙂

cfleming01:04:55

That is really weird.

aratare01:04:33

That’s why I said “persistent” because it somehow survives all those 😅

cfleming01:04:54

I think that qualifies for the “persistent” tag.

aratare01:04:58

👍:skin-tone-3:

Björn Ebbinghaus19:04:22

@U0567Q30W When I started IntelliJ again today, the marcos were not resolved again.

cfleming21:04:41

Ugh, sorry… I’m going to look at that today.

aratare06:04:17

@U0567Q30W I'm seeing the same behaviour as @U4VT24ZM3 today, even after re-resolving yesterday. I'm not sure what I did aside from simply closing Cursive last night.

aratare06:04:14

I'm throwing out a wild (and uneducated) guess here, but could be something to do with how Cursive is caching these resolutions?

aratare06:04:47

I think this has been mentioned before, but this behaviour has only appeared after the latest Cursive update.

wilkerlucio11:04:26

IME it usually happens when I restart the IDE here, closing all and open again, and the problem comes back

1
xceno17:04:40

So, I want to add that I used to fix this issue by just re-resolving, but I can't even resolve as... anymore. The quick-tip doesn't show and the action also isn't available in the action-list. I tried this with the latest IntelliJ and the current cursive EAP, but I had this problem with Intellij 2021.3.3 and curisve 1.12.1 already. But it seems you guys are all still able to re-resolve stuff?

cfleming20:04:16

@U012ADU90SW Someone else reported this yesterday on the mailing list, I’ll look at that today.

🙏 1
wilkerlucio20:04:30

hope you can find the cause soon @U0567Q30W, this one is being a big bummer, will be great to have it fixed, please let me know if there is any data/dumps that may help you figure it out

cfleming21:04:15

@U066U8JQJ Yeah, this one is a pain, I’m sorry. I have an idea of how to fix it, I’ll try it this morning and get a dev build out so people can test it. I worked with aratare the other day who was kind enough to debug for me, and I can’t find anything wrong 😕

cfleming05:04:52

Has everyone suffering from this bug only experienced it on IntelliJ 2022.1? Did anyone ever experience it on 2021.3?

aratare05:04:02

I remember updating to some newer version of Cursive on 2021.3, can’t remember if it has started happening then. It’s only when I upgraded to 2022.1 that I start noticing this problem. But it could be just me not paying attention closely enough previously.

cfleming05:04:05

Yeah, with sporadic problems it can be really hard to tell. But this code hasn’t changed in a long time, so I suspect some platform change is causing it. But I’m really struggling to imagine what it might be.

cfleming05:04:06

I have seen some indexing weirdness under 2022.1, so I suspect there might be an underlying bug there, but there’s obviously something on the Cursive side too since the resolve customisation bit is all Cursive.

cfleming05:04:32

cc @U08BJGV6E @UGMAVSMUM I think you guys were getting this too. Any idea if it ever happened on 2021.3?

aratare05:04:19

@U0567Q30W If it’s not too urgent, I can downgrade back to 2021.3 later today and give it a spin

cfleming05:04:39

@U013F1Q1R7G Thanks, I’d appreciate that. No urgency, apart from the fact that the bug sucks, of course 🙂. I’m going to go through the Pathom tutorials this evening, since for whatever reason it seems to happen a lot with Pathom.

cfleming05:04:58

Hopefully I can reproduce it.

imre07:04:22

@U0567Q30W I had it on 2021.3 yes. I think the issue started appearing around the time there was some sort of a config schema change for Cursive

imre07:04:47

yeah, that's the one

cfleming07:04:15

Hmm. I’ll look at the changes there, but I don’t think they have anything to do with the customisation code.

imre07:04:34

I also noticed that if I try to persist code style settings to the project, they wouldn't be used the next time I load the project

imre07:04:04

but I hadn't used that before said release so wouldn't know if it had been working earlier

cfleming07:04:10

Really? I’ll look at that.

imre07:04:30

so, say, I generally want to align map values but for some projects I don't

cfleming07:04:45

Right, so you’d set formatting to the Project scheme, but that doesn’t get persisted?

imre07:04:29

Let me do a repro on what exactly I see there

cfleming07:04:15

So I can’t see how that change could have had anything to do with this problem. That change and this problem don’t have any intersecting code at all.

imre07:04:06

It is still strange that these are all issues with project-wide settings, which started appearing after a change to how settings are stored

imre07:04:23

I'll open a new issue for the code style one

👍 1
cfleming07:04:45

Right. But the settings are stored differently (the resolution customisation and the formatting config).

cfleming07:04:36

That’s why I asked about the IntelliJ version, I was wondering if something had changed in the platform that might have affected config storage somehow.

imre08:04:02

I'm still on 2021.3.3 btw with latest cursive eap

cfleming08:04:19

And you’re also seeing the resolution customisation problem?

imre08:04:34

since about the release you linked

imre08:04:23

see here for the earliest report of the issue that I know of: https://clojurians.slack.com/archives/C0744GXCJ/p1645540040848229

cfleming08:04:37

@U013F1Q1R7G No need to downgrade, thanks 🙂

cfleming08:04:50

Ah, thanks I was looking for that one.

cfleming08:04:59

So that is prior to the config change.

imre08:04:18

the config change was sometime in January, no?

cfleming08:04:52

Yes, but AJ wasn’t on that build, the change was in 1.12.2-eap2.

imre08:04:00

oh gotcha

imre08:04:39

silly me assuming everyone else would be running latest eap all the time 😅

xceno08:04:01

> Has everyone suffering from this bug only experienced it on IntelliJ 2022.1? Did anyone ever experience it on 2021.3? Yes. Cursive hasn't lost the resolution settings in a while, but I was unable to resolve as... for at least a few months. Yesterday I upgraded to the latest intellij and downgraded again to 2021.3. That's when all resolutions didn't work anymore. The settings are still there, they just have no effect. Afterwards I upgraded to the latest cursive eap, but to no avail. If there's any data dump or anything I can help with, let me know

cfleming08:04:59

Yes, the Resolve as… thing is also really strange. I’ll think about data to dump, thanks. I tried with aratare the other day and everything was hunky-dory.

xceno09:04:50

Okay, so here's a small update. The embarrassing part first: I somehow disabled the resolve action in Preferences->Editor->Intentions and because I use the Intellij Settings-Sync, of course it got disabled on all my machines and versions, that's why I thought it's a bug :man-facepalming: TBH, I didn't even realize that disabling Intentions was possible. Anyway: I re-enabled the resolve action and then re-resolved everything. I also re-started and disabled/enabled various other plugins several times. There was one instance where cursive lost the resolutions again: cursive ok -> clojure extras enabled -> lost resolves But I couldn't reproduce it. Now I've got cursive and clj-extras enabled and re-started Intellij several times to make sure, but everything seems fine for now. Intellij 2021.3 + cursive 1.12.3-eap1

Björn Ebbinghaus14:04:31

@U0567Q30W The "Resolve as" intention is missing entirely if the symbol couldn't be resolved because it was defined in a macro. This is also the case, if the symbol in question is defined in a library. So not only I have to "resolve as" my own symbols, but symbols in libraries as well. Maybe Cursive should be more "trustful". Warn about an unresolved symbol, but assume that it is a real symbol. State now is that if Cursive can't resolve the symbol, it is like it doesn't exist. :requires are marked as "unused" and removed by optimize import, and you can't resolve that symbol as something else… This makes the whole situation just worse. To a point where I can't really use Cursive for now, except if I keep it running all the time, or I have to resolve everything again.

Björn Ebbinghaus14:04:45

I think false-negatives would be more forgiving than false-positives.

cfleming05:04:22

@U4VT24ZM3 I agree that swapping out false positives for negatives is a better solution, but it’s not always easy unfortunately. I think I can make the Resolve as… intention more robust in that case, and also the import optimisation. I’ll look at that now.

tony.kay15:04:39

I got it to start working again by reverting to Nov 29th (install plugin from disk) release of Cursive on 2021.3.2. I did not notice this issue until I updated Cursive past that version of Cursive, if it is any help.

Björn Ebbinghaus15:04:41

That seems to be the only way for me to use Cursive for now… 😞 @U0567Q30W Is it possible to provide a version 1.12.1 for IntelliJ 2022.1? And: How about a fallback to the clj-condo config for symbol resolution?

imre15:04:51

> fallback to the clj-condo config for symbol resolution While this would be super nice to have, don't think it would be particularly easy to support. kondo's config mechanism is rather advanced with hooks and imported configs, so to be sure you'd have to invoke it as a tool to get correct info.

Björn Ebbinghaus15:04:29

@U08BJGV6E As a fallback, you would just have to read the :lint-as map in the config.edn

☝️ 1
Björn Ebbinghaus15:04:16

This could even serve as a way to prepopulate the resole settings when importing a new project with existing clj-kondo config.

imre15:04:38

That only work as far as you have a :lint-as map there. Not if you use :config-paths which refer to configs that have their own :lint-as maps and so on

Björn Ebbinghaus15:04:14

Still better than nothing. 🙂

Björn Ebbinghaus15:04:57

And even with :config-paths clj-kondo already copies them into the .clj-kondo folder. Wouldn't be so hard to read all configs and merge the :lint-asmaps.

imre16:04:22

As someone being on the receiving end of "shouldn't be so hard" assumptions, I'm generally cautious in that regard.

Björn Ebbinghaus16:04:02

@U08BJGV6E Being cautious with such assumptions is good. 👍 But maybe we are talking about different things? I don't propose supporting custom hooks for symbols. Just the plain symbol->symbol resolution. Supporting custom hooks is hard, but reading some .edn files could be as simple as:

(defn get-lint-as [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)))
    {}))

(get-lint-as ".clj-kondo/config.edn")

Björn Ebbinghaus16:04:33

Just for completeness:

(defn lint-as->cursive-resolve-settings [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"))
This would emit the config usable for Cursive. (minus the HTML character escaping)

imre17:04:34

I could imagine this as a repl command even

imre18:04:32

What I'm cautious about is that as you said this is far from complete. In the project I'm on right now it wouldn't help due to significant use of imported configs and hooks. But if this becomes a feature in cursive, it will have to be maintained and extended as people start depending on it and that's always a burden. That being said, I'd love config sharing between kondo and cursive.

cfleming21:04:44

@U4VT24ZM3 Unfortunately the first report of this error used Cursive 1.12.1, so even that version is not immune.

cfleming21:04:58

re: taking config from clj-kondo, I’ve been looking at something similar for cljfmt, too. IntelliJ doesn’t make it easy to update the config dynamically when the file changes unfortunately, but there is some prior art there (EditorConfig) so I can look at how that works. However, I’m not convinced it will help in this case. I did some debugging with aratare the other day and his config was correct, both in the editor and in memory, so 🤷 I really have absolutely no idea what is happening with this one, and I can’t reproduce it no matter what I do. I’m going to prepare some more debugging to try today.

aratare01:04:39

@U0567Q30W One thing I haven’t tried is to pull down the repo from GH into a different place and import it into IntelliJ (so hard hard reimport). I’ll try this later today, and if the bug is present then perhaps you can try it on your machine.

cfleming03:04:17

@U013F1Q1R7G Thanks, I’d be interested to know. I was planning to get a copy of your repo and try it out.

cfleming12:04:22

Just to let everyone on this thread know that there is an EAP release out (1.12.3-eap2) which I’m hoping fixes this issue.

🎉 2
Björn Ebbinghaus12:04:51

At the first look it seems to work. 👍:skin-tone-2: The only unresolved symbols are the usual JavaScript stuff.

cfleming12:04:35

Fantastic! Thanks for letting me know. I’m going to work on the JavaScript stuff next as part of ClojureDart support.

Björn Ebbinghaus12:04:16

And reader conditionals in ns, but that is another, less critical problem.

cfleming12:04:09

I’m interested to hear about that one, but perhaps in another thread (or issue) to keep this one on topic.

wilkerlucio16:04:56

@U0567Q30W have been testing here and so far its working as expected! 😄

cfleming23:04:39

@U066U8JQJ Great, thanks for letting me know, that’s great news!

genekim20:05:31

FWIW, I was having this problem of >defn functions not showing up in the Structure window — it was fixed after upgrading Cursive version. 🎉

markaddleman17:04:18

I'd like to script a few IntelliJ tasks but the existing scripting languages are unpalatable. Can I use Clojure(script) to orchestrate IntelliJ?

cfleming21:04:37

So there is a type of IDE console, and at one point it did actually support Clojure, which is why Clojure-Kit is a thing. But it never seemed very official or very well documented, and I never managed to figure it out. There’s also just been a plugin developers’ webcast about dynamically modifying the IDE which I haven’t had time to watch yet.

cfleming21:04:24

All this is to say, there isn’t a great option at the moment. What sort of things do you want to script?

markaddleman21:04:29

I've got a really simple thing that I want to automate. We manage our tasks using Jira. When I pick up new work, I use IntelliJ's "switch task" to create a new work context and automatically create a branch. Then, I manually create a new "repl" file which serves as the experimentation and testing namespace for the work. I copy the repl file from a read-only repl.clj file and then I rename the new repl file as repl-<jira ticket>.clj. It's a very simple workflow but it would be convenient to automate it.

markaddleman21:04:01

I'll take a look at the scripting console. I'm sure this could easily be done in one of the existing, supported languages but I'm a curmudgeon when it comes to learning new languages 🙂