NomicFoundation / hardhat-vscode

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

with emacs lsp-bridge package, textDocument/definition find contract definition not work #573

Open getong opened 1 month ago

getong commented 1 month ago

The code file example contracts/BasicERC20.sol from https://github.com/protokol/solidity-typescript-hardhat-template

The code sample:

import { ERC20Pausable } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";

find ERC20Pausable definition fail:

--- [10:15:13.605713] Send textDocument/definition request (44080) to 'solidity' for project 
{
   "id": 44080,
   "method": "textDocument/definition",
   "params": {
      "position": {
         "line": 6,
         "character": 9
      },
      "textDocument": {
         "uri": "file:///Users/gerald/test/typescript/solidity-typescript-hardhat-template/contracts/BasicERC20.sol"
      }
   },
   "message_type": "request",
   "jsonrpc": "2.0"
}

--- [10:15:13.606691] Recv textDocument/definition response (44080) from 'solidity' for project 
Eval in Emacs: (lsp-bridge-find-def-fallback '(:line 6 :character 9))
{
   "jsonrpc": "2.0",
   "id": 44080,
   "result": null
}

But find the file definition works, find the "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol", it jump to the right file

--- [10:16:13.605574] Send textDocument/definition request (3315) to 'solidity' for project 
{
   "id": 3315,
   "method": "textDocument/definition",
   "params": {
      "position": {
         "line": 6,
         "character": 95
      },
      "textDocument": {
         "uri": "file:///Users/gerald/test/typescript/solidity-typescript-hardhat-template/contracts/BasicERC20.sol"
      }
   },
   "message_type": "request",
   "jsonrpc": "2.0"
}

--- [10:16:13.606381] Recv textDocument/definition response (3315) from 'solidity' for project 
Eval in Emacs: (lsp-bridge-define--jump '"/Users/gerald/test/typescript/solidity-typescript-hardhat-template/node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol" '"" '(:line 6 :character 0))
{
   "jsonrpc": "2.0",
   "id": 3315,
   "result": {
      "uri": "file:///Users/gerald/test/typescript/solidity-typescript-hardhat-template/node_modules/%40openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol",
      "range": {
         "start": {
            "line": 6,
            "character": 0
         },
         "end": {
            "line": 6,
            "character": 96
         }
      }
   }
}

I also test the code with emacs lsp-mode package, same behaviour, same error.

kanej commented 4 weeks ago

I have not been able to reproduce this error when navigating within the vscode extension against the protokol template repo.

Which version of the language server is being used by the emacs package?

getong commented 4 weeks ago

0.9.0 I know this work with vscode, but it does not work with emacs. I does not test it with vim, you might take a test with vim.

kanej commented 3 weeks ago

0.9.0 I know this work with vscode, but it does not work with emacs. I does not test it with vim, you might take a test with vim.

The latest version of the solidity language server is 0.8.3, is 0.9.0 the version of the emacs package?

Can you try updating to the last language server and retesting?

I initially thought there might be a mapping issue with the line/column numbers coming from the emacs package, but the message shown matches the message that vscode sends for onDefinition for the ERC20Pausable token in BasicERC20.sol. If other messages are give correct responses then is suggests it is not a message encoding issue either.

getong commented 3 weeks ago

I update it with

npm install @nomicfoundation/solidity-language-server -g

same error

Does it setup with initial setting?

kanej commented 2 weeks ago

The defaults should work in this case. The directory that you start the language server might have an effect, if its not able to identify the Hardhat/Foundry project directory.

Can you point me to the emacs package you are using to interact with our Language Server?

getong commented 2 weeks ago

https://github.com/manateelazycat/lsp-bridge