NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
174 stars 44 forks source link

Autocompletion for npm imports not working #116

Closed FreezyEx closed 2 years ago

FreezyEx commented 2 years ago

Autocompletion as shown here is not working

https://twitter.com/i/status/1501981617304309760

image

kanej commented 2 years ago

Thanks for the feedback. First can I confirm what OS your running on?

I suspect the issue is that there is no closing " in the example above. We determine whether we are in an import statement by parsing the line. But our parser can misreport if there is no closing bracket:

Mar-16-2022 09-15-04

@FreezyEx can you confirm you can completions if you start with import "<cursor here>";?

This is a limitation, but improvements mean rework in solidity-parser, making this quite a big task.

FreezyEx commented 2 years ago

I just tried adding the closing" but same issue: image

I am on Windows10

kanej commented 2 years ago

@FreezyEx can I confirm two things:

FreezyEx commented 2 years ago
  • the completion requires a trigger, it doesn't happen on every character. So if the cursor is after z in @openz and you hit ctrl + space, or if you type @openzeppelin then / do you get any completion?

No, I don't get any completion.

  • are you able to navigate to openzepplin files, for instance the "@openzeppelin/contracts/access/Ownable.sol" in the import bellow if you right click on Ownable.sol and choose go to definition?

Yes it correctly goes to the Ownable.sol

kanej commented 2 years ago

Are there any errors in the output channel immediately after attempting an import completion on the line in question. You can find the output channel by going to the output tab and picking hardhat from the dropdown:

image

FreezyEx commented 2 years ago

I just tried with another project and now seems to work. I don't understand which was the issue. Both are hardhat projects. Now I have the autocompoletion after openzeppelin/

UPDATE: I must restart vscode after intalling a package and get the autocompletion.

kanej commented 2 years ago

@FreezyEx that is a known bug, https://github.com/NomicFoundation/hardhat-vscode/issues/91#issue-1161216370.

Sorry it took so many iterations to get there, I will lead with that next time. Thanks for helping work that through.

FreezyEx commented 2 years ago

Thank you for the help @kanej