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

Format doesn't work properly if ##Inf is involved #870

Closed
werenike opened this issue Dec 13, 2020 · 11 comments
Closed

Format doesn't work properly if ##Inf is involved #870

werenike opened this issue Dec 13, 2020 · 11 comments
Labels
bug Something isn't working formatting upstream

Comments

@werenike
Copy link

werenike commented Dec 13, 2020

I'm just starting out with Clojure/Calva/REPL-based-dev. I've managed to connect to the REPL and evaluate forms. However, after connecting to the REPL, my code is no longer formatted as I type, whereas it was being formatted before connecting. I've tried both the Jack-In option and starting my own REPL and connecting to the port, both with the same result. I'm not seeing any errors in the outputs. I'm not sure where to go from here, any help would be appreciated!

edit: I am now also getting an error pop up "Running the contributed command: 'calva-fmt.formatCurrentForm' failed." when I try to tab-indent a section of code, which I believe was not the case before I started experimenting with the REPL. The auto-formatting while coding is also less sophisticated than it was before I started experimenting with the REPL (even when not connected to a REPL now). It seems the experiments have broken something in my configuration, even though I don't think I explicitly changed any settings. I've tried reinstalling Calva and rebooting, to no avail.

VS code info:

Version: 1.51.1
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-12T10:54:25.653Z
Electron: 9.3.5
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.9.11-3-MANJARO

Calva version: v2.0.134

@werenike werenike changed the title No formatting after connecting to REPL Calva no longer formats properly after REPL usage Dec 13, 2020
@bpringe
Copy link
Member

bpringe commented Dec 13, 2020

Hello fellow Manjaro user 😃. This sounds really strange. Have you changed any formatting settings? (https://calva.io/formatting/#configuration). The only other thing off the top of my head that can be affecting it is other extensions. Have you tried disabling all other extensions (clj-kondo is fine to leave enabled), and then seeing if it behaves the same?

@bpringe bpringe added bug Something isn't working formatting labels Dec 13, 2020
@werenike
Copy link
Author

Hi, thanks for your help!

AFAIK I haven't changed any formatting settings. I don't have any .edn files in this project. I also checked the VS settings and the only relevant setting there is "calva.paredit.defaultKeyMap": "strict".

I tried disabling all extensions except Calva, or Calva and clj-kondo, but there is no change in the behavior.

Here's another thing I found: if I try to run the command 'Calva Format: Format Current Form', or a similar command, I also get the pop-up error "Running the contributed command: 'calva-fmt.formatCurrentForm' failed." or equivalent.

@PEZ
Copy link
Collaborator

PEZ commented Dec 13, 2020

Very strange! Does it help to make click between some different clojure files? Thinking that maybe Calva gets confused about what is the active window, when the output window is activated....

@werenike
Copy link
Author

Thanks for the input! I've tried opening multiple Clojure files, opening a single Clojure file, having VS Code's Output window opened or closed, but none of it made a difference in the behavior.

I will experiment some more later when I have time, and try to gather more data about the problem.

@bpringe
Copy link
Member

bpringe commented Dec 28, 2020

@MareinK If you can give code that the issue happens with, all the code in the file (can make a small sample file to make it simpler to analyze), maybe we can see if something in the code is tripping up the formatter.

@werenike
Copy link
Author

werenike commented Jan 2, 2021

@bpringe Thanks! I've currently shifted my experiments with Clojure/Calva to the browser with ClojureScript and shadow-cljs, so I haven't been in a situation where the REPL problem popped up. However, I will take some time soon to look into the problem again and try to produce a minimal example.

@werenike
Copy link
Author

Hi! Sorry for taking so long to look into this. I had a look now and I'm afraid I can't quite reproduce the problem. Maybe something changed in my configuration since I had the problem, or maybe I misinterpreted the problem to begin with.

I did find an example where the formatting seems to fail, but it's not affected by the REPL. It seems that many (or all?) code samples involving ##Inf are not formatted. Maybe there is a reason for this which I don't know about, or maybe ##Inf is not advised to be used at all, but this is what I ran into (I was using it in cases like (range start ##Inf).

The simplest example I found where the formatting fails is the following. Suppose we start with the following code consisting of two lines, one of which is empty:


1

Place the cursor at the top line and write (f, at which point the closing ) will be assumed, and then use slurp forward (ctrl+right in my case). The result is as follows:

(f
 1)

The second line has been indented. This result is as expected. Now we try the same but replacing 1 by ##Inf. We start as follows:


##Inf

After typing (f on the first line and slurping forward:

(f 
##Inf)

The second line has not been indented, which is not as expected. This is the simplest example I could think of, but the presence of ##Inf seems to cause issues throughout the file. Here is a more complicated example copied from my code and changed slightly. The logic is not that important, I think, but note the ##Inf near the end of the first line.

(let [[time id] (->> (range init-time ##Inf)
                     (some time-id-now))]
  (println (* (- time init-time) id)))

(let [start 0
      [max-i max-id] (apply max-key second ids)
      offset (+ max-i (rem start max-id))]
  (->> (range (- start offset) max-id)
       (filter all-ordered?)
       (first)
       (println)))

If I place my cursor right after the ->> near the end of the code, and press enter and then save the file, I get the following:

(let [[time id] (->> (range init-time ##Inf)
                     (some time-id-now))]
  (println (* (- time init-time) id)))

(let [start 0
      [max-i max-id] (apply max-key second ids)
      offset (+ max-i (rem start max-id))]
  (->>
   (range (- start offset) max-id)
       (filter all-ordered?)
       (first)
       (println)))

This is not as expected. The elements below ->> should all have the same indentation. And indeed that's what I get if I remove the top part of the code containing the ##Inf before inserting the new line and saving:

(let [start 0
      [max-i max-id] (apply max-key second ids)
      offset (+ max-i (rem start max-id))]
  (->>
   (range (- start offset) max-id)
   (filter all-ordered?)
   (first)
   (println)))

That's what I have so far. As I said this doesn't seem to be linked to the REPL. It could be that earlier I was conflating my experiments with ##Inf and my experiments with the REPL, when this problem first occured. If desired I can start a new issue about this problem. Since the REPL doesn't seem to be causing trouble at present, I will start using it again and I will keep an eye out for the original issue, if it exists.

Thanks again for your patience and I'm curious to hear your feedback about this.

@bpringe
Copy link
Member

bpringe commented Jan 18, 2021

Thanks for the detailed examples! Let's see what @PEZ has to say about this. It does seem that ##Inf is causing issues.

@PEZ PEZ added the upstream label Jan 19, 2021
@PEZ
Copy link
Collaborator

PEZ commented Jan 19, 2021

Glad the mysterious behaviour went away, @MareinK.

That looks like this issue with cljfmt: weavejester/cljfmt#171

I renamed this issue and suggest we keep it open a while so that people who stumble across the problem can find it.

@werenike
Copy link
Author

Thanks @bpringe and @PEZ for your help!

@bpringe bpringe changed the title Calva no longer formats properly after REPL usage Format doesn't work properly if ##Inf is involved Jan 19, 2021
@bpringe
Copy link
Member

bpringe commented Jan 19, 2021

I renamed this issue

I didn't see this rename, so I renamed 😄. Hope it's what was intended.

PEZ added a commit that referenced this issue Feb 12, 2022
Also inline pez-cljfmt and use it if :align-associative? is true

Fixes #1179
Fixes #1414
Fixes #1267
Fixes #1054
Fixes #870
Fixes #807
Fixes #782
@PEZ PEZ mentioned this issue Feb 12, 2022
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatting upstream
Projects
None yet
Development

No branches or pull requests

3 participants