annotate-snippets-rs icon indicating copy to clipboard operation
annotate-snippets-rs copied to clipboard

Special way to underline with empty spans

Open epage opened this issue 1 year ago • 7 comments

The toml crate occasionally returns empty spans and #107 fixed it so we could render something but it might be useful to try to highlight the space between characters, rather than a character.

epage avatar Mar 21 '24 17:03 epage

Hi @epage,

I’m working on addressing this ticket and would appreciate your guidance.

Background

According to your fix in #107, you added additional col annotation span allowing symbols of Error (^), Warning (-) etc., to be displayed.


My understanding of the goal for this ticket is illustrated by the following example:

asdf_

as_f
       'd" belongs here        

'_' represents "highlight" rather than any specific symbol.

If this is the case, we would need to find a way to place the "highlight" either directly after or between characters, which is very different (I think) from the current implementation. Do you have any ideas on how we might achieve this? Or is my understanding for ticket incorrect?

chengr4 avatar Aug 14 '24 03:08 chengr4

To recap, toml sometimes highlights empty ranges (e.g. bytes at 0..0), like at EOF or EOL when a terminating character is needed.

Do you have any ideas on how we might achieve this? Or is my understanding for ticket incorrect?

This is a "needs design" type of issue; no decision is made about what this should look like.

One idea I've toyed with for EOL is for us to render \n or \r\n as Dimmed and highlight those. We could pick a character to similarly represent EOF. In snapbox diffs, I chose ∅.

That is only one idea and that doesn't cover other cases of empty spans.

@estebank any thoughts?

epage avatar Aug 14 '24 13:08 epage

One option is to do what we do in rustc now: replace the ASCII control characters with their Unicode graphical representation (like ). For zero-width spans in rustc in general, we print a one-width underline starting at the right position and "bleeding" to the right. If you look at a representative test, you can see that showing something seems to work better than leaving the "hidden" char hidden. I had considered a long time ago using /\ as an underline pointing in between to char positions, but ended up never doing it because there was no way of doing the same for the secondary spans (-).

estebank avatar Aug 15 '24 02:08 estebank

If I understand correctly, now For EOL, we have two options

# render \n or \r\n
This is a line of "code␍␊
                       ^
# OR

# print a one-width underline
This is a line of "code_
                       ^

And for EOF, we also have two options

# render ∅
This is a line of "code∅
                      ^
# OR

# print a one-width underline
This is a line of "code_
                       ^

chengr4 avatar Aug 15 '24 08:08 chengr4

@chengr4 you can also have, for both of these:

This is a line of "code
                       ^

estebank avatar Aug 19 '24 22:08 estebank

@chengr4 you can also have, for both of these:

This is a line of "code
                       ^

@estebank I think this is the current state and @epage wants to change it.

Or I misunderstood 🤔?

chengr4 avatar Aug 20 '24 05:08 chengr4

Right, what I'm saying is that leaving as-is is a valid decision (although not necessarily ideal). I've found pointing at nothing also useful for suggestions like

code
    ^ help: missing `;` here

so you might need the flexibility to support both substitutions and the current behavior, depending on whether you want to point at a hidden char or merely point at the point after some code (which can be right on a newline).

estebank avatar Aug 20 '24 16:08 estebank