hardhat-vscode
hardhat-vscode copied to clipboard
Signature help not working properly
This might have to do with the change of making analysis async.
Simple example:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
contract Foo {
function hi(uint a) public pure {
}
}
contract Small {
Foo foo;
constructor(){
foo.hi(<CURSOR>
}
}
Hint: when there's a semicolon at the end of the line, the signature help works
Just noticed this might be a duplicate of #174
I did some investigation on this and here's what I could find:
- Analysis is not being triggered on signatureHelp request. So at the moment of execution, the analyzer tree might not be refreshed and might not have the available data to handle the request.
- If the parsing by
solidity-parserfails on the current contract text, then the request is aborted. - When a function invocation is only partially written (i.e.
greeter.greetorgreeter.greet(), the parsing fails. But havinggreeter.greet(),greeter.greet;orgreeter.greet(;will produce a valid ast with the required MemberAccess node. If parenthesis auto-close is enabled, when the opening parenthesis is typed, the resulting text should be parseable and after analysis the request should be successful. Althought right now there's something wrong with the analyzer that it's not correctly loading the MemberAccess node in the graph even thought it's present on the ast.
I think these are the required changes to have this feature working properly:
- Refactor
onSignatureHelpto be async. - Invoke analysis in the request.
- Optionally insert some workaround that will help the parsing to succeed (i.e. appending a semicolon at the end of the line)
- Dive deeper into the analyzer and ensure the graph is built correctly (it links the MemberAccess node) when the ast is correct.
Invoking analysis and making the onSignatureHelp async both sound like good moves.
I suspect we will want to hold on this until we can pull in slang parser to give us better parse results in the case of syntax errors.