NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code

Home Page:https://hardhat.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VS Code Solidity extension: Highlight Only Uninitialized Immutable Variables and Constructor

AbhinavMir opened this issue · comments

In the Solidity extension, currently, when immutable state variables are not initialized, the entire contract is highlighted in red. This is not optimal for understanding the issue at hand. It would be more helpful if only the uninitialized immutable variables and the related constructor were highlighted.

Steps to Reproduce:

  1. Declare an immutable state variable in a Solidity contract.
  2. Create a constructor without initializing the immutable variable.

Expected: Highlighting of immutable variable and constructor to be have red squiggly lines.

Actual: Everything is red, making it hard to see which immutable variables are the problem.

image

(Can take this up is this is an actual issue!)

This is a great suggestion for an improvement.

What is happening is that that solc is giving an error (solc 2658). The range that solc is giving in the source code is the entire contract:

image

With the extension we can manipulate that source range so that it is limited to the constructor, more specifically just to the constructor keyword.

The way this would be implemented is by providing a new CompilerDiagnistic for 2658. This diagnostic would provide no code actions but transform the solc error by constraining the source range by implementing fromHardhatCompilerError, and constraining to the constructor keyword. You can see a similar move here:

return attemptConstrainToFunctionName(document, error);

Thanks! I can implement this, but I'm taking a break till end of week. Could you assign it to me so I can keep a tab on it and close it this weekend?

Hey @AbhinavMir I have assigned it to you. Thanks and good luck.