Skip to content
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

Special way to underline with empty spans #108

Open
epage opened this issue Mar 21, 2024 · 7 comments
Open

Special way to underline with empty spans #108

epage opened this issue Mar 21, 2024 · 7 comments
Labels
C-enhancement Category: enhancement

Comments

@epage
Copy link
Contributor

epage commented Mar 21, 2024

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 epage added the C-enhancement Category: enhancement label Mar 21, 2024
@chengr4
Copy link

chengr4 commented Aug 14, 2024

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?

@epage
Copy link
Contributor Author

epage commented Aug 14, 2024

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?

@estebank
Copy link

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 (-).

@chengr4
Copy link

chengr4 commented Aug 15, 2024

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_
                       ^

@estebank
Copy link

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

This is a line of "code
                       ^

@chengr4
Copy link

chengr4 commented Aug 20, 2024

@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 🤔?

@estebank
Copy link

estebank commented Aug 20, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

3 participants