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

Jump to Solidity function from JS/TS land

Open devanoneth opened this issue 3 years ago • 2 comments
trafficstars

I think all the pieces are in place to do this now. It would create a really integrated experience for developers.

Imagine CTRL+clicking on a Typechained contract call in your tests leads you to the corresponding Solidity function in VSCode rather than the Contract.d.ts file.

Related to #101, although probably a step further. Not sure if Typechain would need to start annotating their .d.ts files with some source maps or if this extension already has enough information to figure it out alone (even without Typechain).

Will start looking to build this out in a PR myself, but in the meantime maybe someone with more experience on this codebase can point me in the right direction? Thanks!

devanoneth avatar Mar 15 '22 14:03 devanoneth

Thanks for this suggestion, @devanonon.

I'll let you and @kanej take it from here.

alcuadrado avatar Mar 15 '22 16:03 alcuadrado

An approach to this is to have the hardhat extension register for javascript and typescript files. The extension implements the go to definition feature for js/ts but pipes the request to the hardhat lsp by a custom command.

The hardhat lsp parses the js/ts and ignores anything that is not an ethers contract invocation. The lsp can use its internal knowledge of the solidity contracts to find where the navigation should lead and return the response to the extension, which can then answer the js/ts request.

We believe the typescript server is smart enough to defer to other extensions if they have registered for js/ts features.

kanej avatar Aug 02 '22 15:08 kanej