Skip to content

Commit

Permalink
Merge pull request scala-ide#68 from dragos/master
Browse files Browse the repository at this point in the history
Only display problem annotations in the hover.
  • Loading branch information
dragos committed Apr 4, 2013
2 parents 25189ca + 4018566 commit fc2b2a6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
.cache .cache
target/ target/
.settings/ .settings/
.target/
.worksheet/
6 changes: 4 additions & 2 deletions org.scala-ide.play2/src/org/scalaide/play2/PlayProject.scala
Expand Up @@ -46,8 +46,10 @@ class PlayProject private (val scalaProject: ScalaProject) {
presentationCompiler.destroy() presentationCompiler.destroy()
} }


/** /** FIXME: This method should probably not exist.
* It has the source directory of scala template files * Template files can be anywhere
*
* @return the absolute location of the `/app/views` directory, below the project root
*/ */
lazy val sourceDir = new File(scalaProject.underlying.getLocation().toString() + "/app/views") lazy val sourceDir = new File(scalaProject.underlying.getLocation().toString() + "/app/views")
} }
Expand Down
Expand Up @@ -39,6 +39,7 @@ import scala.tools.eclipse.lexical.ScalaPartitions
import org.eclipse.jdt.ui.text.IJavaPartitions import org.eclipse.jdt.ui.text.IJavaPartitions
import scala.tools.eclipse.ui.BracketAutoEditStrategy import scala.tools.eclipse.ui.BracketAutoEditStrategy
import org.eclipse.jdt.internal.ui.text.java.SmartSemicolonAutoEditStrategy import org.eclipse.jdt.internal.ui.text.java.SmartSemicolonAutoEditStrategy
import org.eclipse.jface.text.source.Annotation


class TemplateConfiguration(prefStore: IPreferenceStore, templateEditor: TemplateEditor) extends TextSourceViewerConfiguration with PropertyChangeHandler { class TemplateConfiguration(prefStore: IPreferenceStore, templateEditor: TemplateEditor) extends TextSourceViewerConfiguration with PropertyChangeHandler {


Expand All @@ -64,12 +65,6 @@ class TemplateConfiguration(prefStore: IPreferenceStore, templateEditor: Templat
TemplatePartitions.getTypes() TemplatePartitions.getTypes()
} }


/** Necessary for hover over annotations
*/
override def getAnnotationHover(viewer: ISourceViewer): IAnnotationHover = {
new DefaultAnnotationHover(true)
}

/** Necessary for code completion /** Necessary for code completion
*/ */
override def getContentAssistant(sourceViewer: ISourceViewer): IContentAssistant = { override def getContentAssistant(sourceViewer: ISourceViewer): IContentAssistant = {
Expand Down Expand Up @@ -118,6 +113,12 @@ class TemplateConfiguration(prefStore: IPreferenceStore, templateEditor: Templat
Array(detector, localDetector) Array(detector, localDetector)
} }


override def getAnnotationHover(viewer: ISourceViewer): IAnnotationHover = {
new DefaultAnnotationHover(true) {
override def isIncluded(a: Annotation): Boolean = TemplateEditor.annotationsShownInHover(a.getType)
}
}

override def getTextHover(sv: ISourceViewer, contentType: String, stateMask: Int): ITextHover = { override def getTextHover(sv: ISourceViewer, contentType: String, stateMask: Int): ITextHover = {
if (templateEditor != null && contentType.equals(TemplatePartitions.TEMPLATE_SCALA)) { if (templateEditor != null && contentType.equals(TemplatePartitions.TEMPLATE_SCALA)) {
val cu = TemplateCompilationUnit.fromEditor(templateEditor) val cu = TemplateCompilationUnit.fromEditor(templateEditor)
Expand Down
Expand Up @@ -20,11 +20,12 @@ import org.eclipse.ui.editors.text.TextEditor
import org.eclipse.ui.texteditor.ChainedPreferenceStore import org.eclipse.ui.texteditor.ChainedPreferenceStore
import org.scalaide.play2.PlayPlugin import org.scalaide.play2.PlayPlugin



class TemplateEditor extends TextEditor with ISourceViewerEditor with InteractiveCompilationUnitEditor { class TemplateEditor extends TextEditor with ISourceViewerEditor with InteractiveCompilationUnitEditor {
private lazy val preferenceStore = new ChainedPreferenceStore(Array((EditorsUI.getPreferenceStore()), PlayPlugin.prefStore)) private lazy val preferenceStore = new ChainedPreferenceStore(Array((EditorsUI.getPreferenceStore()), PlayPlugin.prefStore))
private val sourceViewConfiguration = new TemplateConfiguration(preferenceStore, this) private val sourceViewConfiguration = new TemplateConfiguration(preferenceStore, this)
private val documentProvider = new TemplateDocumentProvider() private val documentProvider = new TemplateDocumentProvider()

setSourceViewerConfiguration(sourceViewConfiguration); setSourceViewerConfiguration(sourceViewConfiguration);
setPreferenceStore(preferenceStore) setPreferenceStore(preferenceStore)
setDocumentProvider(documentProvider); setDocumentProvider(documentProvider);
Expand Down Expand Up @@ -70,4 +71,10 @@ class TemplateEditor extends TextEditor with ISourceViewerEditor with Interactiv
annotationModel.replaceAnnotations(previousAnnotations.toArray, newAnnotations.toMap.asJava) annotationModel.replaceAnnotations(previousAnnotations.toArray, newAnnotations.toMap.asJava)
previousAnnotations = newAnnotations.unzip._1 previousAnnotations = newAnnotations.unzip._1
} }
}

object TemplateEditor {
/** The annotation types shown when hovering on the left-side ruler (or in the status bar). */
val annotationsShownInHover = Set(
"org.eclipse.jdt.ui.error", "org.eclipse.jdt.ui.warning", "org.eclipse.jdt.ui.info")
} }

0 comments on commit fc2b2a6

Please sign in to comment.