hardhat-vscode icon indicating copy to clipboard operation
hardhat-vscode copied to clipboard

feat: add support for region comments

Open scorpion9979 opened this issue 2 years ago • 1 comments
trafficstars

  • [ ] 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 //#region and //#endregion patterns.

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.

image


image

How to test this feature

  1. Check out this PR and follow the instructions in CONTRIBUTING.md#running-locally to run it locally.
  2. Open a .sol file in VS Code.
  3. Insert //#region and //#endregion comments around the code you wish to collapse.
  4. Verify that you can collapse and expand the region as expected.

scorpion9979 avatar Nov 03 '23 22:11 scorpion9979

@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.

pegahcarter avatar Apr 01 '24 16:04 pegahcarter

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?

Xanewok avatar Apr 29 '24 12:04 Xanewok