Conversation
This function wraps the default comment line command to ensure that commented lines maintain proper Clojure-aware indentation. It calculates the necessary indent fixes after commenting and applies them to the affected lines, improving the alignment of code structures like association arguments.
This commit introduces a new command to toggle line comments in Clojure files. The command is registered in the package.json and associated with the keybinding Ctrl+/ for ease of use. This enhancement improves the editing experience for users by allowing quick commenting and uncommenting of lines. Fixes BetterThanTomorrow#2872
This commit introduces a suite of integration tests for the toggle comment feature in the editor. The tests cover various scenarios, including commenting and uncommenting lines with correct indentation, handling multiple cursors, and ensuring alignment in nested forms. These tests aim to improve the reliability and correctness of the toggle comment functionality.
✅ Deploy Preview for calva-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…r behavior in edit.ts: - Added early returns for non-Clojure/no-op cases. - Made affected-line handling deterministic (validated + sorted line numbers). - Simplified indent-fix edit application by applying fix.delta directly (no intermediate TextEdit array).
Introduce a new keybinding for toggling line comments that preserves Clojure-aware indentation. This enhancement improves usability by allowing users to comment or uncomment lines while maintaining structural integrity in their code.
This commit introduces an interface and a function to calculate indent fixes for lines in a document. The new functionality allows for determining the necessary adjustments to line indentation, facilitating better formatting and code readability.
|
Thanks for doing this! We should probably be overriding the built-in comment toggle command for people who run with |
| await new Promise((resolve) => setTimeout(resolve, 20 * pauseMs)); | ||
| assert.equal( | ||
| await toggleCommentUsingActiveEditor('(defn foo []• |(println "test"))'), | ||
| '(defn foo []• |;; (println "test"))' |
There was a problem hiding this comment.
This breaks the structure of the document. The end result needs to be:
(defn foo []• ;; |(println "test")• )
There's a paredit function today which knows how to do this correctly: insertSemiColon.
|
This command should to be structural, I think. It doesn't make sense with a Paredit command that breaks structure. 😄 |
Clarify the behavior of the Toggle Line Comment feature to specify how it handles single selections and multi-cursor cases, ensuring users understand the structural indentation preservation and semicolon insertion.
|
I now use |
|
|
||
| it('should uncomment a line and restore correct indentation', async () => { | ||
| assert.equal( | ||
| await toggleCommentUsingActiveEditor('(defn foo []• ;; |(println "test"))'), |
There was a problem hiding this comment.
It hurts my eyes a bit with the unstructured code here. 😄 But it's good that we handle it.
There was a problem hiding this comment.
this is the uncomment case, it's testing how would be aligned after uncommenting that unstructured code
There was a problem hiding this comment.
the test above is the comment case, where it throws the ) to the next line
There was a problem hiding this comment.
I know. I guess I could see it as healing the broken code. 😄
screen-capture.webm |
That's similar to what insertSemiColon does. Same day we should make both commands multi-cursor compliant! 💪 |
package.json
Outdated
| "command": "calva.toggleLineComment", | ||
| "key": "ctrl+/", | ||
| "mac": "cmd+/", | ||
| "when": "calva:keybindingsEnabled && editorLangId == clojure && editorTextFocus && !editorReadOnly" |
There was a problem hiding this comment.
I think we should also check that the user wants us to highjack built-in shortcuts. There's a config for that, and prior art how to check the config from the when-expression.
|
Fixes #2872 Whoops, it was already linked 😅 |
Clarify the behavior of the Toggle Line Comment feature to emphasize Clojure-aware behavior and reformatting of enclosing forms, enhancing user understanding of its functionality.
Enhanced the conditions for the toggle line comment command to include the new configuration option for paredit. Added a new keybinding for inserting a semicolon with specific conditions to improve user experience in Clojure editing.
This commit introduces tests for the insertSemiColon function in the paredit util. The tests verify that a semicolon is correctly inserted at the cursor without breaking the structure, and that a newline is added when necessary to preserve the document's structure.
Enhance the insertSemiColon function to maintain line indentation when inserting a semicolon. This change ensures that the code structure remains intact and improves readability.
What has changed?
calva.toggleLineCommentwith same keybinding aseditor.action.commentLinetoggleLineCommentCommandwich is executed withcalva.toggleLineCommentand wrapseditor.action.commentLinewith the extra feature of indenting commented/uncommented lines.Fixes #2872
My Calva PR Checklist
I have:
devbranch. (Or have specific reasons to target some other branch.)published. (Sorry for the nagging.)[Unreleased]entry inCHANGELOG.md, linking the issue(s) that the PR is addressing.npm run prettier-format)npm run eslintbefore creating your PR, or runnpm run eslint-watchto eslint as you go).