scalameta / coc-metals

Deprecated in favor of scalameta/nvim-metals
http://scalameta.org/metals/
Apache License 2.0
167 stars 24 forks source link

UnhandledRejection with `metals.super-method-hierarchy` and `metals.goto-super-method` commands #439

Closed render1980 closed 2 years ago

render1980 commented 2 years ago

Bug description

Hello!

Got problem with coc commands metals.super-method-hierarchy and metals.goto-super-method using nvim coc-metals plugin in Scala project.

[coc.nvim]: UnhandledRejection: Internal error.
Error: Internal error.
    at Ol (~/.vim/plugged/coc.nvim/build/index.js:37:224)
    at Sp (~/.vim/plugged/coc.nvim/build/index.js:36:11261)
    at Immediate.<anonymous> (~/.vim/plugged/coc.nvim/build/index.js:36:11111)
    at processImmediate (internal/timers.js:464:21)

To Reproduce Steps:

  1. Open .scala source code file in neovim
  2. Move to parent method of Class / trait (in Scala)
  3. Type :CocCommand and choose metals.super-method-hierarchy or metals.goto-super-method
  4. Type :CocOpenLog to watch errors

Expected behavior

Methods of children classes are shown for metals.super-method-hierarchycommand. Going to super method for metals.goto-super-method command.

Diagnostics information

:CocOpenLog

2021-11-11T15:42:51.980 INFO (pid:640022) [services] - registered service "languageserver.ccls"
2021-11-11T15:42:51.985 INFO (pid:640022) [coc-conjure] - CoC conjure enabled!
2021-11-11T15:42:52.062 INFO (pid:640022) [coc-git] - Looking for git in: git
2021-11-11T15:42:52.081 INFO (pid:640022) [services] - registered service "highlight"
2021-11-11T15:42:52.605 INFO (pid:640022) [plugin] - coc.nvim 0.0.80-03c9add7cd initialized with node: v14.18.1 after 737ms
2021-11-11T15:42:52.617 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:42:55.138 INFO (pid:640022) [language-client-index] - Language server "metals" started with 640105
2021-11-11T15:42:55.406 INFO (pid:640022) [attach] - receive notification: runCommand []
2021-11-11T15:43:11.982 INFO (pid:640022) [attach] - receive notification: runCommand []
2021-11-11T15:45:05.691 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:06.992 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:07.582 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:08.813 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:11.618 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:13.875 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:15.179 INFO (pid:640022) [attach] - receive notification: highlight []
2021-11-11T15:45:24.608 INFO (pid:640022) [attach] - receive notification: runCommand []
2021-11-11T15:45:27.458 ERROR (pid:640022) [server] - unhandledRejection  Promise {
  │ <rejected> Mm [Error]: Internal error.
  │ │ │ at Ol (~/.vim/plugged/coc.nvim/build/index.js:37:224)
  │ │ │ at Sp (~/.vim/plugged/coc.nvim/build/index.js:36:11261)
  │ │ │ at Immediate.<anonymous> (~/.vim/plugged/coc.nvim/build/index.js:36:11111)
  │ │ │ at processImmediate (internal/timers.js:464:21) {
  │ │ code: -32603,
  │ │ data: 'java.lang.RuntimeException: java.lang.reflect.InvocationTargetException\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)\n' +
  │ │ │ '\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n' +
  │ │ │ '\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n' +
  │ │ │ '\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)\n' +
  │ │ │ '\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)\n' +
  │ │ │ '\tat java.base/java.lang.Thread.run(Thread.java:831)\n' +
  │ │ │ 'Caused by: java.lang.reflect.InvocationTargetException\n' +
  │ │ │ '\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n' +
  │ │ │ '\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)\n' +
  │ │ │ '\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n' +
  │ │ │ '\tat java.base/java.lang.reflect.Method.invoke(Method.java:567)\n' +
  │ │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)\n' +
  │ │ │ '\t... 11 more\n' +
  │ │ │ 'Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.TextDocumentIdentifier.getUri()" because the return value of "org.eclipse.lsp4j.                           TextDocumentPositionParams.getTextDocument()" is null\n' +
  │ │ │ '\tat scala.meta.internal.implementation.Supermethods.jumpToSelectedSuperMethod(Supermethods.scala:51)\n' +
  │ │ │ '\tat scala.meta.internal.metals.MetalsLanguageServer.executeCommand(MetalsLanguageServer.scala:1770)\n' +
  │ │ │ '\t... 16 more\n'
  │ }                                                                                                                                                                                           } Mm [Error]: Internal error.
 │ at Ol (~/.vim/plugged/coc.nvim/build/index.js:37:224)
  │ │ at Sp (~/.vim/plugged/coc.nvim/build/index.js:36:11261)
  │ │ at Immediate.<anonymous> (~/.vim/plugged/coc.nvim/build/index.js:36:11111)
  │ │ at processImmediate (internal/timers.js:464:21) {
  │ code: -32603,
  │ data: 'java.lang.RuntimeException: java.lang.reflect.InvocationTargetException\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)\n' +
  │ │ '\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n' +
  │ │ '\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n' +
  │ │ '\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)\n' +
  │ │ '\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)\n' +
  │ │ '\tat java.base/java.lang.Thread.run(Thread.java:831)\n' +
  │ │ 'Caused by: java.lang.reflect.InvocationTargetException\n' +
  │ │ '\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n' +
  │ │ '\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)\n' +
  │ │ '\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n' +
  │ │ '\tat java.base/java.lang.reflect.Method.invoke(Method.java:567)\n' +
  │ │ '\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)\n' +
  │ │ '\t... 11 more\n' +
  │ │ 'Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.TextDocumentIdentifier.getUri()" because the return value of "org.eclipse.lsp4j.TextDocumentPositionParams.  getTextDocument()" is null\n' +
  │ │ '\tat scala.meta.internal.implementation.Supermethods.jumpToSelectedSuperMethod(Supermethods.scala:51)\n' +
  │ │ '\tat scala.meta.internal.metals.MetalsLanguageServer.executeCommand(MetalsLanguageServer.scala:1770)\n' +
  │ │ '\t... 16 more\n'
  }
> nvim -v

NVIM v0.5.0
Build type: Debug
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -DNVIM_TS_HAS_SET_MATCH_LIMIT -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=1 -I~/go/src/neovim/build/config -I~/go/src/neovim/src -I~/go/src/neovim/.deps/usr/include -I/usr/include -I~/go/src/neovim/build/src/nvim/auto -I~/go/src/neovim/build/include
Compiled by root@pc

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"
:CocInfo

## versions
  vim version: NVIM v0.5.0
  node version: v14.18.1
  coc.nvim version: 0.0.80-03c9add7cd
  coc.nvim directory: ~/.vim/plugged/coc.nvim
  term: screen
  platform: linux
▶ less ~/.vim/plugged/coc.nvim/package.json | grep version
  "version": "0.0.80"
:CocExtensions

...
* coc-metals 1.0.11 ~/.config/coc/extensions/node_modules/coc-metals
...

codeLens is enabled in coc settings:

:CocConfig

```json
{
"metals.superMethodLensesEnabled": true,
"metals.enable": true,
"codeLens.enable": true,
"java.implementationsCodeLens.enabled": true,
"diagnostic.virtualText": true,
"java.referencesCodeLens.enabled": true,
"coc.preferences.jumpCommand": "tab drop",
"jedi.enable": true,
"jedi.startupMessage": true,
"jedi.markupKindPreferred": "plaintext",
"jedi.trace.server": true,
"jedi.jediSettings.autoImportModules": [],
"jedi.executable.command": "jedi-language-server",
"jedi.executable.args": [],
"jedi.completion.disableSnippets": false,
"jedi.diagnostics.enable": true,
"jedi.diagnostics.didOpen": true,
"jedi.diagnostics.didChange": true,
"jedi.diagnostics.didSave": true,
"jedi.workspace.extraPaths": [],
"python.pythonPath": "/usr/bin/python3",
"coc.source.iced.enable": true,
"coc.preferences.formatOnType": true,
"coc.preferences.formatOnSaveFiletypes": ["css", "markdown", "javascript", "python", "json", "yaml", "yml"],
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": [
"c",
"cpp",
"objc",
"objcpp"
],
"rootPatterns": [
".ccls",
"compile_commands.json",
".vim/",
".git/",
".hg/"
],
"initializationOptions": {
"cache": {
"directory": "/tmp/ccls"
}
}
}
}
}

lsp4j which is used by metals:

> ls ~/./.cache/coursier/v1/https/repo1.maven.org/maven2/org/eclipse/lsp4j/org.eclipse.lsp4j/
0.12.0
> cat /etc/os-release

NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
...
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Tried

The problem is still the same.

Have no idea what's the reason of the problem.

ckipp01 commented 2 years ago

Thanks for reporting @render1980.

Move to parent method of Class / trait (in Scala)

So this actually needs to be used the other way around, not at the parent site. So for example


trait Thing {
  def a: Int <-- it won't work here
  def b: Int <-- it won't work here
}

class OtherThing extends Thing {
  override def a: Int = ??? <-- it would work here
  override def b: Int = ??? <-- it would work here
}

If you want to see the implementation on the parent member, you'd want to use the goto implementations mapping. If there are more than 1, it will show them all to you and you can choose.

All that to say, exception shouldn't be thrown like that, so we can probably fix that to ensure it doesn't lead to a red herring like this.

render1980 commented 2 years ago

Hi @ckipp01

Thank you for the response.

If you want to see the implementation on the parent member, you'd want to use the goto implementations mapping.

If I want to see the implementations on the parent member I also can use coc-implementation command and it works (at the parent site).

But currently these both methods (metals.super-method-hierarchy and metals.goto-super-method) don't work on both sites and produce the same error:

[coc.nvim]: UnhandledRejection: Internal error.
Error: Internal error.
    at Ol (~/.vim/plugged/coc.nvim/build/index.js:37:224)
    at Sp (~/.vim/plugged/coc.nvim/build/index.js:36:11261)
    at Immediate.<anonymous> (/Users/fungus/.vim/plugged/coc.nvim/build/index.js:36:11111)
    at processImmediate (internal/timers.js:461:21)
ckipp01 commented 2 years ago

@render1980 does it work on the minimal example that I have up above, or is this only happening in your project? I'll move this back over to the coc-metals repo. I don't actually even have coc-metals set up for myself with nvim anymore as I solely use nvim-metals now, so it might take a bit for me to get to this. I'm surprised something is going wrong with this though as there isn't a whole lot going on, but one thing that might help is if you can grab the lsp.trace logs for the resquest/response. You can see how to get those here: https://scalameta.org/metals/docs/contributors/getting-started#json-rpc-trace

render1980 commented 2 years ago

It doesn't work neither in this minimal example nor in my project.

Trace for your example:

[Trace - 00:23:27 AM] Received request 'workspace/executeCommand - (33)'
Params: {
  "command": "goto-super-method",
  "arguments": [
    {
      "document": "file:///~/go/src/scala_test/src/main/scala/Test.scala",
      "position": {
        "line": 6,
        "character": 15
      }
    }
  ]
}

[Trace - 00:23:27 AM] Sending response 'workspace/executeCommand - (33)'. Processing request took 5ms
Result: null
dos65 commented 2 years ago

I can confirm that this doesn't work in VSCode too. Previously parameters were extracted into specific GotoSuperMethodParams

But then it was replaced on TextDocumentPositionParams that isn't compatible with old format.

ckipp01 commented 2 years ago

Yup, I'm actually working on a fix atm @dos65