NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
163 stars 36 forks source link

feat: add support for region comments #526

Closed scorpion9979 closed 2 months ago

scorpion9979 commented 8 months ago

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

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.
pegahcarter commented 3 months ago

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

Xanewok commented 2 months ago

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:

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?