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

Rewrite source range highlight() #215

Merged
merged 3 commits into from
Mar 11, 2023
Merged

Rewrite source range highlight() #215

merged 3 commits into from
Mar 11, 2023

Conversation

c42f
Copy link
Member

@c42f c42f commented Mar 10, 2023

highlight() now always prints whole lines of source code, and can highlight arbitrary ranges using box drawing characters, not just with ANSI colors.

Use this to fix diagnostic printing so that it's comprehensible in a non color terminal and so that pasting errors into non-color environments works, as described in #150 (comment).

The box drawing characters from WGL4 seem like a good balance of:

I've also found it's helpful to prepend any lines of annotation with a Julia # comment where possible - this ensures that copy+paste into websites with syntax highlighting will highlight the annotations separately from the code.

A simple example:

julia> (x - (c <--- d))
ERROR: ParseError:
(x - (c <--- d))
#       └──┘ ── invalid operator @ REPL[48]:1:9

With color

line_printing_2

Also some semi-related changes included

  • Generalized/expanded _printstyled() function
  • Better diagnostic range for try-without-catch

`highlight()` now always prints whole lines of source code, and can
highlight arbitrary ranges using box drawing characters, not just with
ANSI colors.

Use this to fix diagnostic printing so that it's comprehensible in
a non color terminal and so that pasting errors into non-color
environments works.

The box drawing characters from WGL4 seem like a good balance of:

* Relatively compatible because they're very old, dating from DOS era:
  https://en.wikipedia.org/wiki/Box-drawing_character#DOS - note we also
  use these for formatting log messages from Logging.ConsoleLogger.

* Easy to distinguish from the user's source code

I've also found it's helpful to prepend any lines of annotation with a
Julia # comment where possible - this ensures that copy+paste into
websites with syntax highlighting will highlight the annotations
separately from the code.

A simple example:

    julia> (x - (c <--- d))
    ERROR: ParseError:
    (x - (c <--- d))
    #       └──┘ ── invalid operator @ REPL[48]:1:9

Also some semi-related changes included

* Generalized/expanded _printstyled() function
* Better diagnostic range for try-without-catch
@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #215 (549055e) into main (fec6f3f) will increase coverage by 1.37%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #215      +/-   ##
==========================================
+ Coverage   94.95%   96.32%   +1.37%     
==========================================
  Files          15       15              
  Lines        3802     3868      +66     
==========================================
+ Hits         3610     3726     +116     
+ Misses        192      142      -50     
Impacted Files Coverage Δ
src/diagnostics.jl 100.00% <100.00%> (+80.39%) ⬆️
src/parse_stream.jl 96.21% <100.00%> (+0.45%) ⬆️
src/parser.jl 97.96% <100.00%> (+<0.01%) ⬆️
src/source_files.jl 97.29% <100.00%> (+11.58%) ⬆️
src/syntax_tree.jl 94.94% <100.00%> (-1.50%) ⬇️
src/utils.jl 87.27% <100.00%> (+9.22%) ⬆️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@c42f
Copy link
Member Author

c42f commented Mar 11, 2023

Ah you got to be kidding. splitpath() didn't exist in julia-1.0? Ok, replace() it is I guess...

@c42f
Copy link
Member Author

c42f commented Mar 11, 2023

codecov keeping me honest here 😅

@c42f c42f merged commit 442f3e4 into main Mar 11, 2023
@c42f c42f deleted the c42f/source-range-printing branch March 11, 2023 10:42
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.

1 participant