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
871 stars 187 forks source link

VSCode Solidity Extension Not Flagging Errors for Undefined Variables and Syntax Issues #424

Open antoniordf opened 10 months ago

antoniordf commented 10 months ago

Hi, everyone and @juanfranblanco.

I was wondering if there has been some breaking update to the extension. I woke up this morning and the extension isn't working. It does the code highlight and colouring but the linting is not working. I am purposefully writing incorrect code expecting to see warnings and errors in vscode and I get nothing. The code below is an example:

` function deposit(address asset, uint256 _amount) external whenNotPaused nonReentrant {

    DataTypes.ReserveData storage reserve = reservesData[asset];
    DataTypes.ReserveCache memory reserveCache = reserve.cache();

    // Updates the interest rate of the reserve
    reserve.updateInterestRates(reserveCache, asset, amount, 0);

    Why is vscode not marking this line as an error????
    var variable = boo;
    etc...

`

I would expect vscode to highlight "Why is vscode not marking this line as an error????" and "var variable = boo;" and display warnings and errors. I would also expect it to flag the fact that I passed "amount" into the updateInterestRates function rather than "_amount". Again I get nothing.

I have tried:

Nothing is working. I get the following errors in the Output tab for "Solidity Language Server" every time I hover over the code: [Error - 22:44:58] Notification handler 'workspace/didChangeConfiguration' failed with message: Unexpected end of JSON input [Error - 22:45:04] Request textDocument/hover failed. Message: Request textDocument/hover failed with message: Cannot read properties of null (reading 'replace') Code: -32603 [Error - 22:45:04] Request textDocument/hover failed. Message: Request textDocument/hover failed with message: Cannot read properties of null (reading 'replace') Code: -32603 [Error - 22:51:31] Request textDocument/hover failed.

I have also noticed that my settings.json in vscode ahs the format [{...}]. The object is contained inside an array. Is that usually how it is? Perhaos it could explain the "Unexpected end of JSON input" error?

I would appreciate any help please.

juanfranblanco commented 10 months ago

@antoniordf can you provide a full file? I don't have any issues.

antoniordf commented 10 months ago

Hi @juanfranblanco, thanks for getting back to me. After my initial message I noticed that prettier also stopped working and isn't formatting my code.

I'm not sure if this is what you meant when you asked for a file, but please see below for all my solidity user settings:

Screenshot 2023-09-06 at 11 42 25 Screenshot 2023-09-06 at 11 42 48 Screenshot 2023-09-06 at 11 43 26 Screenshot 2023-09-06 at 11 43 43

Here are some of the settings in settings.json:

Screenshot 2023-09-06 at 11 53 45 Screenshot 2023-09-06 at 11 54 07 Screenshot 2023-09-06 at 11 54 25

I hope this helps.

juanfranblanco commented 10 months ago

Can you share a solidity file in your project? Or does this happen to any solidity file.

antoniordf commented 10 months ago

I have done some checks on this previously and some more now, and the behaviour is weirder than I thought. Here are the checks I have done: 1- Within the current project, all solidity files are displaying the same behaviour (not highlighting errors and not formatting). 2- So I started a new fresh project and just copied the code to the new project. The same errors ocurred, which led me to think that this was due to vscode or some bug with the extension. 3- But now I thought to check a previous solidity project of mine where I have observed no issues and worked properly. My expectation was that I would see the same issues there. I did not. It still functions properly, shows errors and formats code properly. I checked all settings and they are the same as what I pasted above. 4- So I created a new repository and instead of copy + pasting code from my problematic project into the new repo, I just typed the code from scratch. Everything worked properly. Errors were highlighted and formatting worked. Then, in this same file, I copied some code (one function definition) from my problematic project into the file and suddenly the same issue observed in my problematic project was "imported" into this new file and the code in the new file that previously showed highlighted errors and formatted, no longer did so.

So this seems like really weird behaviour to me. This means that I can solve my problem by simply creating a new project but instead of copying code over, I need to re-write everything from scratch - which will be a huge pain.

I am sharing a WeTransfer link below with my whole project here so maybe you can spot what is going on (I cant attach the file here). It is a sample lending pool that I am writing to better understand how they are built. Its a simplified version and borrows a lot from protocols like AAVE.

https://we.tl/t-7croWTiDju

juanfranblanco commented 10 months ago

Hi, I have not had any major issues, opened the project (removed the git folder) and everything was ok. Prettier was working.

There were issues in your contract, as there were a few might prevent auto complete, linting , formatting (prettier) to work, etc:

For example:

 /**
     * @dev Maps reserves address (key) to the reserve data (value)
     */
    mapping(address => DataTypes.ReserveData) reservesData;

In here I removed storage

You had other issues like:

 // Update the loans mapping with the loan's details and the debt tokens
        loans[_borrower] = Loan({
            amountBorrowed : _notional,
            debtTokenAmount : _debtTokenAmount
        });

which had += instead of a :

antoniordf commented 10 months ago

Thanks for having a look @juanfranblanco. Yes, the issues with the code are because it was being changed when this issue came up and there were things that I was planning to change.

In any case I guess I will manually re-write the code in another project to get over this.

I found that there was someone else who had the same issue in the past, but I was not able to replicate his solution: https://github.com/juanfranblanco/vscode-solidity/issues/274

In any case, thanks for the help! I really appreciate it.

juanfranblanco commented 10 months ago

@antoniordf you should not need to rewrite the code, I just used the same you gave me.

antoniordf commented 10 months ago

I understand that the issue is not related to the code per-se. It seems to be something related to vscode. When you discussed this issue with codeonblocks in the issue #274 above, the problem seemed to be with "solidity.packageDefaultDependenciesDirectory", however it is not clear to me what he did to solve it.

But for some reason vscode is displaying a behaviour in my system such that if I start a new empty file and start typing solidity code, it seems to work fine.

juanfranblanco commented 10 months ago

@antoniordf So if you use your zip package (the one you sent), does everything work? (Apart from the EthPool and Token pool files, etc). As a new project will use the default settings.

antoniordf commented 9 months ago

Hi @juanfranblanco, I have just tried that. I downloaded the code base and opened it in a new fresh project. Unfortunately I have observed that the issue remains. I think this is an issue with some vscode configuration or with the configuration of the extension.

What is perplexing to me is that if I open a project I wrote months ago, before this issue appeared, it works perfectly. But somehow this current project and every new one I start seems to have this issue. Its quite strange frankly.

PS: Before when I said that simply re-typing the code into a fresh project solved the issue, I was wrong. Some 20 lines of code in, I noticed that the issue persists.

juanfranblanco commented 9 months ago

Can you delete your settings here? https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations Can you record the issue you are experiencing? If using windows Screen2Gif is great, or in ubuntu Peek.

antoniordf commented 9 months ago

Hi @juanfranblanco , apologies for delay.

Here are the videos from my old project which works fine:

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/7daf0894-6504-454f-be6d-b470f3480ba1

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/fcb30683-ac17-4c6e-be69-2aa0854101e9

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/3a70938f-0975-4c24-8853-a5bd00221e8a

Here is the project with issues:

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/b169d4af-e88d-43a6-8efc-c1b11f8b74ad

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/7a1da0e4-dfb7-4aa0-9919-33906e85abd8

https://github.com/juanfranblanco/vscode-solidity/assets/54672689/f67ab0e4-338a-45a9-81cf-fe0a80d8b75b

Should I go ahead and delete the settings?

kryptoklob commented 7 months ago

Also experiencing this issue, and having the same very odd issues where I can type code from scratch on a new project and it works fine, but if I copy code from the existing project that has the issue, it refuses to highlight syntax errors etc.

juanfranblanco commented 7 months ago

Did you check the settings and see if validation is enabled?