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
Fix #9116: Error source highlighting in presence of tabs #9118
base: trunk
Are you sure you want to change the base?
Conversation
Actually, after discussing with @Octachron it might not be too hard to address multi-line errors as well. I'll add a commit for that. |
I just added three commits that propose to address the issue for multiline errors. Before the PR, a multiline error is displayed as follows. If the source code is of the form:
where "foobar" is not part of the error, then the error location is displayed as:
i.e. every character that is not part of the error but shares a line with it is replaced by a dot. This is problematic in presence of tabs, since replacing a tab with a dot will break the alignment. To fix the issue, I propose to slightly change the way multiline errors are displayed, and only replace with a dot non-space characters outside the error. On the source code above, the new format shows:
If alignment is performed using tabs, then alignment is now preserved. Again, the PR is best reviewed commit by commit. |
Display blank characters (' ' or '\t') as themselves instead of '.' to avoid messing with the alignment in presence of tabs.
Reading your description of the approach, I thought it was a good idea, but in fact I'm not fond of the look of testsuite examples with irregular dot placement:
Could we consider instead just displaying spaces for characters other than tab? This would give the following
(The simplest implementation implies having trailing spaces on the last line, which I think is perfectly fine.) Another approach would be to use fixed ellipsis markers (eg. |
(In fact one should consider the distance between the location and the closest tab character (excluded), to avoid precisely this alignment issue.) |
Right, I wasn't fond of the irregular dot placement myself, and I like both ideas of replacing all dots by spaces and inserting ellipsis markers. I'll see whether the second option is not too cumbersome to implement; and if it is, I'll go with the first one. |
In this example, spaces look as follows
and the ellipsis markers would look as follows
It's clear to me that |
I just pushed a first implementation of the "..." approach (in separate commits that we can rebase later if we decide to keep them). |
This looks nice; nitpick: we should print ellipses if there are non-whitespace characters before (or after) on the line. |
After a whiteboard discussion with Armaël, we propose the following approach:
Using |
I encountered the issue that this PR is trying to fix, on OCaml 4.13 while browsing the build logs |
This PR fixes error messages with source highlight in batch mode in presence of tabulations, that is, messages of the form:
Before the PR, the
^
characters are aligned using spaces. After the PR, the spikes (^
) are aligned using tabs whenever a tab is used in the source code (and spaces otherwise). (I added a test in a first commit, then fixed the test in the next commit)Note that this PR does not addresses situations where tabs are used in the middle of the error (how many spikes for each tab?)
or multi-line errors.It's not so clear what to do in those cases, but fortunately I don't think they would come up too much in practice.Fixes #9116 .