-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Signature for PrettyPrint #573
Conversation
Removing the WIP because I find difficult implementing the tests, although I will try more. |
stdlib/prettyprint/0/prettyprint.rbs
Outdated
@@ -0,0 +1,364 @@ | |||
# frozen_string_literal: true |
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.
RBS doesn't understand frozen_string_literal
directive. ✂️
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.
I will remove it
stdlib/prettyprint/0/prettyprint.rbs
Outdated
# output | ||
# end | ||
# | ||
def self.format: (?untyped output, ?Integer maxwidth, ?String newline, ?untyped genspace) ?{ (Integer) -> Integer } -> untyped |
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.
I think we can make an interface with <<
method, and use the interface as the type of output
here?
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.
If I correctly understood something like:
interface _Output
def <<: (?String obj, ?String sep, ?String newline, ?untyped genspace ) ?{ (Integer) -> Integer } -> void
end
An then the definition becomes
def self.format: (?untyped output, ?Integer maxwidth, ?String newline, ?untyped genspace) ?{ (Integer) -> Integer } -> Output
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.
I mean like the following:
class PrettyPrint
interface _Output
def <<: (String) -> void
end
def self.format: (?_Output output, ?Integer maxwidth, ?String newline, ?untyped genspace) ?{ (Integer) -> Integer } -> _Output # !?!?
end
Yes, it's my bad... I finally found that the type cannot be written in RBS... 😢
Leave the type of the first argument ?untyped
. 🙏 (I'm sorry for the confusion.)
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.
No worries at all :)
stdlib/prettyprint/0/prettyprint.rbs
Outdated
# | ||
# If `width` is not specified, obj.length is used. | ||
# | ||
def text: (untyped obj, ?Integer width) -> untyped |
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.
I'm wondering if we need untyped
here as the type of obj
. Is there any reason to make it other than String
?
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.
This is a good point, although the documentation is a little bit obscure for me. It's implicit the use of String.
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.
Yeah, I also got confused a bit. 😓
As far as I know, obj
is (implicitly) assumed to be a String
.
|
||
# Breaks the buffer into lines that are shorter than #maxwidth | ||
# | ||
def break_outmost_groups: () -> untyped |
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.
Seems like these -> untyped
can be -> void
?
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.
definitely. I will change this
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.
🚧
@soutaro thanks a lot for the comments and the test templates. I'm really happy to try to give back what Ruby gave to me in all these years. |
4680fe7
to
3cc2124
Compare
0d1b887
to
6f12c6f
Compare
I've checked the original code and modified the PR accordingly and did the requested changes. I also wrote the tests for it. |
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.
Looks great! 💯
Could you fixup the commits?
* Added prettyprint.rbs file with definitions and rdoc annotations * Added the tests
6f12c6f
to
54bba31
Compare
Done :) |
Merged! Thank you! 🎉 |
Added the prettyprint signature file.
Marked as WIP because I'm trying to write the related tests.