lexer: fixed syntax highlighting breaks on longer files - #1357
Open
jorbakk wants to merge 1 commit into
Open
Conversation
If lexer starts parsing at a file offset determined by the horizon variable and this offset happens to be within a string, then all non-strings are highlighted as strings and vice versa. This only occurs with strings that are delimited symmetrically, e.g. single and double quotes. It doesn't affect other syntactic delimiters that are non-symmetric, e.g. parentheses. With this patch, if the horizon variable is set to -1, the whole file buffer is run through the lexer. Performance is still reasonably good, as no syntax highlighting takes place outside of the viewport. Fixes issue martanne#1253
Contributor
Author
|
Without the patch, this would just set the horizon to -1 which means
that lexing of the file begins at
viewport.start - (-1) = viewport.start + 1
which is a one byte offset into the current viewport.
With the patch, the exact same command sets the horizon to the beginning
of the file. So, you also need this command to set the horizon with the
patch to activate it. I made it configurable so that you can opt out if
you might have performance issues on very slow machines.
Currently, it's deactivated by default and it follows the old behaviour
for backward compatibility. However, lexing is fast and otherwise syntax
highlighting is simply not correct and I see no other way to fix this
issue other than to parse the file from the beginning. So it might be
reasonable to activate it by default and remove the horizon variable. I
would be happy to send a patch to do so.
…On 2026-05-30 22:53, Joe M wrote:
*4d30* left a comment (martanne/vis#1357)
<#1357 (comment)>
Cannot the horizon command do this?
|:set horizon -1 |
—
Reply to this email directly, view it on GitHub
<#1357?email_source=notifications&email_token=AWXEBLIV3AKRBADWW7ELNLD45NC5HA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINJYGQ3TENBXGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4584724705>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWXEBLO4SZBPGXMCKNYPACL45NC5HAVCNFSM6AAAAACZQQWGF6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DKOBUG4ZDINZQGU>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If lexer starts parsing at a file offset determined by the horizon variable and this offset happens to be within a string, then all non-strings are highlighted as strings and vice versa.
This only occurs with strings that are delimited symmetrically, e.g. single and double quotes. It doesn't affect other syntactic delimiters that are non-symmetric, e.g. parentheses.
With this patch, if the horizon variable is set to -1, the whole file buffer is run through the lexer. Performance is still reasonably good, as no syntax highlighting takes place outside of the viewport.
Fixes issue #1253