Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'structure-select-perf-tweak' into wip_experiment

  • Loading branch information...
commit da3f9182ba098f45e7bacf9f2e8f4563d22079c1 2 parents 3e397d4 + b21447e
@dragos dragos authored
View
14 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaStructureSelectEnclosingAction.scala
@@ -5,19 +5,29 @@ import org.eclipse.jdt.internal.ui.javaeditor.selectionactions._
import org.eclipse.jface.action.Action
import org.eclipse.jface.text.ITextSelection
+import scalariform.parser.ScalaParserException
import scalariform.astselect.AstSelector
import scalariform.utils.Range
-
/**
* A Scala-aware replacement for {@link org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectEnclosingAction}.
*/
class ScalaStructureSelectEnclosingAction(editor: ScalaSourceFileEditor, selectionHistory: SelectionHistory) extends Action {
+ private var previousAstSelector: Option[(String, AstSelector)] = None
+
override def run() {
val source = editor.getDocumentProvider.getDocument(editor.getEditorInput).get
+ val astSelector = previousAstSelector match {
+ case Some((previousSource, astSelector)) if previousSource == source => astSelector
+ case _ =>
+ try new AstSelector(source)
+ catch { case _: ScalaParserException => return }
+ }
+ previousAstSelector = Some(source, astSelector)
+
val selection = editor.getSelectionProvider.getSelection.asInstanceOf[ITextSelection]
val selectionRange = Range(selection.getOffset, selection.getLength)
- for (Range(offset, length) <- AstSelector.expandSelection(source, selectionRange)) {
+ for (Range(offset, length) <- astSelector.expandSelection(selectionRange)) {
selectionHistory.remember(new SourceRange(selection.getOffset, selection.getLength))
try {
selectionHistory.ignoreSelectionChanges()
Please sign in to comment.
Something went wrong with that request. Please try again.