Skip to content

Commit

Permalink
Added Scala Plugin Spy.
Browse files Browse the repository at this point in the history
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
dragos committed Oct 4, 2012
1 parent ca44dc9 commit a9fd272
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions org.scala-ide.sdt.build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
7 changes: 7 additions & 0 deletions org.scala-ide.sdt.dev.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
8 changes: 8 additions & 0 deletions org.scala-ide.sdt.spy/.classpath
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions org.scala-ide.sdt.spy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
26 changes: 26 additions & 0 deletions org.scala-ide.sdt.spy/.project
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 32 additions & 0 deletions org.scala-ide.sdt.spy/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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: .
7 changes: 7 additions & 0 deletions org.scala-ide.sdt.spy/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
icons/,\
.,\
plugin.xml,\
plugin.properties
Binary file added org.scala-ide.sdt.spy/icons/cog.ico
Binary file not shown.
Empty file.
16 changes: 16 additions & 0 deletions org.scala-ide.sdt.spy/plugin.xml
Original file line number Diff line number Diff line change
@@ -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>
14 changes: 14 additions & 0 deletions org.scala-ide.sdt.spy/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
75 changes: 75 additions & 0 deletions org.scala-ide.sdt.spy/src/org/scalaide/spy/SpyView.scala
Original file line number Diff line number Diff line change
@@ -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.