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

Trigger validation properly after file movement/rename #387

Closed
honestbonsai opened this issue Feb 4, 2023 · 8 comments · Fixed by #421
Closed

Trigger validation properly after file movement/rename #387

honestbonsai opened this issue Feb 4, 2023 · 8 comments · Fixed by #421
Labels
status:ready This issue is ready to be worked on type:bug Something isn't working

Comments

@honestbonsai
Copy link

honestbonsai commented Feb 4, 2023

I have the following folder structure:

hardhat.config.ts
node_modules
test
    folder1
        folder1.1
            Contract1.sol
        folder1.2
            Contract2.sol
    folder2
        Contract3.sol
        Contract4.sol

I'm doing import "hardhat/console.sol"; in all of the solidity files, however they only work in folder2, and do not work in folder1.1, folder1.2.

I get the following error for all solidity files in folder1.1 and folder1.2:

Source "hardhat/console.sol" not found: File not found. Searched the following locations: "".solidity(6275)

If I change the import for folder1.1 to ../../../node_modules/hardhat/console.sol, the error from VSCode goes away.

I also do import 'openzeppelin-contracts-06/math/SafeMath.sol'; in the solidity files in folder1 and get the error:

Source "openzeppelin-contracts-06/math/SafeMath.sol" not found: File outside of allowed directories.solidity(6275)

In my package.json, I have the alias for openzeppelin-contracts-06

{
    "devDependencies": {
        "openzeppelin-contracts-06": "npm:@openzeppelin/contracts@3.4.2",
    }
}

My tests still run fine and everything compiles, I just get the red underlines and errors from VSCode.

@honestbonsai
Copy link
Author

Not sure why but when I open and closed VSCode again, it seems ok now?

But then when I move files around while I'm in VSCode, the error reappears?

@antico5
Copy link
Collaborator

antico5 commented Feb 6, 2023

@honestbonsai Hi! I noticed this issue happens only while moving files around (rename, move to different folder). In my case, just making a modification to the file removes the error lines (since it re-triggers validation). Can you validate that you get the same behavior? in that case, we can relabel the issue to something like "Trigger validation properly after file movement/rename".

The npm alias for packages e.g. @openzeppelin/contracts is working fine and is supported by the extension.

@honestbonsai
Copy link
Author

@antico5 I can confirm what you just said. I did the following:

  1. Deep nested file with import "hardhat/console.sol" showing no errors on a freshly opened VSCode
  2. Rename the file
  3. File shows errors with the import
  4. Add a line to the file
  5. Error disappears

I agree with your idea for the relabeling to "Trigger validation properly after file movement/rename". Thanks for the help!

@honestbonsai honestbonsai changed the title Direct imports not working with deeply nested folders Trigger validation properly after file movement/rename Feb 6, 2023
@antico5
Copy link
Collaborator

antico5 commented Feb 6, 2023

@honestbonsai Thank you for reporting! we will address it as soon as possible.

@kanej kanej added type:bug Something isn't working status:ready This issue is ready to be worked on and removed status:triaging labels Feb 7, 2023
@kanej kanej moved this to Todo in hardhat-vscode Feb 7, 2023
@PaulRBerg
Copy link

PaulRBerg commented Mar 3, 2023

Just bumped into this bug as well. It's quite a blocker when writing tests with Forge!

Source "forge-std/StdError.sol" not found: File not found. Searched the following locations: "".

Reloading the VSCode windows makes the bug go away, however.

@kanej
Copy link
Member

kanej commented Mar 3, 2023

@PaulRBerg are you encountering that error when you move/rename files or is it happening in another context?

@PaulRBerg
Copy link

@kanej hard to pin it down, but I know for certain that it also happened after updating my submodules.

@kanej
Copy link
Member

kanej commented Mar 7, 2023

@PaulRBerg we suspect we are not updating the foundry project metadata against new (#416) and renamed files (#417) within the foundry project (at least that is our current working theory). We will be looking into both those issues this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on type:bug Something isn't working
Projects
Status: Done
4 participants