scalameta / nvim-metals

A Metals plugin for Neovim
https://scalameta.org/metals/
Apache License 2.0
454 stars 74 forks source link

Metals interfering with manual build processes #683

Open xiaoshihou514 opened 1 week ago

xiaoshihou514 commented 1 week ago

Describe the bug

cd /tmp
mkdir my-project
cd my-project/
mkdir -p src/main/scala/example/
vi src/main/scala/example/Main.scala # @main def main() = print("hello scala")
scala-cli . --watch
Starting compilation server
Compiling project (Scala 3.4.1, JVM (17))
Compiled project (Scala 3.4.1, JVM (17))
Hello scalaProgram exited with return code 0.
# in another window
nvim src/main/scala/example/Main.scala
# scala-cli
Bloop 'bsp' command exited with code 1. Something may be wrong with the current configuration.
Running the clean sub-command to clear the working directory and remove caches might help.
If the error persists, please report the issue as a bug and attach a log with increased verbosity by passing -v -v -v.

add ! after hello scala and save (triggers scala-cli rebuild)

Compiling project (Scala 3.4.1, JVM (17))
Error compiling project (Scala 3.4.1, JVM (17))
Error: Unexpected error when compiling my-project_a71a881f95: java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:171)
        at dotty.tools.dotc.core.Definitions.ObjectClass(Definitions.scala:324)
        at dotty.tools.dotc.core.Definitions.ObjectType(Definitions.scala:328)
        at dotty.tools.dotc.core.Definitions.AnyRefAlias(Definitions.scala:427)
        at dotty.tools.dotc.core.Definitions.syntheticScalaClasses(Definitions.scala:2134)
        at dotty.tools.dotc.core.Definitions.syntheticCoreClasses(Definitions.scala:2147)
        at dotty.tools.dotc.core.Definitions.init(Definitions.scala:2163)
        at dotty.tools.dotc.core.Contexts$ContextBase.initialize(Contexts.scala:900)
        at dotty.tools.dotc.core.Contexts$Context.initialize(Contexts.scala:523)
        at dotty.tools.dotc.Run.rootContext(Run.scala:464)
        at dotty.tools.dotc.Run.<init>(Run.scala:485)
        at dotty.tools.dotc.Compiler.newRun(Compiler.scala:172)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
        at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
        at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)
        at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
        at monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)
        at monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)
        at monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1423)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

Compilation failed
ps -aux | grep bloop | grep -v grep
/usr/lib/jvm/java-21-openjdk-21.0.3.0.9-1.fc40.x86_64/bin/java -Dbloop.trun,,, # omitted
killall java
# press enter in scala-cli window
Starting compilation server
Compiling project (Scala 3.4.1, JVM (17))
Compiled project (Scala 3.4.1, JVM (17))
Hello scala!Program exited with return code 0.

Expected behavior

Metals does its own thing and I can build stuff as usual

Operating system

Linux

Version of Metals

latest stable

Commit of nvim-metals

1b87e6bfa4174b5fbaee9ca7ec79d8eae8df7f18

xiaoshihou514 commented 1 week ago

nvim-metals config:

return {
    "scalameta/nvim-metals",
    dependencies = {
        "nvim-lua/plenary.nvim",
    },
    ft = { "scala", "sbt", "java" },
    opts = function()
        local metals_config = require("metals").bare_config()
        metals_config.on_attach = function(client, buf)
            if client.server_capabilities.semanticTokensProvider then
                vim.lsp.semantic_tokens.start(buf, client.id)
            end
        end

        return metals_config
    end,
    config = function(self, metals_config)
        local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
        vim.api.nvim_create_autocmd("FileType", {
            pattern = self.ft,
            callback = function()
                require("metals").initialize_or_attach(metals_config)
            end,
            group = nvim_metals_group,
        })
    end,
}
xiaoshihou514 commented 1 week ago

Now that I think about it, it's most probably an upstream issue? Is there at least a way to kill the bloop daemon on nvim exit?