juanfranblanco / vscode-solidity

Visual Studio Code language support extension for Solidity smart contracts in Ethereum https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity
MIT License
892 stars 192 forks source link

Very slow Go To Definition #466

Open beaker-meeep opened 23 hours ago

beaker-meeep commented 23 hours ago

Hello everyone!

I am seeing very slow Go To Definition behavior (on the order of 80 seconds). Is this normal? Is there a way I can improve this performance? I searched the existing issues for related wording (slow definition) but couldn't find anything. I have an old machine with an Intel i5-5200U CPU and 12 GB of RAM but even which these old specs I feel like 80 seconds means something is wrong.

VSCode version: 1.94.0 Solidity extension version: v0.0.176

Local user settings are empty. Global user settings.json looks like this:

{
    "editor.formatOnSave": true,
    "[solidity]": {
        "editor.defaultFormatter": "JuanBlanco.solidity"
    },
    "solidity.formatter": "forge",
    "gitlens.currentLine.enabled": false,
    "gitlens.hovers.currentLine.over": "line",
    "editor.minimap.enabled": false,
    "solidity.trace.server": "verbose",
    "solidity.trace.extension": true
}

Steps to repro:

  1. forge init a clean directory
  2. forge install smartcontractkit/chainlink-brownie-contracts@1.1.1 --no-commit
  3. Add the following to your remappings.txt: @chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/
  4. Open the Counter.sol contract and add these three imports:
    import {VRFConsumerBaseV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol";
    import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol";
    import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol";
  5. Try to Go To Definition on either VRFConsumerBaseV2Plus, VRFV2PlusClient or AutomationCompatibleInterface. Some may work, some may not. For me, sometimes VRFConsumerBaseV2Plus works, in which case I attempt to do another Go To Definition from the imports in VRFConsumerBaseV2Plus. In VRFConsumerBaseV2Plus I attempt to Go To Definition for IVRFCoordinatorV2Plus.
  6. The symptom of the problem is the blue loading bar at the top of the file window starts and takes about 80s to resolve. Looking at the traces in the language server I see this exception printed many, many times (could be a red herring).
    TypeError: Cannot read properties of undefined (reading 'forEach')
    at ParsedExpression.createFromMemberExpression (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:53:39)
    at ParsedFunction.initialiseVariablesMembersEtc (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedFunction.js:302:83)
    at /home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:153:42
    at Array.forEach (<anonymous>)
    at ParsedExpressionCall.initialiseExpression (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:152:36)
    at ParsedExpression.createFromElement (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:70:36)
    at ParsedFunction.initialiseVariablesMembersEtc (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedFunction.js:298:84)
    at /home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:153:42
    at Array.forEach (<anonymous>)
    at ParsedExpressionCall.initialiseExpression (/home/beaker/.vscode/extensions/juanblanco.solidity-0.0.176/out/src/server/parsedCodeModel/ParsedExpression.js:152:36)

    I also see the request for the definition of VRFConsumerBaseV2Plus

    [Trace - 12:45:15 PM] Sending request 'textDocument/definition - (135)'.
    Params: {
    "textDocument": {
        "uri": "file:///home/beaker/workspace/repro/lib/chainlink-brownie-contracts/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol"
    },
    "position": {
        "line": 3,
        "character": 24
    }
    }

I then see a couple of replies to the request that look like this:

[Trace - 12:46:51 PM] Received response 'textDocument/definition - (135)' in 95805ms.
Result: [
    {
        "uri": "file:///home/beaker/workspace/repro/lib/chainlink-brownie-contracts/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol",
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 0
            }
        }
    }
]

Followed by the final 'textDocument/didOpen' which opens the relevant file.

Thanks a lot for your help!

beaker-meeep commented 2 hours ago

I tried this repro on a much newer machine and ran into the same behavior. I also downloaded IntelliJ with the Solidity plugin and I was able to navigate between definitions in the chainlink lib contracts with no issue at all.

So my thinking is that I've got something configured incorrectly ... and it's not my old CPU or the size of the dependency.

juanfranblanco commented 2 hours ago

Have you got Copilot installed?