scala-ide/scala-refactoring

Add option for spaces around braces

Closed this issue · 11 comments

Currently there's disagreement between scalariform and refactoring w.r.t. to imports. Organize imports always rewrites them like this:

import org.foo.{Foo, Bar}

but if I reformat the code, it changes to

import org.foo.{ Foo, Bar }

It would be nice to have an option, so we can make the two agree (and not rewrite uselessly).

One can enable the auto format save action if one can live with the spaces.

That's already supported in the library in https://github.com/scala-ide/scala-refactoring/blob/master/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/sourcegen/Formatting.scala we just need to hook it up in the IDE to use the formatter configuration.

I'm trying to reproduce this, which formatter setting controls the space inside the curly braces?

% ag "SpaceInsideParen"
org.scala-ide.sdt.core/src/org/scalaide/refactoring/internal/UserPreferencesFormatting.scala
6:import scalariform.formatter.preferences.SpaceInsideParentheses
26:        if  prefs(SpaceInsideParentheses)

org.scala-ide.sdt.core/src/org/scalaide/ui/internal/preferences/FormatterPreferencePage.scala
189:      addCheckBox(composite, "Space inside parentheses", SpaceInsideParentheses)

Its in the Formatter->Spaces tab

There should be a "Space inside braces" option. But that is probably not supported by scalariform.

Ah yes, thanks! By default this is disabled, but the formatter nevertheless puts spaces inside the braces. Now, when I enable it, organize imports puts a space there too. Maybe a bug in scalariform?

So, if this is not configurable in scalariform, should we just put " " in the UserPreferencesFormatting?

When scalariform can't handle it, I don't see the point in changing the current behavior. It will always be broken for users who don't use auto format.

But we could change it so that the generated code is at least consistent with the default formatting strategy.

Agreed