Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Variable with Parinfer breaks code #2786

Closed
luontola opened this issue Apr 5, 2023 · 3 comments
Closed

Introduce Variable with Parinfer breaks code #2786

luontola opened this issue Apr 5, 2023 · 3 comments
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@luontola
Copy link

luontola commented Apr 5, 2023

Given Parinfer is enabled and we have the following code. (The only difference between the functions is a longer name in :aaa vs :aaaa.)

(ns example)

(defn good []
  (merge {}
         (assoc {}
           :aaa {"a" "1"
                 "b" "2"}
           :b :c)))

(defn bad []
  (merge {}
         (assoc {}
           :aaaa {"a" "1"
                  "b" "2"}
           :b :c)))

Select the {"a" "1" "b" "2"} map and do the Introduce Variable (Ctrl+Alt+V) refactoring for both functions. In the good function the variable is created without problems, but in the bad function it produces broken code.

The resulting code:

(ns example)

(defn good []
  (let [value {"a" "1"
               "b" "2"}]
    (merge {}
           (assoc {}
             :aaa value
             :b :c))))

(defn bad []
  (let [value {"a" "1"
               "b" "2"}]
    (merge {}
           (assoc {})
           :aaaa value
           :b :c)))

Demonstration:

cursive.formatting.bug.mp4

IntelliJ IDEA 2023.1
Cursive plugin 1.12.8-2023.1

@luontola
Copy link
Author

luontola commented Apr 5, 2023

There are other longstanding bugs like this related to Parinfer and refactoring, for example #2106.

I think Cursive should do something like this behind the scenes to avoid breaking code: when any refactoring is triggered, (1) disable Parinfer, (2) do the code changes, (3) fix the indentation, (4) enable Parinfer.

@cursive-ide
Copy link
Owner

Thanks for the excellent reproduction case. I'm looking at this now.

FWIW, Cursive does actually do what you suggest. However, there's something about the sequence of changes which Parinfer sees due to the second refactoring which is different, and the bug is actually in the parinfer algorithm. It's tricky to completely reliably disable Parinfer in the case of inline refactorings like this one though, since there are various steps to the refactoring and it's not completely modal (i.e. the user could conceivably do something in another editor in the middle of the inline refactor which might affect it). I'm still trying to figure it out.

@cursive-ide
Copy link
Owner

So your comment prompted me to revisit how this works, and I re-worked the disabling infrastructure to be more robust. This case now works correctly, and I'm hopeful some others will do too. Thanks for the nudge in that direction!

@cursive-ide cursive-ide added this to the 1.13.0 milestone Apr 22, 2023
@cursive-ide cursive-ide modified the milestones: 1.13.0, 1.13.0-eap1 May 21, 2023
@cursive-ide cursive-ide added the bug Marks issues describing bugs label May 21, 2023
@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

2 participants