hardhat-vscode
hardhat-vscode copied to clipboard
feat: add support for region comments
- [ ] Because this PR includes a bug fix, relevant tests have been included.
- [x] Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
- [ ] I didn't do anything of this.
Overview
This PR introduces support for region comments within Solidity .sol files previously mentioned in https://github.com/NomicFoundation/hardhat-vscode/issues/452, addressing the issue where developers were seeking the ability to organize code into collapsible sections for improved readability and navigation.
Changes
- Modified the Solidity language configuration file to recognize the
//#regionand//#endregionpatterns.
Implementation Details
Region comments are implemented by modifying the Solidity language grammar to include start and end region markers. The pattern follows the typical convention of //#region and //#endregion which is familiar to developers from other programming languages.
//#region ExampleRegion
// Your Solidity code here
//#endregion ExampleRegion
The language configuration now includes logic to parse these markers and translate them into foldable regions within VS Code.
Screenshots
Included are screenshots demonstrating the collapsible regions in action within a Solidity file.
How to test this feature
- Check out this PR and follow the instructions in CONTRIBUTING.md#running-locally to run it locally.
- Open a
.solfile in VS Code. - Insert
//#regionand//#endregioncomments around the code you wish to collapse. - Verify that you can collapse and expand the region as expected.
@Xanewok can we get some support on this feat? It would be great to have for navigating large contracts and can prevent a screen-split if you're working on, for example, public functions and their errors or events.
I'd be open to it; I thought this is a Microsoft/C#-ism but it seems to be ubiquitously supported in languages like Go (https://github.com/microsoft/vscode/pull/69899), Python (https://github.com/microsoft/vscode-python/issues/33) and C++, C#, TS etc.
Ideally:
- it should probably be supported out of box in the VSCode at this point with a way to opt-out for specific languages
- or one should use a dedicated extension for this https://marketplace.visualstudio.com/items?itemName=maptz.regionfolder
However, since this is such a small addition, I think it's more beneficial to have it rather than the other way around, especially if users will be migrating from the existing Juan Blanco's extension that supports it.
@kanej what do you think?