vdoc: refactor html_highlight
and handle strings with string interpolations (eg. ${a}.${b}.${c}
)
#19784
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.
The goal for this PR was to fix the issues with highlighting strings with string interpolations (of which I call them as "complex strings"):
html_highlight
misses most of the code that should be highlighted due to the index greater than thestring
token's byte index. This is triggered for call expression that have complex string as an argument."${a} world"
->"${a}"world"
)"${a}.${b}.${c}"
->"${a.${b.${c"
)A refactor inside
html_highlight
was also done in order to make the fix possible and to make the code more manageable (and more performant, I suppose) as more rules are added.Photo: left: w/ fix, right: w/o fix (sorry if it's reversed)
🤖 Generated by Copilot at 8a3970e
This pull request enhances the vdoc tool by improving the syntax highlighting of string interpolation and builtin types in both HTML and terminal output. It also refactors some common code to use a strings.Builder and a shared array of
highlight_builtin_types
.🤖 Generated by Copilot at 8a3970e
HighlightTokenTyp
(link)highlight_code
function withwrite_token
function that writes to a strings.Builder (link)html_highlight
function main loop (link)builtin
array to module level and rename tohighlight_builtin_types
(link, link)utils.v
(link)highlight_builtin_types
array in bothhtml_highlight
andcolor_highlight
functions (link)