-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...dt.core/src/org/scalaide/core/internal/extensions/saveactions/AutoFormattingCreator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.scalaide.core.internal.extensions.saveactions | ||
|
||
import org.scalaide.core.text.Document | ||
import org.scalaide.extensions.DocumentSupport | ||
import org.scalaide.extensions.saveactions.AutoFormatting | ||
|
||
object AutoFormattingCreator { | ||
def create(doc: Document): AutoFormatting = | ||
new AutoFormatting { | ||
override val document = doc | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
org.scala-ide.sdt.core/src/org/scalaide/extensions/saveactions/AutoFormatting.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.scalaide.extensions | ||
package saveactions | ||
|
||
import org.scalaide.core.ScalaPlugin | ||
import org.scalaide.core.internal.formatter.FormatterPreferences | ||
import org.scalaide.core.text.Replace | ||
|
||
import scalariform.formatter.ScalaFormatter | ||
|
||
object AutoFormattingSetting extends SaveActionSetting( | ||
id = ExtensionSetting.fullyQualifiedName[AutoFormatting], | ||
name = "Auto formatting", | ||
description = "Formats the entire document based on the configuration options in \"Scala > Editor > Formatter\".", | ||
codeExample = """|class C { | ||
| def f = { | ||
| val a=0 | ||
| val b =5 | ||
| a +b | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
|
||
trait AutoFormatting extends SaveAction with DocumentSupport { | ||
|
||
def setting = AutoFormattingSetting | ||
|
||
def perform() = { | ||
val formatted = ScalaFormatter.format( | ||
document.text, | ||
FormatterPreferences.getPreferences(ScalaPlugin.prefStore)) | ||
Seq(Replace(0, document.length, formatted)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters