Skip to content

Commit

Permalink
Separate Scala colouring preferences from Java. Add Syntax Colouring …
Browse files Browse the repository at this point in the history
…preference page.
  • Loading branch information
mdr committed Mar 20, 2011
1 parent 4182a91 commit 73d8ffe
Show file tree
Hide file tree
Showing 24 changed files with 796 additions and 321 deletions.

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions org.scala-ide.sdt.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<page class="scala.tools.eclipse.properties.ScalaPreferences"
name="Scala"
id="org.scala-ide.sdt.core.preferences"/>
<page class="scala.tools.eclipse.properties.SyntaxColouringPreferencePage"
category="org.scala-ide.sdt.core.preferences"
name="Syntax Coloring"
id="org.scala-ide.sdt.core.properties.SyntaxColouringPreferencePage"/>
<page
category="org.scala-ide.sdt.core.preferences"
class="scala.tools.eclipse.properties.CompilerSettings"
Expand Down Expand Up @@ -641,6 +645,9 @@
<extension
id="org.scala-ide.sdt.core.preferences"
point="org.eclipse.core.runtime.preferences">
<initializer
class="scala.tools.eclipse.properties.ColourPreferenceInitializer">
</initializer>
<initializer
class="scala.tools.eclipse.properties.ScalaCompilerPreferenceInitializer">
</initializer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import scala.tools.eclipse.javaelements.ScalaClassFile

class ScalaClassFileEditor extends ClassFileEditor with ScalaEditor {
override def createJavaSourceViewerConfiguration : JavaSourceViewerConfiguration =
new ScalaSourceViewerConfiguration(getPreferenceStore, this)
new ScalaSourceViewerConfiguration(getPreferenceStore, ScalaPlugin.plugin.getPreferenceStore, this)

override def setSourceViewerConfiguration(configuration : SourceViewerConfiguration) {
super.setSourceViewerConfiguration(
configuration match {
case svc : ScalaSourceViewerConfiguration => svc
case _ => new ScalaSourceViewerConfiguration(getPreferenceStore, this)
case _ => new ScalaSourceViewerConfiguration(getPreferenceStore, ScalaPlugin.plugin.getPreferenceStore, this)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import scala.tools.eclipse.markoccurrences.{ ScalaOccurrencesFinder, Occurrences
import scala.tools.eclipse.ui.semantic.highlighting.SemanticHighlightingPresenter
import scala.tools.eclipse.text.scala.ScalaTypeAutoCompletionProposalManager
import scala.tools.eclipse.util.IDESettings
import scala.tools.eclipse.util.{Defensive, Tracer}
import scala.tools.eclipse.util.{ Defensive, Tracer }
import org.eclipse.ui.texteditor.IDocumentProvider
import org.eclipse.ui.IEditorInput
import org.eclipse.jface.util.IPropertyChangeListener
import org.eclipse.jface.util.PropertyChangeEvent

class ScalaSourceFileEditor extends CompilationUnitEditor with ScalaEditor {

Expand Down Expand Up @@ -80,31 +82,29 @@ class ScalaSourceFileEditor extends CompilationUnitEditor with ScalaEditor {
}

override def createJavaSourceViewerConfiguration: JavaSourceViewerConfiguration =
new ScalaSourceViewerConfiguration(getPreferenceStore, this)
new ScalaSourceViewerConfiguration(getPreferenceStore, ScalaPlugin.plugin.getPreferenceStore, this)

override def setSourceViewerConfiguration(configuration: SourceViewerConfiguration) {
super.setSourceViewerConfiguration(
configuration match {
case svc: ScalaSourceViewerConfiguration => svc
case _ => new ScalaSourceViewerConfiguration(getPreferenceStore, this)
case _ => new ScalaSourceViewerConfiguration(getPreferenceStore, ScalaPlugin.plugin.getPreferenceStore, this)
})
}

// doSetInput is called in Thread "main" but can take time because some part require ScalaPresentationCompiler
// but run it in other thread than current raise NPE later
// keep the code block commented for memory (and may be later try to improve)
// /*
// * @see AbstractTextEditor#doSetInput
// * @throws CoreException
// */
// protected override def doSetInput(input: IEditorInput) = Defensive.askRunOutOfMain("ScalaSourceFileEditor.doSetInput") { super.doSetInput(input) }

private[eclipse] def sourceViewer = getSourceViewer

// doSetInput is called in Thread "main" but can take time because some part require ScalaPresentationCompiler
// but run it in other thread than current raise NPE later
// keep the code block commented for memory (and may be later try to improve)
// /*
// * @see AbstractTextEditor#doSetInput
// * @throws CoreException
// */
// protected override def doSetInput(input: IEditorInput) = Defensive.askRunOutOfMain("ScalaSourceFileEditor.doSetInput") { super.doSetInput(input) }

private[eclipse] def sourceViewer = getSourceViewer

override def updateOccurrenceAnnotations(selection: ITextSelection, astRoot: CompilationUnit) = ScalaPlugin.plugin.updateOccurrenceAnnotationsService.askUpdateOccurrenceAnnotations(this, selection, astRoot)
def superUpdateOccurrenceAnnotations(selection: ITextSelection, astRoot: CompilationUnit) = {}//super.updateOccurrenceAnnotations(selection, astRoot)
def superUpdateOccurrenceAnnotations(selection: ITextSelection, astRoot: CompilationUnit) = {} //super.updateOccurrenceAnnotations(selection, astRoot)

override def doSelectionChanged(selection: ISelection) {
Tracer.println("ScalaSourceFileEditor.doSelectionChanged")
Expand All @@ -120,7 +120,7 @@ class ScalaSourceFileEditor extends CompilationUnitEditor with ScalaEditor {
override def installOccurrencesFinder(forceUpdate: Boolean) {
//super.installOccurrencesFinder(forceUpdate)
ScalaPlugin.plugin.updateOccurrenceAnnotationsService.installSelectionListener(getEditorSite)
}
}
override def uninstallOccurrencesFinder() {
ScalaPlugin.plugin.updateOccurrenceAnnotationsService.uninstallSelectionListener(getEditorSite)
//super.uninstallOccurrencesFinder
Expand All @@ -136,24 +136,37 @@ class ScalaSourceFileEditor extends CompilationUnitEditor with ScalaEditor {
val b = new SemanticHighlightingPresenter(getEditorInput.asInstanceOf[FileEditorInput], viewer)
ScalaPlugin.plugin.reconcileListeners.after_+(b.update)
Some(b)
}
}
}

//FIXME : workaround for my limited knowledge about current presentation compiler
val scu = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput()).asInstanceOf[ScalaCompilationUnit]
viewer.getDocument().addPrenotifiedDocumentListener(ScalaTypeAutoCompletionProposalManager.getProposalFor(scu))
}

refactoring.RefactoringMenu.fillQuickMenu(this)
}

override def editorContextMenuAboutToShow(menu: org.eclipse.jface.action.IMenuManager): Unit = {
super.editorContextMenuAboutToShow(menu)
refactoring.RefactoringMenu.fillContextMenu(menu, this)
}

// override to public scope (from protected)
override def getElementAt(offset : Int, reconcile : Boolean) = super.getElementAt(offset, reconcile)
override def getElementAt(offset: Int, reconcile: Boolean) = super.getElementAt(offset, reconcile)

private val preferenceListener = new IPropertyChangeListener() {
def propertyChange(event: PropertyChangeEvent) {
handlePreferenceStoreChanged(event)
}
}
ScalaPlugin.plugin.getPreferenceStore.addPropertyChangeListener(preferenceListener)

override def dispose() {
super.dispose()
ScalaPlugin.plugin.getPreferenceStore.removePropertyChangeListener(preferenceListener)
}

}

object ScalaSourceFileEditor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package scala.tools.eclipse;

//import scala.tools.eclipse.text.scala.ScalaCompletionProcessor
import org.eclipse.jface.util.PropertyChangeEvent
import org.eclipse.jdt.core.{ IJavaProject, IJavaElement, ICodeAssist }
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.javaeditor.{ IClassFileEditorInput, ICompilationUnitDocumentProvider, JavaElementHyperlinkDetector }
Expand All @@ -29,89 +30,123 @@ import scala.tools.eclipse.ui.{ JdtPreferenceProvider, ScalaAutoIndentStrategy,
import scala.tools.eclipse.util.ReflectionUtils
import scala.tools.eclipse.lexical._
import scala.tools.eclipse.formatter.ScalaFormattingStrategy
import scala.tools.eclipse.properties.ScalaSyntaxClasses

class ScalaSourceViewerConfiguration(store : IPreferenceStore, editor : ITextEditor)
class ScalaSourceViewerConfiguration(store: IPreferenceStore, scalaPreferenceStore: IPreferenceStore, editor: ITextEditor)
extends JavaSourceViewerConfiguration(JavaPlugin.getDefault.getJavaTextTools.getColorManager, store, editor, IJavaPartitions.JAVA_PARTITIONING) {

private val codeScanner = new ScalaCodeScanner(getColorManager, store)

override def getPresentationReconciler(sv : ISourceViewer) = {
override def getPresentationReconciler(sv: ISourceViewer) = {
val reconciler = super.getPresentationReconciler(sv).asInstanceOf[PresentationReconciler]

def handlePartition(partitionType: String, tokenScanner: ITokenScanner) {
val dr = new DefaultDamagerRepairer(tokenScanner)
reconciler.setDamager(dr, partitionType)
reconciler.setRepairer(dr, partitionType)
reconciler.setRepairer(dr, partitionType)
}

handlePartition(IDocument.DEFAULT_CONTENT_TYPE, codeScanner)
handlePartition(ScalaPartitions.SCALA_MULTI_LINE_STRING, getStringScanner())
handlePartition(ScalaPartitions.XML_TAG, new XmlTagScanner(getColorManager))
handlePartition(ScalaPartitions.XML_COMMENT, new XmlCommentScanner(getColorManager))
handlePartition(ScalaPartitions.XML_CDATA, new XmlCDATAScanner(getColorManager))
handlePartition(ScalaPartitions.XML_PI, new XmlPIScanner(getColorManager))

handlePartition(IDocument.DEFAULT_CONTENT_TYPE, scalaCodeScanner)
handlePartition(IJavaPartitions.JAVA_DOC, scaladocScanner)
handlePartition(IJavaPartitions.JAVA_SINGLE_LINE_COMMENT, singleLineCommentScanner)
handlePartition(IJavaPartitions.JAVA_MULTI_LINE_COMMENT, multiLineCommentScanner)
handlePartition(IJavaPartitions.JAVA_STRING, stringScanner)
handlePartition(ScalaPartitions.SCALA_MULTI_LINE_STRING, multiLineStringScanner)
handlePartition(ScalaPartitions.XML_TAG, xmlTagScanner)
handlePartition(ScalaPartitions.XML_COMMENT, xmlCommentScanner)
handlePartition(ScalaPartitions.XML_CDATA, xmlCDATAScanner)
handlePartition(ScalaPartitions.XML_PCDATA, xmlPCDATAScanner)
handlePartition(ScalaPartitions.XML_PI, xmlPIScanner)

reconciler
}

override def getTextHover(sv : ISourceViewer, contentType : String, stateMask : Int) = new ScalaHover(getCodeAssist)
private val scalaCodeScanner = new ScalaCodeScanner(getColorManager, scalaPreferenceStore)
private val singleLineCommentScanner = new SingleTokenScanner(ScalaSyntaxClasses.SINGLE_LINE_COMMENT, getColorManager, scalaPreferenceStore)
private val multiLineCommentScanner = new SingleTokenScanner(ScalaSyntaxClasses.MULTI_LINE_COMMENT, getColorManager, scalaPreferenceStore)
private val scaladocScanner = new SingleTokenScanner(ScalaSyntaxClasses.SCALADOC, getColorManager, scalaPreferenceStore)
private val stringScanner = new SingleTokenScanner(ScalaSyntaxClasses.STRING, getColorManager, scalaPreferenceStore)
private val multiLineStringScanner = new SingleTokenScanner(ScalaSyntaxClasses.MULTI_LINE_STRING, getColorManager, scalaPreferenceStore)
private val xmlTagScanner = new XmlTagScanner(getColorManager, scalaPreferenceStore)
private val xmlCommentScanner = new XmlCommentScanner(getColorManager, scalaPreferenceStore)
private val xmlCDATAScanner = new XmlCDATAScanner(getColorManager, scalaPreferenceStore)
private val xmlPCDATAScanner = new SingleTokenScanner(ScalaSyntaxClasses.DEFAULT, getColorManager, scalaPreferenceStore)
private val xmlPIScanner = new XmlPIScanner(getColorManager, scalaPreferenceStore)

override def getHyperlinkDetectors(sv : ISourceViewer) = {
override def getTextHover(sv: ISourceViewer, contentType: String, stateMask: Int) = new ScalaHover(getCodeAssist)

override def getHyperlinkDetectors(sv: ISourceViewer) = {
val shd = new ScalaHyperlinkDetector
shd.setContext(editor)
if (editor != null)
shd.setContext(editor)
Array(shd)
}
def getCodeAssist : Option[ICodeAssist] = Option(editor) map { editor =>

def getCodeAssist: Option[ICodeAssist] = Option(editor) map { editor =>
val input = editor.getEditorInput
val provider = editor.getDocumentProvider

(provider, input) match {
case (icudp : ICompilationUnitDocumentProvider, _) => icudp getWorkingCopy input
case (_, icfei : IClassFileEditorInput) => icfei.getClassFile
case _ => null
case (icudp: ICompilationUnitDocumentProvider, _) => icudp getWorkingCopy input
case (_, icfei: IClassFileEditorInput) => icfei.getClassFile
case _ => null
}
}

def getProject : IJavaProject = {
getCodeAssist map (_.asInstanceOf[IJavaElement].getJavaProject) orNull
def getProject: IJavaProject = {
getCodeAssist map (_.asInstanceOf[IJavaElement].getJavaProject) orNull
}


/**
* Replica of JavaSourceViewerConfiguration#getAutoEditStrategies that returns
* a ScalaAutoIndentStrategy instead of a JavaAutoIndentStrategy.
*
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
*/
override def getAutoEditStrategies(sourceViewer : ISourceViewer, contentType : String) : Array[IAutoEditStrategy] = {
override def getAutoEditStrategies(sourceViewer: ISourceViewer, contentType: String): Array[IAutoEditStrategy] = {
val partitioning = getConfiguredDocumentPartitioning(sourceViewer)

if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)) {
return Array(new JavaDocAutoIndentStrategy(partitioning))
} else if (IJavaPartitions.JAVA_STRING.equals(contentType)) {
return Array(new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning))
} else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
return Array(new SmartSemicolonAutoEditStrategy(partitioning), new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
} else {
return Array(new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
contentType match {
case IJavaPartitions.JAVA_DOC | IJavaPartitions.JAVA_MULTI_LINE_COMMENT =>
Array(new JavaDocAutoIndentStrategy(partitioning))
case IJavaPartitions.JAVA_STRING =>
Array(new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning))
case IJavaPartitions.JAVA_CHARACTER | IDocument.DEFAULT_CONTENT_TYPE =>
Array(new SmartSemicolonAutoEditStrategy(partitioning), new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
case _ =>
Array(new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
}
}

override def getContentFormatter(sourceViewer: ISourceViewer) = {
val contentFormatter = new ContentFormatter
contentFormatter.enablePartitionAwareFormatting( false );
val contentFormatter = new ContentFormatter
contentFormatter.enablePartitionAwareFormatting(false);
contentFormatter.setFormattingStrategy(new ScalaFormattingStrategy(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE)
contentFormatter
contentFormatter
}

// override def getContentAssistant(sourceViewer: ISourceViewer): IContentAssistant = {
// val assistant = super.getContentAssistant(sourceViewer).asInstanceOf[ContentAssistant]
//
// val scalaProcessor = new ScalaCompletionProcessor(getEditor(), assistant, IDocument.DEFAULT_CONTENT_TYPE);
// assistant.setContentAssistProcessor(null, IDocument.DEFAULT_CONTENT_TYPE);
// assistant.setContentAssistProcessor(scalaProcessor, IDocument.DEFAULT_CONTENT_TYPE);
//
// return assistant
// }
// override def getContentAssistant(sourceViewer: ISourceViewer): IContentAssistant = {
// val assistant = super.getContentAssistant(sourceViewer).asInstanceOf[ContentAssistant]
//
// val scalaProcessor = new ScalaCompletionProcessor(getEditor(), assistant, IDocument.DEFAULT_CONTENT_TYPE);
// assistant.setContentAssistProcessor(null, IDocument.DEFAULT_CONTENT_TYPE);
// assistant.setContentAssistProcessor(scalaProcessor, IDocument.DEFAULT_CONTENT_TYPE);
//
// return assistant
// }

override def handlePropertyChangeEvent(event: PropertyChangeEvent) {
super.handlePropertyChangeEvent(event)
scalaCodeScanner.adaptToPreferenceChange(event)
scaladocScanner.adaptToPreferenceChange(event)
stringScanner.adaptToPreferenceChange(event)
multiLineStringScanner.adaptToPreferenceChange(event)
singleLineCommentScanner.adaptToPreferenceChange(event)
multiLineCommentScanner.adaptToPreferenceChange(event)
xmlTagScanner.adaptToPreferenceChange(event)
xmlCommentScanner.adaptToPreferenceChange(event)
xmlCDATAScanner.adaptToPreferenceChange(event)
xmlPCDATAScanner.adaptToPreferenceChange(event)
xmlPIScanner.adaptToPreferenceChange(event)
}

override def affectsTextPresentation(event: PropertyChangeEvent) = true

}
Loading

0 comments on commit 73d8ffe

Please sign in to comment.