Skip to content

Goto definition and autocomplete is broken for some imports when HardHat config is present #712

@emo-eth

Description

@emo-eth

I run into this often in dual hardhat/foundry repos, and usually just delete the hardhat.config.ts file while working, since many of the LSP features I rely on break because the hardhat plugin defaults to loading the hardhat config with no way to configure which it prefers.

This is true even when the project uses HardHat 2 - possibly related to #709

Repro steps:

  • npx create-lz-oapp@latest --example oapp
  • Open MyOapp.sol
    • Observe @layerzero imports do not have goto definition nor autocomplete
    • For some reason, @openzeppelin imports do work
    • Image
    • Image
    • Image
  • Delete hardhat.config.ts or rename to hardhat.config.ts.bak
  • Restart extensions so the HardHat plugin loads the foundry.toml config instead of the HardHat config: > Developer: Restart Extension Host
    • Observe all imports support goto definition
    • Observe autocomplete for imports work
    • Image
    • Image

I only have the HardHat extension installed for Solidity files:

 cursor --list-extensions
adpyke.codesnap
anysphere.cursorpyright
anysphere.remote-containers
asvetliakov.vscode-neovim
bierner.markdown-mermaid
biomejs.biome
bradlc.vscode-tailwindcss
charliermarsh.ruff
connorshea.vscode-ruby-test-adapter
eamodio.gitlens
esbenp.prettier-vscode
github.vscode-github-actions
github.vscode-pull-request-github
golang.go
hbenl.vscode-test-explorer
jdinhlife.gruvbox
jeff-hykin.better-nix-syntax
jock.svg
ms-azuretools.vscode-containers
ms-azuretools.vscode-docker
ms-python.debugpy
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-renderers
ms-toolsai.vscode-jupyter-cell-tags
ms-toolsai.vscode-jupyter-slideshow
ms-vscode.hexeditor
ms-vscode.live-server
ms-vscode.test-adapter-converter
ms-vscode.vscode-github-issue-notebooks
nomicfoundation.hardhat-solidity
nrwl.angular-console
pest.pest-ide-tools
redhat.java
redhat.vscode-yaml
rust-lang.rust-analyzer
ryanluker.vscode-coverage-gutters
ryuta46.multi-command
sainnhe.gruvbox-material
shopify.ruby-lsp
sorbet.sorbet-vscode-extension
tamasfe.even-better-toml
tintinweb.graphviz-interactive-preview
tomoki1207.pdf
vadimcn.vscode-lldb
vscjava.vscode-gradle
vscjava.vscode-java-debug
vscjava.vscode-java-dependency
vscjava.vscode-java-pack
vscjava.vscode-java-test
vscjava.vscode-maven
vscodevim.vim
yoavbls.pretty-ts-errors
yzhang.markdown-all-in-one

I understand why the HardHat Solidity extension would default to HardHat over Foundry when both are present - but I'd love the option to toggle between preferring one or the other. Even if this were fixed, I always default to Foundry-first config, and yours is the best LSP available by a wide margin 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions