I just started working a bit on hyperlink detector. Two things that would be nice if I can solve them:
Does someone know a way to create a function (String => scala.tools.eclipse.javaelements.ScalaSourceFile) where String contains sources? Currently there exists such a function (https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/testsetup/TestProjectSetup.scala#L68) but it expects a path to a source file and not the sources directly.
I need this for the test suite because I'm too lazy to create a file for each simple test.
It looks like the current implementation of the hyperlink detector can't locate symbols defined in Java (https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core/src/scala/tools/eclipse/hyperlink/text/detector/ScalaDeclarationHyperlinkComputer.scala#L74). If I deactivate the check for a Java symbol I do not get any result back, why is that the case? Is it possible to fix that?
Thanks,
Simon
On Fri 05 Oct 2012 01:26:27 PM CEST, iulian dragos wrote:Ok, I will look at that.
You could whip something up based on SDTTestUtils.addFileToProject and
changeContentOfFile.
Yes, I would highly appreciate any additional information. I could fix the ticket about type aliases you commented two days ago, but currently it works only for Scala symbols (I implemented it in ScalaDeclarationHyperlinkComputer). Probably I need to use the way as mentioned in DeclarationHyperlinkDetector.javaDeclarationHyperlinkComputer.
The current implementation of hyperlink detectors needs a bit of love.
I think it's too complicated, and we should get rid of a couple of
layers of indirection. Other than that, no, we can't resolve links to
Java symbols because we don't type-check Java sources. The only thing
the Scala compiler can do for Java symbols is to 'resolve' them to a
Scala symbol, whose `pos` field is not correctly set. From there, we
need the JDT to step in (based on the fully-qualified name).
It would be great if you had a look at it. My suggestion would be to
break the current composite pattern, and have separate hyperlink
detector classes (and remove the 'strategy' pattern as well), and pass
several detectors in the SourceViewerConfiguration class (since you
can pass more than one).
Let me know if you'd like to know more about it, I can talk for hours :)
I also looked at resolving calls to the unapply-/unapplySeq-/update-method or to syntax sugar like `x = x+y <=> x += y` but either they result in missing information or in incorrect positions. The only method which seems currently to work is the apply-method. If you have the time it would be nice if you can tell me if these things could completely solved inside of scala-ide (and not in scalac) and where I have to look to in order to solve these things.
I'm not sure what you mean. Here's the relevant part of the code: https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core/src/scala/tools/eclipse/hyperlink/text/detector/ScalaDeclarationHyperlinkComputer.scala#L67 As you can see, for 'apply' we extract 2 symbols from the tree: one for the qualifier (meaning the definition under the cursor), and another for the `apply` method itself. If you do the same for other standard names, like `unapply` and `unapplySeq`, the rest of the machinery should create the hyperlinks for those symbols.
Tree: Select
[...]
tree.tpe: [A](x: A)Some[A]
symbol: method apply
symbol.info: [A](x: A)Some[A]
Tree: SelectThe `symbol` is not correct any more.
[...]
tree.tpe: Some.type
symbol: object Some
symbol.info: Some.type
Unfortunately, I don't fully understand what you are doing in this case, and in what way it fails. My gut feeling is that the compiler provides all the required information, so it would help to have some code to discuss. Maybe there's a simple tweak to make it work ;-)
Tree: SelectBoth `symbol` and `tree.pos` are correct.
tree.pos: RangePosition(/home/antoras/dev/runtime-EclipseApplicationwithEquinoxWeaving/Test/src/Test.scala, 68, 70, 71)
tree.tpe: (i: Int)C
symbol: method +
symbol.info: (i: Int)C
Tree: ApplyHere, both `symbol` and `tree.pos` are wrong.
tree.pos: RangePosition(/home/antoras/dev/runtime-EclipseApplicationwithEquinoxWeaving/Test/src/Test.scala, 76, 78, 82)
tree.tpe: Unit
symbol: method c_=
symbol.info: (x$1: C)Unit
Yes this works for `apply` but not for `unapply` or `unapplySeq`. This can be tested on `val Some(x) = Some(0)`. ScalaSpy shows on RHS
On 10/06/2012 10:46 PM, iulian dragos wrote:
I'm not sure what you mean. Here's the relevant part of the code: https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core/src/scala/tools/eclipse/hyperlink/text/detector/ScalaDeclarationHyperlinkComputer.scala#L67 As you can see, for 'apply' we extract 2 symbols from the tree: one for the qualifier (meaning the definition under the cursor), and another for the `apply` method itself. If you do the same for other standard names, like `unapply` and `unapplySeq`, the rest of the machinery should create the hyperlinks for those symbols.
Tree: Select
[...]
tree.tpe: [A](x: A)Some[A]
symbol: method apply
symbol.info: [A](x: A)Some[A]
but on LHS
Tree: SelectThe `symbol` is not correct any more.
[...]
tree.tpe: Some.type
symbol: object Some
symbol.info: Some.type
object MySome {
def unapply(a: Int): Option[String] = Some(a.toString)
}
class TestFoo {
val MySome(x) = 10
}