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

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

Open AbhinavMir opened this issue 1 year ago • 4 comments
trafficstars

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

AbhinavMir avatar Feb 14 '24 07:02 AbhinavMir

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

AbhinavMir avatar Feb 14 '24 07:02 AbhinavMir

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:

https://github.com/NomicFoundation/hardhat-vscode/blob/12bb234327561fb1c6877a2ced5ea2f6fc324a45/server/src/compilerDiagnostics/diagnostics/ConstrainMutability.ts#L25

kanej avatar Feb 14 '24 11:02 kanej

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?

AbhinavMir avatar Feb 15 '24 00:02 AbhinavMir

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

kanej avatar Feb 15 '24 09:02 kanej