-
Notifications
You must be signed in to change notification settings - Fork 324
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
Text.to_display_text is (shortened) identity #6174
Changes from 6 commits
78ad6df
4bc2353
886ea39
387bd24
4012b16
621927b
a5022fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package org.enso.interpreter.node.expression.builtin.text; | ||
|
||
import com.ibm.icu.text.BreakIterator; | ||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
|
@@ -11,6 +13,7 @@ | |
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode; | ||
import org.enso.interpreter.runtime.data.text.Text; | ||
import org.enso.polyglot.common_utils.Core_Text_Utils; | ||
|
||
@BuiltinMethod(type = "Any", name = "to_display_text") | ||
public abstract class AnyToDisplayTextNode extends Node { | ||
|
@@ -32,6 +35,22 @@ Text showExceptions( | |
} | ||
} | ||
|
||
@Specialization | ||
Text convertText(Text self) { | ||
final var limit = 80; | ||
if (self.length() < limit) { | ||
return self; | ||
} else { | ||
return takePrefix(self, limit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we an ellipsis here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good idea indeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
"should we add an ellipsis?" is the question? |
||
} | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
private static Text takePrefix(Text self, final int limit) { | ||
var prefix = Core_Text_Utils.take_prefix(self.toString(), limit); | ||
return Text.create(prefix); | ||
} | ||
|
||
@Fallback | ||
Text doShowType(Object self, @Cached TypeToDisplayTextNode typeToDisplayTextNode) { | ||
return Text.create(typeToDisplayTextNode.execute(self)); | ||
|
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.
shouldn't that be lifted to a (
private static final
) constant ?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.
+1
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.
Originally the
limit
was only used locally in a single method. Then I had to move the iterator manipulation behind@TruffleBoundary
...