-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use offsets from .bgv
file to select appropriate text
#10510
base: master
Are you sure you want to change the base?
Conversation
|
||
private Line findLine(EditorCookie cake, int line) { | ||
try { | ||
return cake.getLineSet().getOriginal(line - 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.
Possibly IGV should honor https://www.graalvm.org/graphio/javadoc/jdk/graal/compiler/graphio/GraphLocations.html#locationOffsetStart(java.lang.Object) when the line isn't positive.
@@ -63,24 +67,48 @@ private void openOrView(boolean focus) { | |||
return; | |||
} | |||
int line = location.getLine(); | |||
int[] offsets = location.getOffsetsOrNull(); |
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.
Text based languages (like Truffle ones) are likely to fill offsets rather than line numbers. Passing the offsets to the LocationOpener
in faba84a and using the offsets rather than line when present. More an experiment for your consideration than bullet proof code right now.
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 don't have much opinion since I never use this functionality so you should make it work in some rational way. If the two ways of addressing the text disagree then it's unclear what you should do. Naively I might assume that the line number is more to be trusted given that offsets seem a bit squishy given differences in line terminations between windows and unix, plus the lack of actual terminator characters in a UI element that displays text. How are these mismatches expected to be dealt with?
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.
re. different newline terminators: the information about the OS the code was compiled in is lost during the compilation step, and cannot be even dumped to BGV. Maybe a hint for truffle
to represent positions using line:column pair rather than offsets.
From the user's standpoint I agree that the whole line is too coarse; it's far better to point at a specific position, if we have such data.
I suggest to make an option for this: if the IGV knows (the user configures it) the line terminator use on the compiling machine, it can then recompute the offset to this machine's newline style and to line:column coordinates.
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 hope we'll find a way that works for current as well as future use-cases without a configuration option. I hope #10510 (comment) is a sound approach to achieve so.
.bgv
file.bgv
file to select appropriate text
task.removeTaskListener(whenShowing[0]); | ||
Mutex.EVENT.postReadRequest(() -> { | ||
if (offsets == null) { | ||
StatusDisplayer.getDefault().setStatusText(Bundle.ERR_LineNotFound()); |
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 not sure if I'm understanding the control flow here but it looks to me that if the location had a valid line but no offsets you'd report ERR_LineNotFound
. Am I missing some subtlety?
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 you are right Tom, 8955e69 would address that
- I have to admit I am not sure if
JEditorPane.select
is the right way to highlight the selection - maybe there is something better like attaching some annotation to a Line.Part
- I can try to implement whatever you guys think is the best way to handle the highlight
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.
Thinking a bit more, the editor will have a position that corresponds to the line termination so a unix file and the editor pane should agree about offsets so I think select
will do the right thing. I'm unsure what would happen if the underlying file had windows CR+LF terminators so it would be good to test that out and make it work correctly. I don't know anything about best practices in UI code so I can't offer an opinion about which API to use, but select
seems reasonable to me.
@@ -63,24 +67,48 @@ private void openOrView(boolean focus) { | |||
return; | |||
} | |||
int line = location.getLine(); | |||
int[] offsets = location.getOffsetsOrNull(); |
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.
re. different newline terminators: the information about the OS the code was compiled in is lost during the compilation step, and cannot be even dumped to BGV. Maybe a hint for truffle
to represent positions using line:column pair rather than offsets.
From the user's standpoint I agree that the whole line is too coarse; it's far better to point at a specific position, if we have such data.
I suggest to make an option for this: if the IGV knows (the user configures it) the line terminator use on the compiling machine, it can then recompute the offset to this machine's newline style and to line:column coordinates.
...zer/SourceRepository/src/main/java/org/graalvm/visualizer/source/impl/ui/LocationOpener.java
Outdated
Show resolved
Hide resolved
Thank you for the reviews. Yup, line endings may cause some misalignment. Let's try:
That way we favor existing behavior and enhance it when additional information is present. I'll write some tests and rewrite the logic now. |
Shouldn't we rather specify that offsets in the IGV treat new line as a single character? That's how Truffle Given Enso is the first system trying to use the offsets, we can make some small adjustments to the specification to make things easier. |
With c4f059d I like what I see, CCing @Akirathan: Looks like with this PR the IGV can work for Enso IR graphs well enough. I hope that with #10510 (comment) we have a good compromise to keep the existing behavior unmodified. Can you do some testing on your side and possibly integrate this enhancement? It would increase our (Enso compiler team) productivity when exploring Enso IR graphs a lot. Btw. We'd be in a need of a new IGV release then... |
Enso is trying to generate IGV graph for our internal
IR
:We had issues to provide proper
nodeSourceLocation
information. I had to debug visualizer code to find out what's wrong. While doing that I made few fixes.-1
as line location - IGV was then doing nothing - with 75d41ee it at least opens the fileNullPointerException
s so I am adding checks andassert
to catch that earlierWith these changes IGV picks up
start
andend
offset fromlocation
property and is capable to select appropriate source range. CCing @tkrodriguez, @sdedic, @Akirathan