ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.47k stars 5.8k forks source link

LSP: `textDocument/definition` always returns "result":[] #13035

Open gpersoon opened 2 years ago

gpersoon commented 2 years ago

Description

Environment

Steps to Reproduce

setup

Install solc-windows.exe in C:\tmp\solidity\ Install Notepad++ Setup a language definition for Solidity in Notepad++ (for example via https://github.com/alin1popa/solidity-notepadplusplus-userdefined-highlight) Download https://github.com/Ekopalypse/NppLspClient/releases/download/v.0.0.9-alpha/NppLspClient_x64.zip Install NppLspClient.dll in C:\Program Files\Notepad++\plugins\NppLspClient Edit config file via menu open configuration file (NppLspClientConfig.toml) to contain:

[lspservers.solidity]
executable = 'C:\tmp\solidity\solc-windows.exe'
args = '--lsp'
mode = "io"
auto_start_server = true

Have some sample soldity files in C:\tmp\solidity\ test.sol:

// SPDX-License-Identifier: MIT
import "test2.sol";

contract test() {
   uint x=1;
   uint y=x;
}   

test2.sol

// SPDX-License-Identifier: MIT

test in Notepad++

Open file test.sol in Notepad++ In menu option Plugins/NppLspClient_x64 choose Toggle Console to see debug output. Put the cursor on import In menu option Plugins/NppLspClient_x64 choose Goto Definition Now nothing happens in the editor main screen. The LSP output console shows: {"id":4,"jsonrpc":"2.0","result":[]} So somehow the lookup doesn't work. The same happens with anything else I select.

Note: the detection of syntax errors does work and is shown in the editor, so the LSP interaction does work.

full log

checking current lexer
checking language server status: solidity
  trying to start C:\tmp\solidity\solc-windows.exe
  running
on_initialize: 15908
write_to_stdin: Content-Length: 2128

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":15908,"clientInfo":{"name":"NppLspClient","version":"0.0.1"},"rootUri":"file:///C%3A/tmp/solidity","initializationOptions":{},"capabilities":{"workspace":{"applyEdit":false,"workspaceEdit":{"documentChanges":false},"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":false},"symbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":false},"configuration":false,"workspaceFolders":false},"textDocument":{"publishDiagnostics":{"relatedInformation":false},"synchronization":{"dynamicRegistration":false,"willSave":false,"willSaveWaitUntil":false,"didSave":true},"completion":{"dynamicRegistration":false,"contextSupport":false,"completionItem":{"snippetSupport":false,"commitCharactersSupport":false,"documentationFormat":["plaintext"],"deprecatedSupport":false},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":false,"contentFormat":["plaintext"]},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"documentationFormat":["plaintext"]}},"definition":{"dynamicRegistration":false},"references":{"dynamicRegistration":false},"documentHighlight":{"dynamicRegistration":false},"documentSymbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"codeAction":{"dynamicRegistration":false},"codeLens":{"dynamicRegistration":false},"formatting":{"dynamicRegistration":false},"rangeFormatting":{"dynamicRegistration":false},"onTypeFormatting":{"dynamicRegistration":false},"rename":{"dynamicRegistration":false},"documentLink":{"dynamicRegistration":false},"typeDefinition":{"dynamicRegistration":false},"implementation":{"dynamicRegistration":false},"colorProvider":{"dynamicRegistration":false},"foldingRange":{"dynamicRegistration":false,"rangeLimit":100,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":null}}
on_message_received: Content-Length: 205

{"id":0,"jsonrpc":"2.0","result":{"capabilities":{"definitionProvider":true,"implementationProvider":true,"textDocumentSync":{"change":2,"openClose":true}},"serverInfo":{"name":"solc","version":"0.8.14"}}}
    initialized response received
write_to_stdin: Content-Length: 52

{"jsonrpc":"2.0","method":"initialized","params":{}}
on_file_opened:: solidity: C:\tmp\solidity\test.sol
on_file_opened: initialized=true
write_to_stdin: Content-Length: 291

{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///C%3A/tmp/solidity/test.sol","languageId":"solidity","version":0,"text":"// SPDX-License-Identifier: MIT\r\nimport \"test2.sol\";\r\n\r\ncontract test() {\r\n   uint x=1;\r\n   uint y=x;\r\n}   \r\n"}}}
on_message_received: Content-Length: 299

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":2314,"message":"ParserError: Expected '{' but got '('","range":{"end":{"character":14,"line":3},"start":{"character":13,"line":3}},"severity":1,"source":"solc"}],"uri":"file:///C%3A/tmp/solidity/test.sol"}}
write_to_stdin: Content-Length: 166

{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///C%3A/tmp/solidity/test.sol"},"position":{"character":0,"line":1}}}
on_message_received: Content-Length: 36

{"id":1,"jsonrpc":"2.0","result":[]}
cameel commented 2 years ago

Pinging @christianparpart

christianparpart commented 2 years ago

I will respond ASAP. Thanks for the reminder. :)

sebastianst commented 2 years ago

@christianparpart I can confirm that my solc (version 0.8.16+commit.07a7930e.Linux.g++) has the same problem, definitions are always empty. OS: Arch Linux Editor: neovim with built-in lsp (config from https://github.com/neovim/nvim-lspconfig)

The solc lsp is working properly otherwise, e.g. detecting syntax errors or faulty imports.

christianparpart commented 2 years ago

@gpersoon Would you mind trying out this branch? Please tell me if you need a binary I should create for you (otherwise, just checkout the PRs branch and build).

@sebastianst while the above linked PR does fix it indeed for me, I am not sure it does for you. The reason why @gpersoon did have empty goto-def results is because URL decoding on his Windows platform is much more relevant (due to drive letters) than on Linux. Since you mentioned Linux in your version string, I wonder if it does fix it for you, too. Otherwise I'd like to get some I/O trace from you (can neovim's builtin lsp store one to disk? :thinking:).

sebastianst commented 2 years ago

@christianparpart thanks, the PR didn't fix the problem for me, so it seems to be a different issue. Here is a trace log when trying to go-to-definition when on an identifier defined in the same Solidity file:

[DEBUG][2022-09-27 11:32:28] .../lua/vim/lsp.lua:1023   "LSP[solc]"     "client.request"        1       "textDocument/definition"       {  position = {    character = 19,    line = 59  },  textDocument = {    uri = "file:///home/seb/yg/yieldgate/packages/contracts/contracts/YieldGate.sol"  }}     <function 1>    1
[DEBUG][2022-09-27 11:32:28] .../vim/lsp/rpc.lua:347    "rpc.send"      {  id = 22,  jsonrpc = "2.0",  method = "textDocument/definition",  params = {    position = {      character = 19,      line = 59    },    textDocument = {      uri = "file:///home/seb/yg/yieldgate/packages/contracts/contracts/YieldGate.sol"    }  }}
[DEBUG][2022-09-27 11:32:28] .../vim/lsp/rpc.lua:454    "rpc.receive"   {  id = 22,  jsonrpc = "2.0",  result = {}}
[TRACE][2022-09-27 11:32:28] ...lsp/handlers.lua:488    "default_handler"       "textDocument/definition"       {  ctx = '{\n  bufnr = 1,\n  client_id = 1,\n  method = "textDocument/definition",\n  params = {\n    position = {\n      character = 19,\n      line = 59\n    },\n    textDocument = {\n      uri = "file:///home/seb/yg/yieldgate/packages/contracts/contracts/YieldGate.sol"\n    }\n  }\n}',  result = {}}
[INFO][2022-09-27 11:32:28] ...lsp/handlers.lua:324     "textDocument/definition"       "No location found"
gpersoon commented 2 years ago

@christianparpart could you create a binary? (i'm stuck on getting the boost library to work)

Op vr 2 sep. 2022 om 15:37 schreef Christian Parpart < @.***>:

@gpersoon https://github.com/gpersoon Would you mind trying out this branch? Please tell me if you need a binary I should create for you (otherwise, just checkout the PRs branch and build).

@sebastianst https://github.com/sebastianst while the above linked PR does fix it indeed for me, I am not sure it does for you. The reason why @gpersoon https://github.com/gpersoon did have empty goto-def results is because URL decoding on his Windows platform is much more relevant (due to drive letters) than on Linux. Since you mentioned Linux in your version string, I wonder if it does fix it for you, too. Otherwise I'd like to get some I/O trace from you (can neovim's builtin lsp store one to disk? 🤔).

— Reply to this email directly, view it on GitHub https://github.com/ethereum/solidity/issues/13035#issuecomment-1235516341, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJXKE32BI67WZ4STOYLWTLV4H7IXANCNFSM5WFK34HA . You are receiving this because you were mentioned.Message ID: @.***>

cameel commented 2 years ago

@gpersoon You can get the binary from the CI runs on that branch. For example here are the artifacts of the most recent run of the CI job that produces a static Linux binary.

gpersoon commented 2 years ago

Hi @cameel, thanks for the link to the CI. Is there a windows binary in there too? I can't find it. As the issue is windows specific it can't be tested with the linux binary.

cameel commented 2 years ago

Yeah: b_win artifacts.

gpersoon commented 2 years ago

I've tested the windows binary 0.8.18-ci.2022.11.4+commit.a2de5d4b.Windows.msvc and the output is still the same. Not sure if this rpc call is supposed to give any output.

{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///C%3A/tmp/solidity/test.sol"},"position":{"character":3,"line":2}}}
on_message_received: Content-Length: 36

{"id":1,"jsonrpc":"2.0","result":[]}