formatter indents lines without ";" differently from lines that end with ";"
Example:
Note: In Eclipse, there is a way to format that I have used for years: CTRL-a, CTRL-i. The scalariform page recommends different shortcuts. This should be considered a bug only if other ways of formatting will not be supported. Tabs are being inserted even though the Scala preferences are set to not use tabs to indent.
class HelloWorld {
val a = 1;
val b = 2;
}
class HelloWorld {
val a = 1
val b = 2
}
Note: In Eclipse, there is a way to format that I have used for years: CTRL-a, CTRL-i. The scalariform page recommends different shortcuts. This should be considered a bug only if other ways of formatting will not be supported. Tabs are being inserted even though the Scala preferences are set to not use tabs to indent.
Leave a comment
on 2011-07-01 02:01 *
By wjohnsonga
Description changed from Scala plugin version: 2.0.0... to Scala plugin version: 2.0.0...
on 2011-07-16 14:25 *
By MattRussell
Ctrl-Shift-F will invoke the formatter (Scalariform) on the file, and won't exhibit the mismatch you're seeing (and it will respect the tab prefs). Ctrl-I is slightly a different thing -- "correct indentation", which doesn't work very well in Scala at the moment.
on 2011-07-18 15:20 *
By dhgarrette
On a related note, if you type a val/var declaration and don't end it with a ";", then when you hit 'enter', the next line will be auto-indented, which is wrong.
on 2011-08-09 09:38 *
By Mirco Dotta
I've opened a new ticket for the issues raised by @dhgarrette 1000550
on 2011-08-09 10:22 *
By Mirco Dotta
I believe the problem is releated to us not overriding the `IndentAction` in `ScalaSourceFileEditor` (and also the default `JavaHeuristicScanner` may play a role). The default `IndentAction` uses `JavaIndenter` class to perform indentation.
What I think we should do is to implement a `ScalaIndentAction` (which should use `ScalaIndenter` behind the scene) and maybe also have a `ScalaHeuristicScanner`. Then in class `ScalaSourceFileEditor` add the following:
And the `ScalaIndentAction` will be called when CTRL+i is pressed.
What I think we should do is to implement a `ScalaIndentAction` (which should use `ScalaIndenter` behind the scene) and maybe also have a `ScalaHeuristicScanner`. Then in class `ScalaSourceFileEditor` add the following:
override protected def createActions() {
super.createActions()
val indentAction= new ScalaIndentAction(bundleForConstructedKeys, "Indent.", this, false); //$NON-NLS-1$
indentAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.INDENT);
setAction("Indent", indentAction); //$NON-NLS-1$
markAsStateDependentAction("Indent", true); //$NON-NLS-1$
markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
PlatformUI.getWorkbench().getHelpSystem().setHelp(indentAction, IJavaHelpContextIds.INDENT_ACTION);
val indentOnTabAction = new ScalaIndentAction(bundleForConstructedKeys, "Indent.", this, true); //$NON-NLS-1$
setAction("IndentOnTab", indentOnTabAction); //$NON-NLS-1$
markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
// ...
}
And the `ScalaIndentAction` will be called when CTRL+i is pressed.
Moving to 2.1, like the related ticket.
on 2014-02-27 17:38 *
By Simon Schäfer
Version changed from 2.0.0-final-29 to 3.0.2-210
Description changed from Scala plugin version: 2.0.0... to Example:
class ...
Status changed from Accepted to Duplicate
Closing as duplicate of #1000556