cursive-ide / cursive

Cursive: The IDE for beautiful Clojure code
579 stars 7 forks source link

Refactoring keywords creates incorrect values #2051

Closed conan closed 5 years ago

conan commented 5 years ago

Say I have two namespaces,conan.egg and conan.omelette, and the second depends on the first.

(ns conan.egg
  (:require [clojure.spec.alpha :as s]))

(s/def :conan.egg.parts/yolk #{:hard :soft})
(ns conan.omelette
  (:require [conan.egg :as egg]
            [clojure.spec.alpha :as s]))

(s/def :conan.omelette/consistency :conan.egg.parts/yolk)

Now I want to simplify things by renaming the spec for yolk from :conan.egg.parts/yolk to :conan.egg/yolk, so I do a Refactor > Rename, and type in :conan.egg/yolk into the rename dialogue, and confirm the refactor.

This renames the spec in the egg namespace to ::yolk, which is annoying as that's not what i typed, but at least it will work; but it does the same thing in the omelette namespace, which won't work. It ends up looking like this:

(ns conan.omelette
  (:require [conan.egg :as egg]
            [clojure.spec.alpha :as s]))

(s/def :conan.omelette/consistency ::yolk)

That ::yolk spec is shorthand for :conan.omelette/yolk, which doesn't exist.

As a result it isn't safe to use Refactor to rename specs to have namespaces which match their current Clojure namespace, and in practice I find it's easier just not to think about it and assume it's not safe ever to use Refactor to rename specs.

conan commented 5 years ago

Autocomplete also does the same thing; if I type conan.egg/y and autocomplete in the conan.omelette namespace, it will autocomplete to ::yolk, which doesn't resolve in that namespace. Seems like all of this could be fixed by avoiding the shorthand altogether.

cursive-ide commented 5 years ago

I can't reproduce this - this definitely should work correctly. When I do the first rename the keyword in egg becomes ::yolk as you see, but the one in the omelette namespace becomes ::egg/yolk. Autocomplete similarly shows ::egg/yolk in the omelette namespace and ::yolk in the egg one.

It's possible your indexes have become corrupted - does "File->Invalidate caches and restart" help this?

conan commented 5 years ago

Ugh, yes it seems to be behaving itself after invalidating caches, sorry.