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

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

Open antoniordf opened this issue 2 years ago • 16 comments

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:

  • uninstalling and reinstalling the extension
  • uninstalling and reinstalling solhint
  • restarting vscode
  • completely removing vscode from my system and reinstalling it from scratch

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.

antoniordf avatar Sep 01 '23 22:09 antoniordf

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

juanfranblanco avatar Sep 06 '23 08:09 juanfranblanco

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.

antoniordf avatar Sep 06 '23 10:09 antoniordf

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

juanfranblanco avatar Sep 06 '23 10:09 juanfranblanco

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

antoniordf avatar Sep 06 '23 11:09 antoniordf

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 :

juanfranblanco avatar Sep 06 '23 12:09 juanfranblanco

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.

antoniordf avatar Sep 06 '23 14:09 antoniordf

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

juanfranblanco avatar Sep 06 '23 14:09 juanfranblanco

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.

antoniordf avatar Sep 06 '23 14:09 antoniordf

@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.

juanfranblanco avatar Sep 07 '23 05:09 juanfranblanco

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.

antoniordf avatar Sep 07 '23 10:09 antoniordf

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.

juanfranblanco avatar Sep 07 '23 10:09 juanfranblanco

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?

antoniordf avatar Sep 08 '23 09:09 antoniordf

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.

xklob avatar Nov 21 '23 11:11 xklob

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

juanfranblanco avatar Nov 21 '23 12:11 juanfranblanco