juanfranblanco / vscode-solidity

Visual Studio Code language support extension for Solidity smart contracts in Ethereum https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity
MIT License
904 stars 193 forks source link

Solidity Vscode Intellisense only working if i specify a contract #316

Open markokhman opened 2 years ago

markokhman commented 2 years ago

Hello folks! I'm struggling severely to configure my Vscode working properly.

I have imported contract of openzeppelin - ERC721.sol Now I expected its function setApprovalForAll() be available in intellisense when i start typing it in my contract, but here is what i see if I start typing it and then click Ctrl+Space:

Screen Shot 2022-01-21 at 10 26 00

In the same time if i explicitly type the contract name - then i can see intellisense autocompletion:

Screen Shot 2022-01-21 at 10 25 47

Please give me a hint - what am I doing wrong?

markokhman commented 2 years ago

I realised that it is working this way because ERC721.sol is in one of node_modules. Once i put my contract file into the openzeppelin module folder, next to the ERC721.sol - autocompletion works fine. But isn't that possible to make it so that I could use autocompletion for modules that are imported?

juanfranblanco commented 2 years ago

Hi @markokhman in settings you can set the value of the dependencies forlder, that is the defaulted to node_modules as many contracts are distributed using npm, you can change the folder if you want (relative to the root of the project)

We have support also for the "remappings" file, check the readme for instructions on that (and the above) to get bigger detail.

https://github.com/juanfranblanco/vscode-solidity#project-structure-and-remappings

markokhman commented 2 years ago

@juanfranblanco thank you very much for getting into this issue for me! Really appreciate that.

I was able to successfully import a contract (ex. ERC271) that is provided by @openzeppelin and stored in node_modules, so I guess this means that my VSCode is configured properly. Also i get autocompletion if i reference directly from contract:

Screen Shot 2022-01-21 at 14 01 48

I face an issue if I try to access the methods of this imported contract directly:

Screen Shot 2022-01-21 at 14 02 00

I was able to find out that if I put my custom contract next to the ERC721.sol - then the autocomplete magically works!

Screen Shot 2022-01-21 at 16 15 54

But isn't it supposed to work the same way once I import the ERC721 from the @openzeppelin?

juanfranblanco commented 2 years ago

Seems ok here: image

if the parser fails, try this., i think i have parsing issues on the return value with anonymous fields.

juanfranblanco commented 2 years ago

The issue was with vscode, as there was not possible to set the label (null) the autocomplete was breaking, this was not related to the parser.

gRoussac commented 2 years ago

Hi @juanfranblanco thanks for your awesome plugin.

If I may there is still a small issue in 0.0.137, not sure if this is helping but it's quite confusing. When the contract can not be parsed I guess with a syntax error (not all though...), completion goes away. Not sure if this is normal behavior or expected.

Desktop-screenshot - 2022-03-07T011652 619 Desktop-screenshot - 2022-03-07T011605 009

Cheers !