NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
177 stars 44 forks source link

Extension considers sol files not part of hardhat project if project path contains symlink #270

Open SAPikachu opened 2 years ago

SAPikachu commented 2 years ago

I use symlink to point my development workspace to a synced folder. When I open a hardhat project inside the symlink, I got following error and intellisense doesn't work correctly:

image

If I open the same project directly inside the real path without symlink, intellisense works correctly.

Environment:

VSCode (note that I use SSH remote extension to work with project inside a VM):

Version: 1.72.0 (user setup)
Commit: 64bbfbf67ada9953918d72e1df2f4d8e537d340e
Date: 2022-10-04T23:20:39.912Z (6 days ago)
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

VM:

fubhy commented 1 year ago

This also happens under certain circumstances (not yet entirely sure how to reproduce this reliably) when using pnpm with symlinked node modules that host smart contracts (e.g. openzeppelin, etc.)

antico5 commented 1 year ago

@fubhy About the foundry + pnpm issue (copying my answer from slack):

I've been investigating the symlink issue using the repo you shared (https://github.com/KedziaPawel/symlink-hardhat-bug). I've arrived to 2 conclusions:

Forge works on the provided settings because it uses the solc CLI instead of the json interface (which the extension uses).

I tried the following json inputs for solidity < 0.8.8 to try and make it work without success: Given import path is import '@openzeppelin/...' a) Set remappings to @openzeppelin => node_modules/@openzeppelin/ b) Set remappings to @openzeppelin => /absolute/path/to/node_modules/@openzeppelin/

Both give the "file outside allowed directories" error.

@SAPikachu I was able to reproduce the reported issue. Our extension does not behave as expected on hardhat project directories that are symlinked, because of the way we load the HRE for providing validation and other services (require.resolve, which unavoidably resolves symlinks). We will have to think about possible workarounds for this.

fvictorio commented 1 year ago

This happens in fresh MUD projects too. Repro:

pnpm create mud@canary app
# selected vanilla, but i'm pretty sure it's not relevant
code app

And go to packages/contracts/src/systems/IncrementSystem.sol. The @latticexyz/world/src/System.sol import will show as not found.

kanej commented 1 year ago

@alcuadrado suggested we investigate the library: https://www.npmjs.com/package/resolve, and whether it can help us with out node require resolution for pnpm.

antico5 commented 1 year ago

@kanej I wasn't able to crack it so far. These are my findings on the issue:

I'm sure there must be a simpler way of supporting symlinked directories. Perhaps we should look into how other language servers handle this.

kanej commented 1 year ago

Thanks @antico5, I'll take it from here :wave:

tpae commented 1 year ago

Any updates on this?

peersky commented 5 months ago

Any update on this?

kanej commented 5 months ago

No updates, we haven't progressed the investigation.