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

Signature help not working properly

Open antico5 opened this issue 2 years ago • 3 comments

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

antico5 avatar Dec 27 '22 15:12 antico5

Just noticed this might be a duplicate of #174

antico5 avatar Dec 27 '22 16:12 antico5

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-parser fails on the current contract text, then the request is aborted.
  • When a function invocation is only partially written (i.e. greeter.greet or greeter.greet(), the parsing fails. But having greeter.greet() , greeter.greet; or greeter.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 onSignatureHelp to 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.

antico5 avatar Dec 30 '22 16:12 antico5

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.

kanej avatar Jan 02 '23 09:01 kanej