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

Improvements to Commentary extension #493

Merged
merged 18 commits into from
Apr 21, 2022

Conversation

citizenmatt
Copy link
Member

@citizenmatt citizenmatt commented Apr 18, 2022

This PR adds a number of improvements and fixes to the Commentary extension:

  • Fix VIM-1687 - gcc does not take a count
  • Fix VIM-2381 - fall back to line comment if block comment is not available
  • Fix VIM-2589 - add gc text object. Can now use comment blocks as text objects, e.g. delete a comment block with dgc, change a comment block with cgc, yank with ygc, etc. Also allows for gcgc to uncomment the current comment block (VIM-2125)
  • Add gcu mapping to uncomment the current comment block (mapped to <Plug>Commentary<Plug>Commentary with is the same as gcgc)
  • Add :Commentary command, which works great for commands such as :%g/fun/Commentary
  • Correctly reposition caret to the range start after adding comments
  • Uses the same mappings as Commentary, so custom bindings for the Vim plugin will work with IdeaVim, too. E.g. <Plug>Commentary instead of <Plug>(CommentMotion). Old mappings are maintained for compatibility

Some implementation notes:

  • The Commentary extension was converted to Kotlin
  • The extension no longer uses the Commenter services, but calls the CommentByLineComment and CommentByBlockComment actions directly. This is an important step to get this working with Rider, but it doesn't yet work because Rider's actions are async. The current implementation invokes the actions and then immediately resets selection and caret position. This causes Rider to terminate the async processing of the actions. I will follow up with a separate PR for this (VIM-1758, RIDER-38359)
  • Simplifying the implementation of the Normal and Visual operators meant introducing Visual mode support for g@. THis means the Commentary handler can now set an operator func and invoke g@ for both Normal and Visual mode.
  • Adding a test for VIM-2381 requires including YAML as a dependency. All of the file types in the default set of references support both block and line comments. YAML only supports line comments. The YAML plugin is already part of the IdeaIC SDK, but needs to be imported as a reference

override fun init() {
putExtensionHandlerMapping(MappingMode.N, parseKeys("<Plug>Commentary"), owner, CommentMotionHandler(), false)
putExtensionHandlerMapping(MappingMode.XO, parseKeys("<Plug>Commentary"), owner, CommentMotionVHandler(), false)
putKeyMappingIfMissing(MappingMode.N, parseKeys("<Plug>CommentaryLine"), owner, parseKeys("gc_"), true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@citizenmatt
Copy link
Member Author

Added a couple of new commits. This adds a backwards compatibility mapping so anyone using <Plug>(CommentMotion) or any of the other older mappings will still work.

Also fixes VIM-2381, by adding a fallback. If the block comment action isn't available, then we fall back to the line comment (and vice versa).

@AlexPl292
Copy link
Member

Yes, this looks awesome! Thank you for the updates.

@AlexPl292 AlexPl292 merged commit 5a6de3a into JetBrains:master Apr 21, 2022
@citizenmatt citizenmatt deleted the feature/commentary branch April 21, 2022 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants