-
Notifications
You must be signed in to change notification settings - Fork 8
Adds UAST encoding options and improves tests #126
Conversation
Signed-off-by: ncordon <[email protected]>
The reason for overrriding methods with default parameters instead of coding with default arguments is because if we import the package from a Java, they do not work: https://docs.scala-lang.org/tour/default-parameter-values.html Signed-off-by: ncordon <[email protected]>
This makes possible, as explained in package.scala file, to use a method f(fmt: UastFormat) as f(0) or f(1) and a method g(fmt: Int) as g(UastBinary) or g(UastYaml) Signed-off-by: ncordon <[email protected]>
Includes positions mainly, to be able to test against all new orders in libuast Signed-off-by: ncordon <[email protected]>
Signed-off-by: ncordon <[email protected]>
Invalid means a number out of the set of accepted ones for iterator orders Signed-off-by: ncordon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 9 of 17 files at r1.
Reviewable status: 9 of 17 files reviewed, 2 unresolved discussions (waiting on @ncordon)
src/main/scala/org/bblfsh/client/v2/BblfshClient.scala, line 157 at r1 (raw file):
* Since v2. */ def decode(buf: ByteBuffer): ContextExt = Libuast.synchronized {
As written I think this is a breaking change to the API. Should we provide a default argument?
(I believe only DP team may be using this right now, but I'd really like to avoid breaking them without a good reason)
This also applies below.
src/main/scala/org/bblfsh/client/v2/package.scala, line 14 at r1 (raw file):
import BblfshClient._ /** Allow to use methods
I'm not sure why we would want to pun away the types here. Is this needed for some other interface we're relying on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 17 files at r1.
Reviewable status: 13 of 17 files reviewed, 2 unresolved discussions (waiting on @ncordon)
src/main/scala/org/bblfsh/client/v2/BblfshClient.scala, line 157 at r1 (raw file): Previously, creachadair (M. J. Fromberger) wrote…
No no, I have not touched the API at all. The syntax What I do not recommend is having default parameters in Scala, because they are not compatible with Java, as documented here. Of course we can use them if you prefer to do it. But that is why I have duplicated the
|
src/main/scala/org/bblfsh/client/v2/package.scala, line 14 at r1 (raw file): Previously, creachadair (M. J. Fromberger) wrote…
I am only exposing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 17 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @creachadair)
src/main/scala/org/bblfsh/client/v2/BblfshClient.scala, line 157 at r1 (raw file):
Previously, ncordon (Nacho Cordón) wrote…
No no, I have not touched the API at all. The syntax
buf.decode()
was not provided by these functions, but by animplicit
here.implicits
lie in memory and whenever I try to usebuf.decode()
Scala says: okay I do not know how to calldecode
on aByteBuffer
explicitly, do I have anyimplicits
which tells me how to do it in my runtime? Here is some documentation for them: https://docs.scala-lang.org/overviews/core/implicit-classes.htmlWhat I do not recommend is having default parameters in Scala, because they are not compatible with Java, as documented here. Of course we can use them if you prefer to do it. But that is why I have duplicated the
decode
methods for example into:def decode(buf, format) def decode(but) = decode(buf, UastBinary)
Understood, thanks for the explanation!
Given that this decode
is to satisfy the interface, and isn't called directly by the client, I agree it doesn't make sense to add in defaults.
(As an aside: Implicit classes are a great example of a feature that really helps the author of the code, at the expense of the reader. I wish language designers would think about both sides more carefully.)
src/main/scala/org/bblfsh/client/v2/package.scala, line 14 at r1 (raw file): Previously, ncordon (Nacho Cordón) wrote…
I would rather erase this of course, but then we delete the backward compatibility with the old syntax passing numbers, and I prefer to have these things here. They are here because they would be in scope for the whole package, since |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! all files reviewed, all discussions resolved
src/main/scala/org/bblfsh/client/v2/package.scala, line 14 at r1 (raw file):
Previously, ncordon (Nacho Cordón) wrote…
I would rather erase this of course, but then we delete the backward compatibility with the old syntax passing numbers, and I prefer to have these things here. They are here because they would be in scope for the whole package, since
treeOrder
s anduastFormat
s are used in several files from the library and I want the old syntax to work everywhere inside the package
Makes sense, thanks for the clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! all files reviewed, all discussions resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2.
Reviewable status:complete! all files reviewed, all discussions resolved
src/main/scala/org/bblfsh/client/v2/BblfshClient.scala, line 157 at r1 (raw file): Previously, creachadair (M. J. Fromberger) wrote…
Yes, totally agree, when I started programming in Scala it was driving me mad constantly not knowing where the definitions for thing were because of the |
Just to clarify, tests are going to fail because in the file
would be encoded as:
due to this line which is code called by |
Signed-off-by: ncordon <[email protected]>
5b81fec
to
9cafe98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r3.
Reviewable status:complete! all files reviewed, all discussions resolved
It is the only format we can assure it is invertible Signed-off-by: ncordon <[email protected]>
libuast
native side to the managed layer.python-client
ones.Closes #107, closes #108
This change is