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

[wip] feat(fmt): intermediate chunk struct #1831

Merged
merged 7 commits into from
Jun 3, 2022

Conversation

jpopesculian
Copy link
Contributor

So I went a little crazy trying to get comments to work in the scope of function declarations and otherwise... The main crux of this PR (still WIP) is to add a Chunk struct that holds the context of comments. You can then format this Chunk or rearrange it or manage its comments in special cases.

This is especially useful in lists for example. We can essentially extract the chunk information first, sort if necessary, use that chunk information to check if it fits, and then rewrite the chunks with commas correctly placed before the postfix comments

The other big change here, this chunk on writing handles its own whitespace. This is just kind of a side effect that it has to handle its own whitespace because its potentially surrounded by comments.

There's a bunch of minor stuff in here about handling of temp buffers as well as some helpers for dealing with surrounding things with parentheses and such and handling comments and spacing there as well. Its still very much a work in progress and a complete mess, but I wanted to get it posted here for feedback and collaboration

@jpopesculian jpopesculian marked this pull request as ready for review June 3, 2022 21:23
@jpopesculian jpopesculian merged commit 4281511 into rkrasiuk/fmt-groups Jun 3, 2022
@jpopesculian jpopesculian deleted the jpopesculian/fmt-chunk-struct branch June 3, 2022 21:45
jpopesculian added a commit that referenced this pull request Jun 3, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit to jpopesculian/foundry that referenced this pull request Jun 3, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (foundry-rs#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit to jpopesculian/foundry that referenced this pull request Jun 6, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (foundry-rs#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit that referenced this pull request Jun 8, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit that referenced this pull request Jun 8, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit that referenced this pull request Jun 9, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
jpopesculian added a commit that referenced this pull request Jun 10, 2022
* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>
gakonst added a commit that referenced this pull request Jun 11, 2022
* squashed WIP initial comments implementation

* Use FormatBuffer for both main buf and temp bufs

The FormatBuffer now implements fmt::Write and handles the indentation
logic, tracking characters and line length. Formatter continues to
control the rest of the logic for how to build strings

* add idempotency test

* try to correctly prefix/postfix given indentation grouping

* [wip] fix(forge): `fmt` write chunk (#1717)

* keep tack of emitter of logs (#1669)

* [not compiling] keep tack of emitter of logs

by switching from RawLog to Log

* ugly fix

* cargo +nightly fmt

* Add comment

Co-authored-by: Bjerg <[email protected]>

* fix variable name

Co-authored-by: Bjerg <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>

* provide default impls for remaining visitor methods (#1706)

* chore(clippy): make clippy happy (#1707)

* chore: bump ethers

* feat(bind): option to skip Cargo.toml from consistency checks (#1702)

* feat(bind): option to skip Cargo.toml from consistency checks

* chore: cargo fmt

* Update cli/src/cmd/forge/bind.rs

Co-authored-by: Matthias Seitz <[email protected]>

* chore: clippy lints

Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Georgios Konstantopoulos <[email protected]>

* fix(verify): encode constructor arguments correctly (#1711)

* fix(verify): encode constructor arguments correctly

* chore: rotate api keys

* Update cli/tests/it/verify.rs

Co-authored-by: Georgios Konstantopoulos <[email protected]>

* feat: use rotating api keys in fork unit tests (#1693)

* feat: use rotating api keys in fork unit tests

* fix: use correct path

Co-authored-by: Georgios Konstantopoulos <[email protected]>

* refactor: spawn backendhandler on background thread (#1704)

* fix(watch): only watch dirs that exists (#1710)

* Switch selector database to sig.eth.samczsun.com (#1674)

* feat(utils): use samczsun selector directory

This commit switches the utils crate to use samczsun's new function
selector over 4byte for an improved interface and better stability

* feat(cast): update cli to use new 4byte interface

The util bindings were changed to use samczsun's selector library in the
previous commit; this commit updates the cast cli to properly use the
slightly changed interface.

Also ran cargo fmt which updated some unrelated formatting

* fix: review comments

- undo unrelated cargo fmt changes
- rename fourbyte_* -> decode_* in utils

* fix: remove fourbyte test helper

No longer necessary with sig.eth.samczsun.com

* Add `forge upload-selectors` command (#1676)

* feat: add upload selectors command to forge

This commit adds a new command to forge to upload a contract's abi to
sig.eth.samczsun.com selector database

* fix: review comments

- added default for CoreBuildArgs
- cleaned up code ordering
- moved url to constant

* fix: derive CoreBuildArgs::Default

* test: rotate rinkeby keys

* fix(forge/install): add git status check before commit (#1696)

* fix(forge/install): add git status check before commit

* move logic to git_status_clean function

Co-authored-by: test <[email protected]>

* write chunk

* restore original

* write chunks w/ paren

* semicolon cleanup

* write_semicolon

* feat: add `cast upload-signature` (#1716)

* feat: add `cast upload-signature`

This commit adds a new cast command to upload a raw function signature
to the https://sig.eth.samczsun.com 4byte database.

It also moves some of the original signature upload logic from `forge
upload-selectors` to a helper in foundry_utils

API looks like:
```
❯ cast upload-signature 'function approve(address,uint256)' 'transfer(uint256)' 'event Transfer(uint256,address)'
Duplicated: Function approve(address,uint256): 0x095ea7b3
Duplicated: Function transfer(uint256): 0x12514bba
Duplicated: Event Transfer(uint256,address): 0xabe1dcf9fcb8e5fb309db76bcab112a217aa5754d0f038921282bfe7907aa516
```

* fix: move selectors utils to separate module

* fix: add examples to cli help

* test(cast): add integration test for `cast upload-signature`

* feat(cast): allow uploading contract artifacts

This commit enables the `cast upload-signatures` tool to take contract
artifact files and upload the entire json to sig.eth.samczsun.com

* test: update failing tests (#1714)

* test: fix flaky timestamp test (#1727)

* fix: expressive value_name in clap annotations (#1700)

* value_name in forge test

* test debug help

* remove help and revert debug value_name to TEST FUNCTION

* forge test value_name

* forge value_name

* forge args add value_name

* all cast value_name

* Update cli/src/cmd/cast/run.rs

Co-authored-by: Matthias Seitz <[email protected]>

* cast FourByteDecode merge conflict

Co-authored-by: Matthias Seitz <[email protected]>

* ClapChain value_name (#1731)

* utils & cleanup

* fix(forge/install): git status check (#1732)

* fix(cli): can_update_libs_section test (#1733)

* write_chunk! where possible

* func def fmt

* fix attrs

* tests

* linter

* anvil value_name (#1743)

* docs

* indented & indented_if

* unused import

* cleanup

* ci: add additional ci jobs for forks (#1728)

* ci: add additional ci jobs for forks

* test: fix flaky anvil test

* ci: setup git config

* ci: setup git config

* ci: setup git config global

* chore: fix flaky snapshot test

* fix: enable tokio time feature (#1750)

* chore(deps): replace colored with yansi (#1722)

* feat(config): add allow paths setting (#1751)

* ci: set git config global in cross platform ci (#1754)

* ci: set git config global in cross platform ci

* fix: flaky tests

* fix: use proper types

* fix(cast): improve cast wallet new (#1713)

* fix(cast): improve cast wallet new

* chore: cleanup imports

Co-authored-by: jole <[email protected]>
Co-authored-by: Bjerg <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Georgios Konstantopoulos <[email protected]>
Co-authored-by: Meet Mangukiya <[email protected]>
Co-authored-by: marktoda <[email protected]>
Co-authored-by: 0xYYY <[email protected]>
Co-authored-by: test <[email protected]>
Co-authored-by: Shawn Harmsen <[email protected]>

* [wip] feat(fmt): format buffer groups (#1780)

* fmt groups

* reset to init start group functionality & use where needed

* expand test case

* [wip] feat(fmt): intermediate chunk struct (#1831)

* wip: use a struct for managing an intermediate representation

* cleanup visit function definition

* fix import statements

* restrict temp bufs to the current line restriction and simplify visit contract

* consistent ordering of parameters in chunk operations

* fix up using list formatting for multiline support

* convert to second iteration of write_chunk_separated

Co-authored-by: Julian Popescu <[email protected]>

* [wip] feat(fmt): expressions (#1809)

* add an Operator trait for implementing Expression formatting

* basic implementation of write operator expression

* add grouping of expression parts by precedence

* Add tests back and fix unnecessary indent

Chunks were being unnecessarily indented because writing source to a
temp buffer wasn't accounting the indent already existing, thereby
essentially adding extra indent where not needed when being written
again to the underlying buffer

* Add custom error to fmt (#1852)

* feat(fmt): Add single line helpers (#1860)

* Add single line helpers and reimplement surrounds and function definition with helpers

* feat(fmt): `for`, `while` & `do while` statements (#1864)

* for while statements

* rm comments

* for loop header

* do while support

* uncomment tests

* rm comments

* address comments

* feat(fmt): Expression multiline formatting (#1879)

* Basic flat expressions

* Add expression formatting

* fix var definition to handle multiline declaration appropriately

* Add assignment expressions

* fix tests

* simplify result handling

Co-authored-by: Roman Krasiuk <[email protected]>

* add information about chunks and comments

* fix unit tests

* fix(fmt): comment indent (#1888)

* fix comment indent

* Fix postfix categorization for multiline comments

Postfix comments try to see if they sit on an indent greater
than the next code block. However the code was splitting the src into
lines before removing comments to check for the next code point causing
it to break on multiline comments

* Fix write_raw indent len

`write_raw` wasn't appropriately trimming base_indent_len and was off by
one in special cases. In addition `write_raw` was not setting
is_beginning_of_line correctly

Co-authored-by: Julian Popescu <[email protected]>

* fix spacing in source unit parts

* fix spacing in contract parts with comments

* fix statement spacing

* make lined statements dryer

* fix duplicated prefix statement in visit_src block

* fix event multiline edge cases

* convert attributes to chunks after newline to account for line length

* better function ordering and Transact helpers

* add doc comments to visit helpers

* add doc comments to other helper traits and structs

* add location info to break and continue

* trim the end of comments where necessary

* fix expression lists

* fix the case of a missing list param

* dep(fmt): update ethers & solang (#1909)

* upd solang

* remove helpers

* attr override

* fix

* remove

* group ident path

Co-authored-by: Roman Krasiuk <[email protected]>
Co-authored-by: jole <[email protected]>
Co-authored-by: Bjerg <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Georgios Konstantopoulos <[email protected]>
Co-authored-by: Meet Mangukiya <[email protected]>
Co-authored-by: marktoda <[email protected]>
Co-authored-by: 0xYYY <[email protected]>
Co-authored-by: test <[email protected]>
Co-authored-by: Shawn Harmsen <[email protected]>
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