solidity icon indicating copy to clipboard operation
solidity copied to clipboard

LSP throwing an error on each and every character I type in the editor

Open Gilgames000 opened this issue 3 years ago • 20 comments

Description

The LSP throws an error whenever I'm editing a .sol file. The error gets triggered every time I type a character. Restarting the LSP or reinstalling it doesn't fix the problem.

Environment

  • Compiler version: 0.8.13
  • Editor: NeoVim 0.7.0
  • LSP client: NeoVim built-in
  • Operating system: Arch Linux

Steps to Reproduce

Open any .sol file and start typing.

Error message:

LSP[solc]: Error INVALID_SERVER_MESSAGE: {
  error = {
    code = -32603,
    message = "Unhandled exception: /solidity/libsolidity/lsp/HandlerBase.cpp(48): Throw in function Json::Value solidity::lsp::HandlerBase::toJson(const solidity::langutil::SourceLocatio
n&) const\nDynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Solidity assertion failed\n[solidity::util::tag_comment*] = Solidity
 assertion failed\n"
  },
  jsonrpc = "2.0"

Gilgames000 avatar Mar 21 '22 04:03 Gilgames000

Hey @Gilgames000. Thanks for your report. I am using coc.nvim along with NeoVIM / VIM. Can you maybe tell me your vim-native LSP configuration such that I can reproduce your local environment?

christianparpart avatar Mar 21 '22 10:03 christianparpart

Sure @christianparpart! I use the built-in LSP client, the official nvim-lspconfig configuration for it, nvim-cmp and an auto-completion engine that uses LSPs as completion sources, and nvim-lsp-installer to easily install and manage LSP servers.

You can install all of this using vim-plug

Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/nvim-lsp-installer'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'

and then use :LspInstall solc to install solc. That's it! I didn't customize the LSP config. The default config can be found here. It sets the nearest ancestor with a .git folder as the root directory, and triggers the server on .sol files. The LSP install script gets the server from the GitHub releases page.

The only problem is that I get the error quite randomly, meaning that it doesn't fire right away sometimes. Though it always shows up quite consistently after I write some code. I still couldn't figure out what code exactly triggers it since it shows up quite often anyway...

Gilgames000 avatar Mar 21 '22 22:03 Gilgames000

I tried enabling solc again today to see if I could find some more clues about the issue. After writing a few lines of code I got this:

LSP[solc]: Error INVALID_SERVER_MESSAGE: {
  error = {
    code = -32603,
    message = "Unhandled exception: /solidity/libsolidity/interface/CompilerStack.cpp(353): Throw in function bool solidity::frontend::CompilerStack::parse()\nDynamic exception type: boos
t::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Parser returned null but did not report error.\n[solidity::util::tag_comment*] = Parser returned null but d
id not report error.\n"
  },
  jsonrpc = "2.0"
}

Looks like a new message :monocle_face:

Gilgames000 avatar Mar 26 '22 16:03 Gilgames000

Yes, thanks @Gilgames000. Seems like neovim is doing something fishy here. It looks like it's not senting the initialization as its first step. I'll keep you posted. :)

christianparpart avatar Mar 29 '22 10:03 christianparpart

Yes, thanks @Gilgames000. Seems like neovim is doing something fishy here. It looks like it's not senting the initialization as its first step. I'll keep you posted. :)

I see, thanks! Should I open an issue on neovim repo? Or the lsp repo? Since you seemed to imply that the problem is on their end. Correct me if I'm wrong!

Gilgames000 avatar Apr 03 '22 17:04 Gilgames000

Hey @christianparpart this morning I decided to go back to coc.nvim for the time being just for Solidity since you said it works fine for you so I set it up using the config I found in your dotfiles. But now I'm facing the same problem and error message on coc.nvim too. Here's the log:

## versions

vim version: NVIM v0.7.0-dev+1299-g773516365
node version: v16.14.2
coc.nvim version: 0.0.80-1fffa716 2022-04-04 12:52:23 +0800
coc.nvim directory: /home/gilgames/.config/nvim/plugged/coc.nvim
term: tmux
platform: linux

## Log of coc.nvim


2022-04-05T08:07:38.806 INFO (pid:14813) [services] - registered service "languageserver.Solidity"
2022-04-05T08:07:38.808 INFO (pid:14813) [plugin] - coc.nvim initialized with node: v16.14.2 after 31ms
2022-04-05T08:07:40.304 INFO (pid:14813) [services] - Solidity state change: stopped => starting
2022-04-05T08:07:40.310 INFO (pid:14813) [language-client-index] - Language server "languageserver.Solidity" started with 15208
2022-04-05T08:07:40.351 INFO (pid:14813) [services] - Solidity state change: starting => running
2022-04-05T08:07:40.354 INFO (pid:14813) [services] - service languageserver.Solidity started
2022-04-05T09:52:31.727 ERROR (pid:14813) [language-client-client] - Received message which is neither a response nor a notification message:
{
    "error": {
        "code": -32603,
        "message": "Unhandled exception: /solidity/libsolidity/interface/CompilerStack.cpp(1193): Throw in function solidity::frontend::CompilerStack::resolveImports()::<lambda(const solidity::frontend::CompilerStack::Source*)>\nDynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Solidity assertion failed\n[solidity::util::tag_comment*] = Solidity assertion failed\n"
    },
    "jsonrpc": "2.0"
}

and then the log goes on and on with the same error message being spammed for each keystroke I press when I'm editing a Solidity file.

Gilgames000 avatar Apr 05 '22 08:04 Gilgames000

I'm having the exact same error but with coq_nvim. Used the same method as @Gilgames000 to install solc.

0xgui avatar Apr 15 '22 16:04 0xgui

Facing the same error on MacOS, same installation method. The language server works great for a few minutes, then starts throwing this error on every keystroke - haven't been able to find out what triggers it yet.

distractedm1nd avatar May 18 '22 04:05 distractedm1nd

I noticed you mentioned that nvim is doing something weird with the initialization, so I think this may be related: Running :LspRestart always fails, but it gives a different error.

  error = {
    code = -32002,
    message = "Server is not properly initialized."
  }

distractedm1nd avatar May 18 '22 07:05 distractedm1nd

Having the same issues as well. Running :LspRestart also yields

LSP[solc]: Error INVALID_SERVER_MESSAGE: {
  error = {
    code = -32002,
    message = "Server is not properly initialized."
  },
  jsonrpc = "2.0"

Read my log files and this is the first error that showed up for me

[ERROR][2022-05-11 22:03:31] .../lua/vim/lsp.lua:824	"LSP[solc]" "on_error" {
   "code =""INVALID_SERVER_MESSAGE",
   "err ="{
      "error ="{
         code = -32603,
         "message =""Unhandled exception: /solidity/libsolidity/interface/CompilerStack.cpp(353): Throw in function bool solidity::frontend::CompilerStack::parse()\nDynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Parser returned null but did not report error.\n[solidity::util::tag_comment*] = Parser returned null but did not report error.\n"
      },
      "jsonrpc =""2.0"
   }
}

mouseless0x avatar May 18 '22 23:05 mouseless0x

I'm with the same issue with coc.nvim. Everytime I open a solidity file, solc crashed.

[coc.nvim] The "solidity" server crashed 4 times in the last 3 minutes. The server will not be restarted.

Did anyone find a solution?

If I ran LspRestart solc

  error = {                                                                                                                                                                                                                                                                    
    code = -32002,                                                                                                                                                                                                                                                             
    message = "Server is not properly initialized."                                                                                                                                                                                                                            
  },                                                                                                                                                                                                                                                                           
  jsonrpc = "2.0"   

anajuliabit avatar Jul 05 '22 17:07 anajuliabit

It seems that this error is most prevalent when I am also running a hardhat node while simultaneously working in a solidity file.

When I spin down the hardhat node, the solc LSP seems to run fine unless I use LspRestart, which does still cause the initialization failure. It seems that the LSP server seems to work decently as long as the node is not running and I do not restart the LSP server.

There could be some underlying conflict caused by running the LSP and a local node in simultaneity on a localhost.

Side note: Running the local node on a different port: npx hardhat node --port 9000 also seems to assist in avoiding the initialization error, but have not confirmed much other than the LSP initialization error did not re-appear immediately after starting the node on an alternate port.

My workflow now has been to spin down the node, modify the code, then spin the node back up. Tis a bit a bugger, but a smidge better than the constant initialization errors upon each keystroke.

BitlyTwiser avatar Aug 07 '22 18:08 BitlyTwiser

When I spin down the hardhat node, the solc LSP seems to run fine unless I use LspRestart, which does still cause the initialization failure. It seems that the LSP server seems to work decently as long as the node is not running and I do not restart the LSP server.

@BitlyTwiser solc is pretty strict about when calls are allowed, i.e. it doesn't allow a request to document-highlight if the server has not yet received the initialization call just yet.

Would you mind trying out a debug binary? What distribution / OS are you testing on? Mind, that we recently also merged some improvements on the LSP side, not necessarily to address this, but it might have had an impact. In case you still see the errors, I would like to give you a binary that produces a debug solc.log file, that you could hand me back for inspection.

christianparpart avatar Sep 01 '22 13:09 christianparpart

@christianparpart Data points for my current system: Linux 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

I shall attempt to perform some development on the Solidity smart contracts in the next few days to determine if I am yet running into LSP issues.

I would indeed be more than happy assist via utilizing a debugging binary if the issue yet persists.

BitlyTwiser avatar Sep 03 '22 15:09 BitlyTwiser

@BitlyTwiser I've fixed a bug related to URL decoding. This might maybe also fix your problem.

Related fix-PR: https://github.com/ethereum/solidity/pull/13473

Would you mind giving that a try?

In case you need a prebuilt binary for Ubuntu Linux, here's one created by the CI:

https://output.circle-artifacts.com/output/job/1ddf7057-73e4-4ff4-92f4-4bff0a5ba70e/artifacts/0/solc

EDIT: You may need to sudo apt install libcvc4 in order to execute this binary, if not yet installed.

christianparpart avatar Sep 05 '22 10:09 christianparpart

Hi! I am experiencing the same problem as everyone here (error 32603 on pretty much every keystroke after writting some code)

I Have tried the fix above and it didn't solve the issue :( image

LSP[solc]: Error INVALID_SERVER_MESSAGE: {
  error = {
    code = -32603,
    message = "Unhandled exception: /solidity/libsolidity/lsp/HandlerBase.cpp(48): Throw in function Json::Value solidity::lsp::HandlerBase::toJson(const solidity::langutil::SourceLocation&) const\nDynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Solidity assertion failed\n[solidity::util::tag_comment*] = Solidity assertion failed\n"
  },
  jsonrpc = "2.0"

Any other fixes or ideas available? I am more than happy to run debug binaries

oscariquelme01 avatar Sep 15 '22 09:09 oscariquelme01

@oscariquelme01, the only LSP that worked for me on Neovim was vscode-solidity. I installed it using nvim-lsp-installer, which now migrates to mason. Mason doesn't support vscode-solidity yet, but I'm working on a PR to add. You can find my conf on my dotfiles repo

anajuliabit avatar Sep 15 '22 11:09 anajuliabit

@anajuliabit Thanks a lot for the dotfiles! I ll be trying to figure out how to set up solidity_ls in the mean time. Quick question tho, where did you find the list of configuration options for the solidity_ls language server? I can't find it anywhere :(

oscariquelme01 avatar Sep 16 '22 07:09 oscariquelme01

Personally, I've been having a lot more luck with solidity-ls for the time being. Configuration for this lsp is here

trevorgjohnson avatar Sep 16 '22 16:09 trevorgjohnson

Any progress to this, having the same issue just like @anajuliabit

nzhl avatar Sep 20 '22 02:09 nzhl

@oscariquelme01 they called the package solidity_ls on nvm-lspconfig. Conf is here.

anajuliabit avatar Sep 25 '22 13:09 anajuliabit

I tried enabling solc again today to see if I could find some more clues about the issue. After writing a few lines of code I got this:

LSP[solc]: Error INVALID_SERVER_MESSAGE: {
  error = {
    code = -32603,
    message = "Unhandled exception: /solidity/libsolidity/interface/CompilerStack.cpp(353): Throw in function bool solidity::frontend::CompilerStack::parse()\nDynamic exception type: boos
t::wrapexcept<solidity::langutil::InternalCompilerError>\nstd::exception::what: Parser returned null but did not report error.\n[solidity::util::tag_comment*] = Parser returned null but d
id not report error.\n"
  },
  jsonrpc = "2.0"
}

Looks like a new message 🧐

I am getting this frequently. The LSP is not usable for myself. I can produce this be deleting some lines and undoing deletion. Have you found a workaround?

beauwilliams avatar Oct 02 '22 04:10 beauwilliams

I have similar issue(0.8.17) with solc. I switched from lunarvim to astronvim which uses mason-lspconfig out of the box. With that I install solidity-ls through :LspInstall solidity which for the moment is more complete.

nonogakhi avatar Oct 08 '22 11:10 nonogakhi

Similar issue. The day I installed it it worked just fine, but after a restart I cannot get this to work. Fails as described above.

NeoVim v0.7.2 solc 0.8.17

installed via Mason.

oliversavio avatar Oct 13 '22 10:10 oliversavio

Hey @oliversavio, I recommend using solidity-ls for the time being that was just added to mason.nvim if you use it. It's been working great for me until the solc lsp gets fixed

trevorgjohnson avatar Oct 13 '22 16:10 trevorgjohnson

Also having this issue. Would really appreciate this getting fixed!

nickshatilo avatar Oct 13 '22 20:10 nickshatilo

Hey @oliversavio, I recommend using solidity-ls for the time being that was just added to mason.nvim if you use it. It's been working great for me until the solc lsp gets fixed

I seem to be getting this error when using solidity-ls - any idea why?

LSP[solidity]: Error SERVER_REQUEST_HANDLER_ERROR: "...neovim/0.8.0/share/nvim/runtime/lua/vim/lsp/handlers.lua:89: bad argument #1 to 'ipai
rs' (table expected, got nil)"

zkSoju avatar Nov 01 '22 23:11 zkSoju

@christianparpart any progress on this? I can confirm the -32603 error popping up on almost every key stroke with nvim v0.8.0 and solc 0.8.17 on Arch Linux.

sebastianst avatar Nov 10 '22 17:11 sebastianst

@christianparpart I can also confirm that the problem persists using #13473 (solc --version: 0.8.18-develop.2022.11.10+commit.a2de5d4b.Linux.g++)

sebastianst avatar Nov 10 '22 19:11 sebastianst

Same error here nvim v0.8.0 Arch Linux and Ubuntu WSL2.

R4k4210 avatar Nov 21 '22 05:11 R4k4210