Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antoniordf opened this issue Sep 1, 2023 · 15 comments

Comments

@antoniordf
Copy link

antoniordf commented Sep 1, 2023

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.

@juanfranblanco
Copy link
Owner

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

@antoniordf
Copy link
Author

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
Copy link
Owner

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

@antoniordf
Copy link
Author

antoniordf commented Sep 6, 2023

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
Copy link
Owner

juanfranblanco commented Sep 6, 2023

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
Copy link
Author

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:
#274

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

@juanfranblanco
Copy link
Owner

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

@antoniordf
Copy link
Author

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
Copy link
Owner

juanfranblanco commented Sep 7, 2023

@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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

Hi @juanfranblanco , apologies for delay.

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

Screen.Recording.2023-09-07.at.14.24.19.mov
Screen.Recording.2023-09-07.at.14.26.00.mov
Screen.Recording.2023-09-07.at.14.33.06.mov

Here is the project with issues:

Screen.Recording.2023-09-07.at.14.28.02.mov
Screen.Recording.2023-09-07.at.14.29.56.mov
Screen.Recording.2023-09-08.at.10.35.03.mov

Should I go ahead and delete the settings?

@xklob
Copy link

xklob commented Nov 21, 2023

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
Copy link
Owner

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

@Marvelousy20
Copy link

Screenshot 2024-11-19 at 12 41 45 AM

If anyone is still facing this issue, I was able to resolve mine by going to the solidity extension settings and enable the
"Enabled as you type compilation error check". For some reasons I do not know, it was disabled, I enabled it and everything worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants