8000 Add option --html-details-with-highlighting. by Spacetown · Pull Request #402 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option --html-details-with-highlighting. #402

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

Merged
merged 7 commits into from
Sep 12, 2020

Conversation

Spacetown
Copy link
Member

Add optional syntax highlighting as added in #43.

@codecov
Copy link
codecov bot commented Jul 29, 2020

Codecov Report

Merging #402 into master will increase coverage by 0.21%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #402      +/-   ##
==========================================
+ Coverage   93.72%   93.93%   +0.21%     
==========================================
  Files          20       20              
  Lines        2311     2342      +31     
  Branches      404      406       +2     
==========================================
+ Hits         2166     2200      +34     
+ Misses         77       75       -2     
+ Partials       68       67       -1     
Impacted Files Coverage Δ
gcovr/configuration.py 97.67% <ø> (ø)
gcovr/html_generator.py 98.36% <100.00%> (+0.19%) ⬆️
gcovr/tests/test_args.py 100.00% <100.00%> (ø)
gcovr/__main__.py 91.20% <0.00%> (+1.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73e8776...8c2fd0d. Read the comment docs.

@Spacetown Spacetown force-pushed the syntax_highlighting branch 2 times, most recently from 0ec6c79 to 4754735 Compare July 29, 2020 20:42
Copy link
Member
@latk latk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlighting is a large quality of life improvement! I think the current implementation is a bit to complicated though:

  • the new option should just modify the HTML generator, not add another way to add outputs
  • highlighting should probably handle each file in one go, instead of highlighting line by line

I also have more general questions:

  • Should highlighting be enabled by default? Pro: this is a quality of life improvement. Con: reports might be more difficult to read?
  • I think a Pygments dependency has to be added to the setup.py file. CI accidentally works, probably because Pygments is also installed for Sphinx. Or should Pygments be an optional dependency that we test for at runtime?
  • Is there any interaction between source code highlighting and the coloured backgrounds that indicate coverage (c.f. --html-theme)? Will highlighted code still be legible?

@Spacetown
Copy link
Member Author
Spacetown commented Jul 30, 2020

I've also a con:

  • For large projects the generation time can increase significant.
    But if there is a negotiation, we can set it as default.
    I'll also add the dependency and a runtime fallback if the module isn't installed.

@latk
Copy link
Member
latk commented Jul 30, 2020
8000

The point that highlighting slows the report down is very good 🤔

The question is then what case should be optimized for: small to medium projects and users that are using gcovr for the first time, or larger projects. In one case there's non-obvious knowledge to make gcovr more useful, in the other non-obvious knowledge to make gcovr fast.

I think that, within reason, the median project and the newer user should be prioritized over performance:

  • this likely benefits more people
  • gcovr's design decisions already try to favor usability over speed (like the bruce-force heuristics to figure out where gcov should be invoked)
  • there are better opportunities to gain performance than disabling syntax highlighting
    • like fixing the gcov invocation heuristics, or using the gcov-json format where possible
  • people who want to speed up gcovr are more likely to read the full docs

Perhaps a compromise to ensure discoverability is to time how long HTML report generation takes and write a Clippy-style suggestion to stderr when it takes too long? “Tip: you can speed up your HTML reports by disabling syntax highlighting with --no-html-details-highlighting”. In any case, that would be out of scope for this PR.

@Spacetown Spacetown force-pushed the syntax_highlighting branch 3 times, most recently from 30c95bc to 3a1dc63 Compare July 30, 2020 20:18
@Spacetown
Copy link
Member Author

The hilighting looks good in default and in blue theme.

@Spacetown Spacetown force-pushed the syntax_highlighting branch from f890b32 to 13e398d Compare August 14, 2020 18:50
@chrta
Copy link
Contributor
chrta commented Aug 17, 2020

Is there at least one test for both options, with and without syntax highlighting? Just to ensure that both settings do not break in the future.

@Spacetown
Copy link
Member Author

Good point @chrta, I'll update one test to use --html-details-no-sysntaxhilighting.

@Spacetown
Copy link
Member Author

Good point @chrta, I'll update one test to use --html-details-no-sysntaxhilighting.

While adding the tests I found out, that leading and trailing newlines where missing in the output of pygments. The default is to strip them. See option stripnlin https://pygments-doc.readthedocs.io/en/latest/lexer.html. I'm updating the test data.

@Spacetown Spacetown requested a review from chrta September 4, 2020 20:29
Copy link
Contributor
@chrta chrta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor nit. Otherwise after trying it locally, it seems to work fine.

Copy link
Contributor
@chrta chrta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i can tell, looks good.

@Spacetown Spacetown merged commit 8d69bb8 into gcovr:master Sep 12, 2020
@Spacetown Spacetown deleted the syntax_highlighting branch September 12, 2020 09:20
@Spacetown Spacetown mentioned this pull request Sep 12, 2020
Comment on lines +644 to +650
GcovrConfigOption(
"html_details_syntax_highlighting", ["--html-details-no-syntax-highlighting"],
group="output_options",
help="Disable syntax highlighting in HTML details page. "
"Default is active syntax highlighting.",
action="store_false",
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, it's worth considering if we want to name negative options as --NAMESPACE-no-FEATURE or --no-NAMESPACE-FEATURE. I'm in the second camp because this allows positive/negative pairs to be autogenerated.

For example:

GcovrConfigOption(
  "html_details_syntax_highlighting", ["--html-details-syntax-highlighting"],
  group="output_options",
  help="Use syntax highlighting in HTML details page. "
       "Enabled by default.",
  action="store_const",
  default=True,
  const=True,
  const_negate=False,  # autogenerates --no-NAME with action const=False
)

Until now, the only use of this feature is the --html-self-contained/--no-html-self-contained option.

There are also concerns regarding configuration file support. A config key is derived for all options, unless explicitly disabled with config=False. It is not directly apparent what html-details-no-syntax-highlighting = yes would mean. Actually, I think there's a bug in the config file handling because config-key = no would reset to the default, which would make the above option impossible to disable. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a Gold point. I haven't seen the existing negative Option. I also Luke the autogenerared - - no-... I'll Chance this in a separate PR.

Spacetown added a commit to Spacetown/gcovr that referenced this pull request Sep 13, 2020
Spacetown added a commit that referenced this pull request Sep 14, 2020
Change option as mentioned in #402
Co-authored-by: Lukas Atkinson <opensource@LukasAtkinson.de>
@Spacetown Spacetown added this to the 4.3 milestone Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0