Intellij 11 not respecting Code Style changes!

I'm writing an ActionScript project and there's one thing that Intellij IDEA does that I do not want it to. Intellij inserts a space after I type a comma in the function parameters (like func(a,<automatic space>b)). While I do like  spaces after my comma, it's pretty much habit for me to insert them myself. The problem is, I end up often with two spaces! Which does take some time to constantly go back and delete one of the spaces.

I found the Spaces tab, under Code Style -> ActionScript, and unchecked the "After comma" field under Other. However, the IDE still inserts the space! To further test things out, I checked "Before comma" and the IDE doesn't insert that space. Either I have the wrong settings or the IDE doesn't appear to be respecting the changes.

While I could get used to not inserting the space, I use other IDEs for other languages that don't give me that option so I'd rather keep consistency and insert the spaces manually.

Help?

Thanks,
C.J.

1 comment
Comment actions Permalink

Most code style settings do not apply (i.e. are not 'activated' or 'enforced') while actively typing. They only apply when IDEA auto-generates code, when you paste code (if so set in Editor > Smart Keys > Reformat on paste), and when you invoke the format code action. So regardless of the"after comma" setting I can type foo(x,y) or foo(x, y) and IDEA will not change it until I invoke the format code option.

The behavior you describe will happen if you use the comma key to select an item from the code completion suggestion list. (This is true even if you have fully typed the parameter and it is still selected in the code completion suggestion list.) I suspect that is when the issue happens for you. To verify that, type a function and enter garbage that would not be found in the suggestion list: func(aaaaa,bbbbbb) You should see that a space is not added after the comma. Using a comma to select a code completion option is a feature that allows you select an item, enter the comma, and enter a space in one key stroke. Unfortunately, this action does not directly honor the "after comma" code style setting (until you reformat the code). Nor is there a way (as far as I know) to change that behavior. You can submit a feature request (http://youtrack.jetbrains.com) to allow you to set whether the space is added or not when using the comma to select a code completion option.

For now, your options are:

  1. Set the code completion "Preselect the first suggestion" option to "Never" (Settings > Editor > Code Completion > Preselect the first suggestion). This will allow you to fully type a parameter and then the comma without it being "seen" as you using the comma to select a code completion option and thus adding the space. But on the flip side, you will always have to arrow down the suggestion list to select a suggestion.
  2. Turn off auto-completion (Settings > Editor > Code Completion > Autopopup code completion) so it does not pop open automatically when typing.
  3. Use enter to select from the code completion window, then type the comma (and space)
  4. Hit Esc (to close the code completion window) before typing the comma when you have fully typed a parameter name (and it shows as selected in the code completion suggestion list).
  5. Don't worry about the double spaces while actively editing. Then, periodically use the format action (Ctrl+Alt+L) to remove any double spaces.


I hope that helps.

0

Please sign in to leave a comment.