Skip to content

[solc] colorized diagnostics output #5511

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 2 commits into from
Feb 7, 2019
Merged

[solc] colorized diagnostics output #5511

merged 2 commits into from
Feb 7, 2019

Conversation

christianparpart
Copy link
Member

@christianparpart christianparpart commented Nov 26, 2018

This PR is a resurrection of #3046 and their related #4338 and #4340.

  • ANSI coloring (termcolor): I didn't copy'n'paste the original one (which requires a additional license), but hacked together our own, that fits our needs
  • SourceReferenceFormatter: greatly refactored to:
  • solc: adds --color for forced colorized output and --no-color for explicitly disabling terminal-autodetection, e.g. if none of these will be given, the diagnostic output will be colored when stdout/stderr is connected to a terminal.

image

please note

Only the last 3 commits matter, the rest is from the rebase.

@christianparpart christianparpart changed the title [solc] colorized diagnostics output [RFC] [solc] colorized diagnostics output Nov 26, 2018
@codecov

This comment has been minimized.

@chriseth

This comment has been minimized.

@chriseth

This comment has been minimized.

@christianparpart

This comment has been minimized.

@chriseth
Copy link
Contributor

Sounds good, but please split it up.

@christianparpart christianparpart force-pushed the cp-error-output branch 6 times, most recently from 5f48c14 to 166a089 Compare November 30, 2018 19:47
@christianparpart christianparpart changed the title [RFC] [solc] colorized diagnostics output [3/3] [solc] colorized diagnostics output Nov 30, 2018
@christianparpart christianparpart force-pushed the cp-error-output branch 3 times, most recently from 6c27cbc to 45e1d79 Compare December 7, 2018 09:51
@christianparpart christianparpart changed the title [3/3] [solc] colorized diagnostics output [solc] colorized diagnostics output Dec 7, 2018
@ekpyron ekpyron self-requested a review February 4, 2019 11:08
for_each(
_ref.text.cbegin(),
_ref.text.cbegin() + _ref.startColumn,
[this](char ch) { m_stream << (ch == '\t' ? '\t' : ' '); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! We might even have a bug about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I too actually held back for a moment on that line, but said if that's a bug, then it was there before already, and I'd prefer to address it in a separate PR (as the base class is affected then, too).

@christianparpart christianparpart force-pushed the cp-error-output branch 2 times, most recently from 268953e to 5a336f4 Compare February 6, 2019 10:57
ekpyron
ekpyron previously approved these changes Feb 6, 2019
Copy link
Member

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

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

Looks good now!

@chriseth
Copy link
Contributor

chriseth commented Feb 6, 2019

I think there is still an inconsistency with regards to spacing between the errors.
This is how errors with secondary source locations are formatted:

Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.5.4;"
 --> /tmp/x.sol:1:1: 
  |
1 | contract c {
  | ^ (Relevant source part starts here and spans across multiple lines).
Error: Identifier already declared.
 --> /tmp/x.sol:3:1: 
  |
3 | int x = 3;}
  | ^^^^^

Note: The previous declaration is here:
 --> /tmp/x.sol:2:32: 
  |
2 | function f(uint) public pure { int x = 2;
  |                                ^^^^^

Error: No matching declaration found after argument-dependent lookup.
 --> /tmp/x.sol:5:27: 
  |
5 | function g() public pure{ f();}
  |                           ^

And this is how it looks without an error with secondary source location:

Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.5.4;"
 --> /tmp/x.sol:1:1: 
  |
1 | contract c {
  | ^ (Relevant source part starts here and spans across multiple lines).
Error: No matching declaration found after argument-dependent lookup.
 --> /tmp/x.sol:4:27: 
  |
4 | function g() public pure{ f();}
  |                           ^

I would have expected the secondary source location to be appended without an empty line between the main location and the secondary location.

Also we might want to add an empty line between two errors (actually this is how your screenshot in the description has it).

@ekpyron
Copy link
Member

ekpyron commented Feb 6, 2019

If we make more changes to this anyways, then I vote for changing the command line argument from --new-reporter to --fancy-reporter as @chriseth just suggested in the office ;-).

@chriseth
Copy link
Contributor

chriseth commented Feb 6, 2019

Oh and another thing I just noticed: At least in the screenshot in the description, the line numbering it says t.sol:3:... but then on the left there is a 2. I think lines should be numbered starting from 1 in both cases.

@chriseth
Copy link
Contributor

chriseth commented Feb 6, 2019

Ah ok, but the thing I pasted at least has it right.

@chriseth
Copy link
Contributor

chriseth commented Feb 7, 2019

Output is now as follows:

> solc --new-reporter /tmp/x.sol 
Warning: This is a pre-release compiler version, please do not use it in production.

Error: No visibility specified. Did you intend to add "public"?
 --> /tmp/x.sol:2:1: 
  |
2 | function f() {}
  | ^^^^^^^^^^^^^^^

Error: No visibility specified. Did you intend to add "public"?
 --> /tmp/x.sol:6:1: 
  |
6 | function h() {}
  | ^^^^^^^^^^^^^^^

Warning: Source file does not specify required compiler version!
 --> /tmp/x.sol:1:1: 
  |
1 | contract c {
  | ^ (Relevant source part starts here and spans across multiple lines).

Error: Function with same name and arguments defined twice.
 --> /tmp/x.sol:2:1: 
  |
2 | function f() {}
  | ^^^^^^^^^^^^^^^
Note: Other declaration is here:
 --> /tmp/x.sol:5:1: 
  |
5 | function f() public pure {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: Overriding function changes state mutability from "pure" to "nonpayable".
 --> /tmp/x.sol:2:1: 
  |
2 | function f() {}
  | ^^^^^^^^^^^^^^^
Note: Overridden function is here:
 --> /tmp/x.sol:5:1: 
  |
5 | function f() public pure {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

ekpyron
ekpyron previously approved these changes Feb 7, 2019
Copy link
Member

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

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

Looks good!

@chriseth
Copy link
Contributor

chriseth commented Feb 7, 2019

I also verified that the old reporter is used with standard-json.

Christian Parpart added 2 commits February 7, 2019 12:55
…ttedScope

a future commit/PR could replace existing code to use AnsiColorized and
remove the old implementation of FormattedScope.
…pretty and colored output.

* Refactors output format in a way it is (or should at least be) more readable.
  (NB.: As source of inspiration, I chose the rustc compiler output.)
* Adds color support to the stream output.
* Also improves multiline source formatting
  (i.e. truncating too long lines, like done with single lines already)
* solc: adds flags --color (force terminal colors) and --no-color (disable autodetection)
* solc: adds --new-reporter to give output in *new* formatting (colored or not)
* Changelog adapted accordingly.
@chriseth
Copy link
Contributor

chriseth commented Feb 7, 2019

Rebased.

@chriseth chriseth merged commit 8992024 into develop Feb 7, 2019
@christianparpart christianparpart deleted the cp-error-output branch February 8, 2019 12:43
@christianparpart
Copy link
Member Author

P.S. @chriseth I didn't rename it to --fancy-reporter, even though I really very much liked the idea, but I'd rather prefer to see this reporter becoming standard at some point in the future (not necessarily the very next breaking release)

@chriseth
Copy link
Contributor

I guess the plan is to make it the default starting from 0.6.0

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