Skip to content
Browse files

Added Scala Plugin Spy.

This adds a view that can show the cursor offset in the current document,
and additional Scala compiler information:

* tree.pos (range positions)
* tree.tpe
* tree.symbol
* tree.tpe
  • Loading branch information...
1 parent ca44dc9 commit a9fd2726b6ece237373522cec0299932a9d61c47 @dragos committed Oct 2, 2012
View
1 org.scala-ide.sdt.build/pom.xml
@@ -20,6 +20,7 @@
<module>../org.scala-ide.sdt.aspects</module>
<module>../org.scala-ide.sdt.core</module>
<module>../org.scala-ide.sdt.core.tests</module>
+ <module>../org.scala-ide.sdt.spy</module>
<module>../org.scala-ide.sdt.debug</module>
<module>../org.scala-ide.sdt.debug.tests</module>
<module>../org.scala-ide.sdt.weaving.feature</module>
View
7 org.scala-ide.sdt.dev.feature/feature.xml
@@ -69,4 +69,11 @@ SUCH DAMAGE.
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.scala-ide.sdt.spy"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
View
8 org.scala-ide.sdt.spy/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
View
1 org.scala-ide.sdt.spy/.gitignore
@@ -0,0 +1 @@
+target/
View
26 org.scala-ide.sdt.spy/.project
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.scala-ide.sdt.spy</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ <arguments></arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments></arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments></arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
32 org.scala-ide.sdt.spy/META-INF/MANIFEST.MF
@@ -0,0 +1,32 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Scala Plugin Spy
+Bundle-SymbolicName: org.scala-ide.sdt.spy;singleton:=true
+Bundle-Version: 2.1.0.qualifier
+Bundle-Vendor: Scala IDE
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Require-Bundle:
+ org.eclipse.core.runtime,
+ org.eclipse.debug.ui,
+ org.eclipse.help,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.debug.ui,
+ org.eclipse.jdt.junit,
+ org.eclipse.jdt.launching,
+ org.eclipse.jdt.ui,
+ org.eclipse.jface.text,
+ org.eclipse.ui,
+ org.eclipse.ui.console,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.forms,
+ org.eclipse.ui.ide,
+ org.scala-ide.scala.library,
+ org.scala-ide.scala.compiler,
+ org.scala-ide.sdt.core;bundle-version="[2.1.0, 2.2.0)"
+Import-Package:
+ com.ibm.icu.text;apply-aspects:=false;org.eclipse.swt.graphics;apply-aspects:=false,
+ scala.tools.eclipse;apply-aspects:=false,
+ scala.tools.eclipse.contribution.weaving.jdt.ui.javaeditor.formatter;apply-aspects:=false
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ClassPath: .
View
7 org.scala-ide.sdt.spy/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ icons/,\
+ .,\
+ plugin.xml,\
+ plugin.properties
View
BIN org.scala-ide.sdt.spy/icons/cog.ico
Binary file not shown.
View
0 org.scala-ide.sdt.spy/plugin.properties
No changes.
View
16 org.scala-ide.sdt.spy/plugin.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ allowMultiple="false"
+ category="org.scala-ide.sdt.core.viewCategory"
+ class="org.scalaide.spy.SpyView"
+ icon="icons/cog.ico"
+ id="org.scalaide.spy.view"
+ name="Scala Spy View"
+ restorable="true">
+ </view>
+ </extension>
+</plugin>
View
14 org.scala-ide.sdt.spy/pom.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.scala-ide</groupId>
+ <artifactId>org.scala-ide.sdt.build</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ <relativePath>../org.scala-ide.sdt.build/pom.xml</relativePath>
+ </parent>
+ <artifactId>org.scala-ide.sdt.spy</artifactId>
+ <packaging>eclipse-plugin</packaging>
+
+</project>
View
75 org.scala-ide.sdt.spy/src/org/scalaide/spy/SpyView.scala
@@ -0,0 +1,75 @@
+package org.scalaide.spy
+
+import org.eclipse.jface.text.ITextSelection
+import org.eclipse.jface.viewers.ISelection
+import org.eclipse.swt.SWT
+import org.eclipse.swt.widgets.Composite
+import org.eclipse.swt.widgets.Text
+import org.eclipse.ui.ISelectionListener
+import org.eclipse.ui.IWorkbenchPart
+import org.eclipse.ui.part.ViewPart
+import scala.tools.eclipse.InteractiveCompilationUnit
+import scala.tools.eclipse.ui.InteractiveCompilationUnitEditor
+import org.eclipse.swt.graphics.Font
+import org.eclipse.jface.resource.JFaceResources
+
+class SpyView extends ViewPart {
+ private var textArea: Text = _
+
+ def setFocus() {
+ textArea.setFocus()
+ }
+
+ def createPartControl(parent: Composite) {
+ textArea = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL)
+ textArea.setFont(JFaceResources.getTextFont()) // fixed width font
+
+ getSite.getWorkbenchWindow().getSelectionService().addPostSelectionListener(listener)
+ }
+
+ override def dispose() {
+ super.dispose()
+ getSite.getWorkbenchWindow().getSelectionService().removePostSelectionListener(listener)
+ }
+
+ private def updateView(offset: Int, length: Int, part: IWorkbenchPart) {
+ textArea.setText("Offset: \t%s".format(offset.toString))
+ textArea.append("\nLength: \t%s".format(length.toString))
+
+ part match {
+ case icuEditor: InteractiveCompilationUnitEditor =>
+ for (cu <- icuEditor.getInteractiveCompilationUnit) {
+ cu.doWithSourceFile { (source, compiler) =>
+ import compiler._
+
+ val response = new Response[Tree]
+ compiler.askTypeAt(rangePos(source, offset, offset, offset + length), response)
+ response.get match {
+ case Left(tree) =>
+ textArea.append("\n\n============\n\nTree: \t\t" + tree.productPrefix)
+ textArea.append("\ntree.pos: \t%s".format(tree.pos))
+ textArea.append("\ntree.tpe: \t%s".format(tree.tpe))
+ textArea.append("\n\nsymbol: \t\t%s".format(tree.symbol))
+ for (sym <- Option(tree.symbol) if sym ne NoSymbol)
+ textArea.append("\nsymbol.info: \t%s".format(tree.symbol.info))
+
+ case _ =>
+
+ }
+
+ }
+ }
+ }
+ textArea.setSelection(0, 0)
+ }
+
+ object listener extends ISelectionListener {
+ override def selectionChanged(sourcePart: IWorkbenchPart, selection: ISelection) {
+ selection match {
+ case textSelection: ITextSelection =>
+ updateView(textSelection.getOffset(), textSelection.getLength(), sourcePart)
+ case _ =>
+ }
+ }
+ }
+}

0 comments on commit a9fd272

Please sign in to comment.
Something went wrong with that request. Please try again.