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

vdoc: refactor html_highlight and handle strings with string interpolations (eg. ${a}.${b}.${c}) #19784

Merged
merged 6 commits into from
Nov 28, 2023

Conversation

nedpals
Copy link
Member

@nedpals nedpals commented Nov 6, 2023

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 the string token's byte index. This is triggered for call expression that have complex string as an argument.
  • String dollar / string interpolation sign not recognized properly.
  • String quotes are added to the string content automatically regardless of the position. (eg. "${a} world" -> "${a}"world")
  • Closing curly string interpolation brace is only rendered when the content of the string on their right is side is empty. (eg. "${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)
Screen Shot 2023-11-06 at 5 04 48 PM

🤖 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

  • Add support for string interpolation syntax highlighting in HTML output (link, link, link)
  • Define new enum values for interpolation tokens in HighlightTokenTyp (link)
  • Replace highlight_code function with write_token function that writes to a strings.Builder (link)
  • Handle interpolation tokens in html_highlight function main loop (link)
  • Refactor builtin array to module level and rename to highlight_builtin_types (link, link)
    • Avoid duplication and improve maintainability of builtin type names in utils.v (link)
    • Use highlight_builtin_types array in both html_highlight and color_highlight functions (link)

@spytheman
Copy link
Member

Please add a test, that can be run to check that the new functionality will not regress.
Screenshots are nice for people, but imho generating a bunch of html, from a known source, then checking that the generated html has specific things in it, will be easier to test automatically.

@nedpals
Copy link
Member Author

nedpals commented Nov 14, 2023

Still in the middle of adding tests and further documentation but had no time at the moment. Will reopen this at a later time.

@spytheman spytheman force-pushed the vdoc-handle-complex-string branch from 655d58c to 5c4459a Compare November 28, 2023 12:44
@spytheman spytheman merged commit 782bf86 into vlang:master Nov 28, 2023
42 checks passed
@ttytm
Copy link
Member

ttytm commented Nov 28, 2023

Good work guys!

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

Successfully merging this pull request may close these issues.

3 participants