scalameta / coc-metals

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

Errors and autosuggestions doesn't work #442

Closed sicr0 closed 2 years ago

sicr0 commented 2 years ago

Describe the bug For some reason when I write code that is obviously wrong (like using a printl function) CoC doesn't warn me until I save the file. Also the window with autosuggestions doesn't appear anymore while I'm writing

To Reproduce Steps to reproduce the behavior:

  1. Install coc-metals with :CocInstall coc-metals.
  2. Not having it installed in any other ways.
  3. That's it

Expected behavior Errors highlighted and autosuggestions appearing

Screenshots Screenshot_20211126_150303 Installation:

Additional context It feels like the plugin is running so slow it doesn't update.

Search terms autosuggestion, lint

sicr0 commented 2 years ago

Found the solution by reinstalling

sicr0 commented 2 years ago

I began happening again

ckipp01 commented 2 years ago

For some reason when I write code that is obviously wrong (like using a printl function) CoC doesn't warn me until I save the file.

This is by design. There are two types of errors that Metals can report. One being syntactic where we can parse your file via scalameta and immediately know that it's incorrect, like wrong start to an expression or missing brace, but the other types of diagnostics need your code to be compiled first. So that's why the save is necessary. The save triggers the compile, when then returns the diagnostics.

sicr0 commented 2 years ago

Thanks. Didn't know that. About the autosuggestion with the pop-up window, sometimes after I just started coding it works. Then it just stops appearing. Also, it works in Scala2, but not Scala3 projects

ckipp01 commented 2 years ago

It definitely shouldn't stop working. When that happens if you look in the .metals/metals.log file, do you see any errors or anything?

sicr0 commented 2 years ago

Yes, here is the exception happening:

2021.11.26 20:27:14 INFO  no build target: using presentation compiler with only scala-library: 3.1.0
2021.11.26 20:27:14 INFO  time: compiled root in 2.46s
Exception in thread "pool-3-thread-1" java.util.NoSuchElementException: head of empty String
    at scala.collection.StringOps$.head$extension(StringOps.scala:1129)
    at dotty.tools.dotc.semanticdb.Scala3$StringOps$.isJavaIdent(Scala3.scala:405)
    at scala.meta.internal.pc.SemanticdbSymbols$.addName$1(SemanticdbSymbols.scala:92)
    at scala.meta.internal.pc.SemanticdbSymbols$.addDescriptor$1(SemanticdbSymbols.scala:127)
    at scala.meta.internal.pc.SemanticdbSymbols$.addSymName(SemanticdbSymbols.scala:137)
    at scala.meta.internal.pc.SemanticdbSymbols$.symbolName(SemanticdbSymbols.scala:79)
    at scala.meta.internal.pc.CompletionProvider.visit$1(CompletionProvider.scala:116)
    at scala.meta.internal.pc.CompletionProvider.$anonfun$5(CompletionProvider.scala:138)
    at scala.meta.internal.pc.CompletionProvider.enrichWithSymbolSearch$$anonfun$1(CompletionProvider.scala:70)
    at scala.collection.immutable.List.map(List.scala:250)
    at scala.meta.internal.pc.CompletionProvider.enrichWithSymbolSearch(CompletionProvider.scala:70)
    at scala.meta.internal.pc.CompletionProvider.filterInteresting(CompletionProvider.scala:138)
    at scala.meta.internal.pc.CompletionProvider.completions(CompletionProvider.scala:44)
    at scala.meta.internal.pc.ScalaPresentationCompiler.complete$$anonfun$1(ScalaPresentationCompiler.scala:166)
    at scala.meta.internal.pc.CompilerAccess.withSharedCompiler(CompilerAccess.scala:137)
    at scala.meta.internal.pc.CompilerAccess.$anonfun$1(CompilerAccess.scala:87)
    at scala.meta.internal.pc.CompilerAccess.onCompilerJobQueue$$anonfun$1(CompilerAccess.scala:197)
    at scala.meta.internal.pc.CompilerJobQueue$Job.run(CompilerJobQueue.scala:139)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Exception in thread "pool-3-thread-2" java.util.NoSuchElementException: head of empty String
    at scala.collection.StringOps$.head$extension(StringOps.scala:1129)
    at dotty.tools.dotc.semanticdb.Scala3$StringOps$.isJavaIdent(Scala3.scala:405)
    at scala.meta.internal.pc.SemanticdbSymbols$.addName$1(SemanticdbSymbols.scala:92)
    at scala.meta.internal.pc.SemanticdbSymbols$.addDescriptor$1(SemanticdbSymbols.scala:127)
    at scala.meta.internal.pc.SemanticdbSymbols$.addSymName(SemanticdbSymbols.scala:137)
    at scala.meta.internal.pc.SemanticdbSymbols$.symbolName(SemanticdbSymbols.scala:79)
    at scala.meta.internal.pc.CompletionProvider.visit$1(CompletionProvider.scala:116)
    at scala.meta.internal.pc.CompletionProvider.$anonfun$5(CompletionProvider.scala:138)
    at scala.meta.internal.pc.CompletionProvider.enrichWithSymbolSearch$$anonfun$1(CompletionProvider.scala:70)
    at scala.collection.immutable.List.map(List.scala:250)
    at scala.meta.internal.pc.CompletionProvider.enrichWithSymbolSearch(CompletionProvider.scala:70)
    at scala.meta.internal.pc.CompletionProvider.filterInteresting(CompletionProvider.scala:138)
    at scala.meta.internal.pc.CompletionProvider.completions(CompletionProvider.scala:44)
    at scala.meta.internal.pc.ScalaPresentationCompiler.complete$$anonfun$1(ScalaPresentationCompiler.scala:166)
    at scala.meta.internal.pc.CompilerAccess.withSharedCompiler(CompilerAccess.scala:137)
    at scala.meta.internal.pc.CompilerAccess.$anonfun$1(CompilerAccess.scala:87)
    at scala.meta.internal.pc.CompilerAccess.onCompilerJobQueue$$anonfun$1(CompilerAccess.scala:197)
    at scala.meta.internal.pc.CompilerJobQueue$Job.run(CompilerJobQueue.scala:139)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
2021.11.26 20:27:51 INFO  compiling root (1 scala source)
No more data in the server stdin, exiting...
No more data in the server stdin, exiting...
No more data in the server stdin, exiting...
No more data in the server stdin, exiting...
2021.11.26 20:27:51 INFO  Shut down connection with build server.
2021.11.26 20:27:51 INFO  Shut down connection with build server.
No more data in the client stdin, exiting...
No more data in the client stdin, exiting...
sicr0 commented 2 years ago

I've found out that this issue happens only after the first drop-down suggestion is used, after that it just stops working

ckipp01 commented 2 years ago

Hey @sicr0 so I just took a closer look at the stacktrace and the place that the exception is coming from was actually recently fixed. Would you be able to try the latest snapshot? The issue should be gone https://scalameta.org/metals/docs/editors/vim#using-latest-metals-snapshot

sicr0 commented 2 years ago

Hi @ckipp01, using the latest snapshot, the problem is not fixed. This is my stacktrace:

2021.12.02 03:15:34 INFO  tracing is disabled for protocol LSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/ch6/.metals/lsp.trace.json or /home/sicro/.cache/metals/lsp.trace.json
2021.12.02 03:15:34 INFO  logging to file /home/sicro/dev/Scala/ch6/.metals/metals.log
2021.12.02 03:15:34 INFO  Started: Metals version 0.10.9+120-ff0815ae-SNAPSHOT in workspace '/home/sicro/dev/Scala/ch6'for client coc.nvim 0.0.80.
2021.12.02 03:15:35 INFO  time: initialize in 1.16s
2021.12.02 03:15:36 INFO  Attempting to connect to the build server...
2021.12.02 03:15:35 INFO  skipping build import with status 'Installed'
2021.12.02 03:15:38 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/ch6/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.02 03:15:38 INFO  Attempting to connect to the build server...
2021.12.02 03:15:38 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/ch6/project/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.02 03:15:38 INFO  time: Connected to build server in 2.48s
2021.12.02 03:15:38 INFO  Connected to Build server: Bloop v1.4.11
2021.12.02 03:15:40 INFO  no build target: using presentation compiler with only scala-library: 3.1.0
2021.12.02 03:15:41 INFO  no build target: using presentation compiler with only scala-library: 3.1.0
2021.12.02 03:15:42 INFO  time: indexed workspace in 1.96s
2021.12.02 03:15:42 INFO  compiling root (1 scala source)
2021.12.02 03:15:46 INFO  time: compiled root in 3.77s
java.util.concurrent.RejectedExecutionException: Task scala.concurrent.impl.CallbackRunnable@51681af4 rejected from java.util.concurrent.ThreadPoolExecutor@39039846[Shutting down, pool size = 4, active threads = 3, queued tasks = 0, completed tasks = 524]
    at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055)
    at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825)
    at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1355)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$4.execute(ExecutionContextImpl.scala:138)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:72)
    at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1(Promise.scala:288)
    at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1$adapted(Promise.scala:288)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:288)
    at scala.concurrent.Promise.complete(Promise.scala:53)
    at scala.concurrent.Promise.complete$(Promise.scala:52)
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:187)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
ckipp01 commented 2 years ago

Can you produce a code sample that this happens with instructions on exactly how to reproduce it?

sicr0 commented 2 years ago

I run sbt new scala/scala3.g8.

Then I modify the top Main.scala to:

def dou(a: Map): Unit =
    val b = new Arra

@main def hello: Unit =
    println("Hello world!")
    println(msg)

def msg = "I was compiled by Scala 3. :)"

At this point you can see that Metals works perfectly when writing functions parameters. But when in the second line I write new Arra it doesn't show any suggestion even though it should

ckipp01 commented 2 years ago

Hey @sicr0 sorry for the delay. Do you see any errors in your .metals/metals.log while you're doing this? I just tried your reproduction steps and I'm not seeing any issues. At the point you mention I am getting completion results:

Screenshot 2021-12-26 at 18 27 26
sicr0 commented 2 years ago

Hey @ckipp01, I updated to the latest Snapshot. It still happens. This is the .metals/metals.log:

2021.12.27 01:46:20 INFO  tracing is disabled for protocol LSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/.metals/lsp.trace.json or /home/sicro/.cache/metals/lsp.trace.json
2021.12.27 01:46:20 INFO  logging to file /home/sicro/dev/Scala/try/.metals/metals.log
2021.12.27 01:46:20 INFO  Started: Metals version 0.10.9+226-e28384c3-SNAPSHOT in workspace '/home/sicro/dev/Scala/try'for client coc.nvim 0.0.80.
2021.12.27 01:46:22 INFO  time: initialize in 1.32s
2021.12.27 01:46:22 INFO  Attempting to connect to the build server...
2021.12.27 01:46:22 INFO  skipping build import with status 'Installed'
2021.12.27 01:46:28 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.27 01:46:32 INFO  Attempting to connect to the build server...
2021.12.27 01:46:32 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/project/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.27 01:46:38 INFO  time: Connected to build server in 15s
2021.12.27 01:46:38 INFO  Connected to Build server: Bloop v1.4.11-19-93ebe2c6
2021.12.27 01:46:55 INFO  time: indexed workspace in 16s
2021.12.27 01:46:55 INFO  compiling root (1 scala source)
2021.12.27 01:46:56 INFO  no build target found for /home/sicro/dev/Scala/try/.metals/.tmp/Main-5946873169865709225.scala. Using presentation compiler with project's scala-library version: 3.1.0
2021.12.27 01:46:57 INFO  time: compiled root in 1.69s
2021.12.27 01:46:57 INFO  compiling root (1 scala source)
2021.12.27 01:46:57 INFO  time: compiled root in 0.23s
2021.12.27 02:01:55 INFO  /home/sicro/dev/Scala/try/src/main/scala/Main.scala:1:12: stale bloop error: Missing type parameter for Map
def dou(a: Map): Unit =
           ^^^
2021.12.27 02:01:55 INFO  /home/sicro/dev/Scala/try/src/main/scala/Main.scala:2:9: stale bloop error: missing argument for parameter _length of constructor Array in class Array: (_length: Int): Array[T]
    val b = new Array
        ^^^^^^^^^
2021.12.27 02:01:55 INFO  /home/sicro/dev/Scala/try/src/main/scala/Main.scala:1:12: stale bloop error: Missing type parameter for Map
def dou(a: Map): Unit =
           ^^^
2021.12.27 02:01:55 INFO  /home/sicro/dev/Scala/try/src/main/scala/Main.scala:2:9: stale bloop error: missing argument for parameter _length of constructor Array in class Array: (_length: Int): Array[T]
    val b = new Array
        ^^^^^^^^^
java.util.concurrent.RejectedExecutionException: Task scala.concurrent.impl.CallbackRunnable@3b817c6b rejected from java.util.concurrent.ThreadPoolExecutor@3fbeffc3[Shutting down, pool size = 3, active threads = 3, queued tasks = 0, completed tasks = 494]
    at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055)
    at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825)
    at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1355)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$4.execute(ExecutionContextImpl.scala:138)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:72)
    at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1(Promise.scala:288)
    at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1$adapted(Promise.scala:288)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:288)
    at scala.concurrent.Promise.complete(Promise.scala:53)
    at scala.concurrent.Promise.complete$(Promise.scala:52)
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:187)
    at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
2021.12.27 02:02:06 INFO  tracing is disabled for protocol LSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/.metals/lsp.trace.json or /home/sicro/.cache/metals/lsp.trace.json
2021.12.27 02:02:06 INFO  logging to file /home/sicro/dev/Scala/try/.metals/metals.log
2021.12.27 02:02:06 INFO  Started: Metals version 0.10.9+226-e28384c3-SNAPSHOT in workspace '/home/sicro/dev/Scala/try'for client coc.nvim 0.0.80.
2021.12.27 02:02:08 INFO  time: initialize in 1.25s
2021.12.27 02:02:08 INFO  Attempting to connect to the build server...
2021.12.27 02:02:08 INFO  skipping build import with status 'Installed'
2021.12.27 02:02:10 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.27 02:02:10 INFO  Attempting to connect to the build server...
2021.12.27 02:02:10 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/sicro/dev/Scala/try/project/.metals/bsp.trace.json or /home/sicro/.cache/metals/bsp.trace.json
2021.12.27 02:02:10 INFO  time: Connected to build server in 2.71s
2021.12.27 02:02:10 INFO  Connected to Build server: Bloop v1.4.11-19-93ebe2c6
2021.12.27 02:02:13 INFO  time: indexed workspace in 2.56s
2021.12.27 02:02:15 INFO  no build target found for /home/sicro/dev/Scala/try/.metals/.tmp/Main-5616483884788498065.scala. Using presentation compiler with project's scala-library version: 3.1.0

I don't get exactly what the problem might be. Should I create a file named /home/sicro/dev/Scala/try/.metals/lsp.trace.json?

ckipp01 commented 2 years ago

It could be that completions are just being screwed up because the code isn't valid. For example change your Map to Map[Int, Int] or something and see if it fixes it.

ckipp01 commented 2 years ago

Since I haven't heard back I'm going to go ahead and close. If you have other issues feel free to report back.