Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interactive scaladoc used when showing the hover and when presenting scala symbol in the completion popup. Fix #1000453, Fix #1000210.
- Loading branch information
1 parent
fdcf2fa
commit 5a6447c
Showing
18 changed files
with
473 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/pc/DocumentationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package scala.tools.eclipse | ||
package pc | ||
|
||
import javaelements.ScalaCompilationUnit | ||
import scala.tools.nsc.doc.base.comment.Comment | ||
import scala.tools.nsc.interactive.Response | ||
import scala.reflect.internal.util.{ Position, SourceFile } | ||
import org.junit._ | ||
|
||
object PresentationCompilerDocTest extends testsetup.TestProjectSetup("pc_doc") | ||
|
||
class PresentationCompilerDocTest { | ||
import PresentationCompilerDocTest._ | ||
|
||
@Test | ||
def variableExpansion() { | ||
val expect: Comment => Boolean = { cmt => | ||
existsText(cmt.body, "correctly got derived comment") | ||
} | ||
doTest(open("varz.scala"), expect) | ||
} | ||
|
||
@Test | ||
def inheritedDoc() { | ||
val expect: Comment => Boolean = { cmt => | ||
existsText(cmt.todo, "implement me") | ||
} | ||
doTest(open("inherited.scala"), expect) | ||
} | ||
|
||
private def doTest(unit: ScalaCompilationUnit, expectation: Comment => Boolean) { | ||
project.withSourceFile(unit) { (src, compiler) => | ||
val pos = docPosition(src, compiler) | ||
val response = new Response[compiler.Tree] | ||
compiler.askTypeAt(pos, response) | ||
response.get.left.toOption match { | ||
case None => Assert.fail("Couldn't get typed tree") | ||
case Some(t) => | ||
compiler.parsedDocComment(t.symbol, t.symbol.enclClass) match { | ||
case None => Assert.fail("Couldn't get documentation") | ||
case Some(comment) => Assert.assertTrue(s"Expectation failed for $comment", expectation(comment)) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
val rangeStartMarker = "/*s*/" | ||
val rangeEndMarker = "/*e*/" | ||
|
||
private def docPosition(src: SourceFile, compiler: ScalaPresentationCompiler): Position = { | ||
val content = new String(src.content) | ||
val start = content.indexOf(rangeStartMarker) + rangeStartMarker.length | ||
val end = content.indexOf(rangeEndMarker, start) | ||
compiler.rangePos(src, start, start, end) | ||
} | ||
|
||
private def existsText(where: Any, text: String): Boolean = where match { | ||
case s: String => s contains text | ||
case s: Seq[_] => s exists (existsText(_, text)) | ||
case p: Product => p.productIterator exists (existsText(_, text)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
org.scala-ide.sdt.core.tests/test-workspace/pc_doc/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
18 changes: 18 additions & 0 deletions
18
org.scala-ide.sdt.core.tests/test-workspace/pc_doc/.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>pc_doc</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.scala-ide.sdt.core.scalabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.scala-ide.sdt.core.scalanature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
13 changes: 13 additions & 0 deletions
13
org.scala-ide.sdt.core.tests/test-workspace/pc_doc/src/inherited.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
trait T { | ||
/** | ||
* @todo implement me | ||
*/ | ||
def foo(): Unit | ||
} | ||
|
||
abstract class C extends T { | ||
override def foo() {} | ||
|
||
/*s*/foo/*e*/() | ||
} |
11 changes: 11 additions & 0 deletions
11
org.scala-ide.sdt.core.tests/test-workspace/pc_doc/src/varz.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
/** | ||
* @define BaseComment correctly got $BaseVar comment | ||
*/ | ||
trait TV | ||
|
||
/** | ||
* $BaseComment | ||
* @define BaseVar derived | ||
*/ | ||
class /*s*/CV/*e*/ extends TV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.