While y'all are on a roll of fixing things that have made me slightly annoyed for years (🙏thanks2gratitude-thank-you), here's another one. Happy to file an issue if it's issue-worthy. Given this code:
;; Foo
(do foo)
;; Bar
(do bar)
;; Baz
(do baz)
Running drag sexp backward on the last form (or drag sexp forward on the second form) results in this:
;; Foo
(do foo)
;; Bar
(do baz)
;; Baz
(do bar)
I would've expected at least this (i.e. dragging ignores the comments):
;; Foo
(do foo)
;; Bar
(do bar)
(do baz)
;; Baz
Or even better:
;; Foo
(do foo)
;; Baz
(do baz)
;; Bar
(do bar)
I not infrequently have comments above forms, so when I drag them around I end up having to go back and copy paste the comments separately, or I just end up undoing and copy-pasting the whole chunk instead of dragging.Yeah, please file an issue. This is tricky to fix, but it is good to have it on the radar. Some people even like tricky.
Is there a way to show/hide specific status bar items provided by calva? My status bar is getting crowded, and I don't necessarily need the pprint or strict mode toggles there
Currently it is an all or nothing thing.
@pez per the checklist, do you need a corresponding issue for this PR as well?
Yes, that’s how we do things. 😃 Issues tell why something should be done. PRs what was done (and possibly why it was done in some particular way). And we try to keep the changlog on the Issue level. So that it can be understood on the why level, and since issues are linked to PRs, users can also investigate code changes, should they experience some problem or wonder something that code would answer.
Do you mind if I file an issue? I night have time for a pr too if I’m lucky
Issue welcome. I’m not too keen on adding settings, though, so I suggest we remove the pprint status item, and possibly the strict mode toggler as well,
Another thought: if there a way to make them individually toggleable in the status bar?
I don’t know. If there is, I’m fine with doing it that way.
Reading some old vscode issues, it seems like if we used the larger arity of createStatusBarItem it might make the items individually hideable
The other option is that the returned StatusBarItem has a hide method, so we’d just have to decide what the user interaction that results in that method being called would be
I'll test out the first approach in a bit
Let’s hope the first approach works, because I don’t quite understand the second one. 😃
It did! Currently all the status bar items are registered like this:
const typeStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
To make them individually hide-able, two things need to be done: each needs to be given an id that's unique to the extension, and they need a name so you can tell them apart in the right click menu:
const connectionStatus = vscode.window.createStatusBarItem(
'connectionStatus',
vscode.StatusBarAlignment.Left,
1
);
connectionStatus.name = 'Calva: REPL Connection Status';
Sweet!
I can do a pr if you want, though I feel like someone else will have stronger opinions on what the item names should be
I can have strong opinions about that on the PR. 😃
The new insertSemiColon command is working great! No more indent issues, and I like how by default it doesn't let you create invalid forms. I may have found a bug though: commenting out multiple selected lines doesn't seem to work quite right. For example, if you select this:
(defn foo []
(prn "hi"))
and run the command, you get this:
;;
(defn foo []
;; (prn "hi")
)
It also loses the selection when you run the command, which seems wrong.
Or is there another way to comment out multiple lines at once?@pez do you want a separate issue for the insertSemiColon thing I mentioned above? Same issue? Or is it expected behavior?
@pez Sorry, it was a bit late and I was tired. Here's the before, with a whole function highlighted -- and the after (Calva: Toggle line comment). Not quite sure how to describe that behavior other than "completely broken" 🙂
I mean, it does at least leave the code legal afterward but it certainly doesn't match what I would expect:
@seancorfield well, @max.r.rothman described it as > commenting out multiple selected lines doesn’t seem to work So that’s easier to fix than that something is completely broken. And we have a fix cooking.
@max.r.rothman I can’t reproduce the problem with the ; -binding not working. What’s bound to ; if you check the keyboard shortcuts editor?
What is Calva: Toggle line comment supposed to do that the built-in Toggle line comment command does not? Since the built-in command works "just fine" as far as I'm concerned, I assume Calva's command is supposed to do something similar but different?
(the plain ; bound to insertSemiColon is great BTW)
The built in command produced some weird indentation, so that’s why we provide a separate command. While at it we made the command structurally aware. (But we forgot that more than one line could be selected when you toggle.)
@pez ; is bound to insertSemiColon. Is there anything else I can do to help debug?
When I try it on different functions, I get seemingly random results. e.g., this function (which has no nesting) ends up with the body commented out (and illegal):
;;
(defn check-all
;; "Wrapper for build/bin/check-all.sh for consistency in build REPL."
;; [params]
;; (run-build-script "bin/check-all.sh")
;; params
)
;; Can you provide an example of the built-in Toggle line comment not working / messing up indentation? I'm curious now because I've never seen that happen.
@seancorfield Yeah, totally unpredictable, because: > (But we forgot that more than one line could be selected when you toggle.) Fix is coming.
@max.r.rothman do you have some special keyboard layout?
@max.r.rothman Ah, I guess I've never tried to use the built-in Toggle line comment command unless I have multiple lines selected -- for a single line, I would just type ; or ;; 🙂 So the built-in command worked for me because I always selected multiple lines?
Not as far as i know. And I can tell that insertSemiColon is doing something because it has the correct behavior on eg the second line of that fn
It is extremely rare that I use the toggle comments, but when I do, I have nothing selected. If I want to comment out a form I use #_.
> Not as far as i know. And I can tell that insertSemiColon is doing something because it has the correct behavior on eg the second line of that fn Was that an answer to my question about keyboard layout? What’s “that fn” referring to?
Sorry, yes in response to keyboard layout. Here's an example of insertSemiColon working correctly:
(defn foo []
|(prn "hi"))
to
(defn foo []
;(prn "hi")
)So clearly it is bound and doing something
Sorry, we're having like 3 different convos in this thread 😛
Ah, that’s very extra weird. There’s an inspect keymapping command in VS Code. Can you check if it produces the same results depending on where the cursor is in that function?
I see this line in both outputs:
; => [Semicolon]Interesting. I see:
; => shift+[Comma]
I guess it doesn’t really inspect what I hoped it would inspect.You could run Calva in the debugger and see if both instances hit a breakpoint inside where we handle insertSemiColon.
Will do
Well that was unexpected: when trying both scenarios in calva's debug window, they both function correctly
so it is something with my setup
Can you see something in the console log happening when it fails?
Would that be in Calva Says?
I don't see anything in there, devtools, or the Window output
I meant the devtools.
You could build yourself a prerelease of Calva:
1. Edit package.json and add -something-something after the version
2. npm run package-vsix-prerelease
And old-school console.log debug it. First step is to see if both ; presses hit the function.
Good idea, I tried looking for paredit.ts in devtools but it can't seem to find it
to add a breakpoint in my live vscode window where I'm seeing the issue
I don’t know how source maps survive the bundling.
Oh I've got it! The behavior I reported only occurs in unsaved clj files
Nice find!
Issue please. 😃
> (the plain ; bound to insertSemiColon is great BTW)
I have been running with this keybinding for quite a while, and realized it may be time to make it the default.
https://clojurians.slack.com/archives/CBE668G4R/p1712135613844839
Not at my computer but ctrl+/ I think?
calva now overrides that shortcut by default
That command is something like Toggle Comment
so yeah I can trigger the toggle comment command manually through the palette, but my sense was that calva's new insertSemiColon command was supposed to handle multi-line forms gracefully
> calva now overrides that shortcut by default
Ugh! The multi-line Calva toggle line comment is completely broken -- I deleted the ctrl+/ so I can easily get back the default working version in VS Code 🙂
The individual insertSemiColon bound to ; seems to work just fine for inline comments tho', I agree.
Well, sort of. It still can create invalid forms:
|(defn foo []
(prn "hi"))
hitting ; gives you
;(defn foo []
(prn "hi"))For me, that puts ; on its own line and moves the whole defn form down one line. I.e., it worked as expected.
Are you on the very latest Calva that came out today?
interesting, I see that behavior for cmd+/ but not for ;
yes, I just updated
Check that ; is bound to Calva's command
it is, cmd+/ is bound to calva: toggle line comment which is a different command
Right, I disabled Calva's ctrl+/
For me, ; is bound to paredit.insertSemiColon twice with different conditions
@max.r.rothman please file an issue about multiline connect toggle.
@seancorfield anything more than “completely broken” you could give us? 😀