metals icon indicating copy to clipboard operation
metals copied to clipboard

Worksheet not re-compiling if signature changed on source

Open Swoorup opened this issue 2 years ago • 7 comments

Describe the bug

When a signature changes in source scala file, metals worksheet fails to recompile with the following error:

java.lang.NoSuchMethodError: 'void woot.core.AnimalDsl$.animalConfig(scala.Function1)'
    at repl.MdocSession$App.<init>(circe.worksheet.sc:135)
    at repl.MdocSession$.app(circe.worksheet.sc:3)

The workaround is to restart metals server.

Expected behavior

Metals recompiles both source followed by worksheet.

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

0.11.8+23-2dffaf36-SNAPSHOT

Extra context or search terms

worksheet, metals

Swoorup avatar Aug 15 '22 14:08 Swoorup

Thanks for reporting! Do you have an example to share, I managed to change the signature and the worksheets still worked. The only issue was that the completions were not up to date, which we should fix, but it was compiling alright.

tgodzik avatar Aug 15 '22 16:08 tgodzik

Related https://github.com/scalameta/metals/pull/4270

tgodzik avatar Aug 15 '22 16:08 tgodzik

This happened on my multi-project folder. I can reproduce quite easily.

But I can't seem to recreate an isolated enough example :/ I'll post it here when I am able to...

Swoorup avatar Aug 16 '22 00:08 Swoorup

Tried the latest change and got this

java.lang.ClassCastException: class woof.core.bot.animal.dsl.AnimalConfigBuilder cannot be cast to class woof.core.bot.animal.dsl.AnimalConfigDsl$AnimalConfigBuilder (woof.core.bot.animal.dsl.AnimalConfigBuilder and woof.core.bot.animal.dsl.AnimalConfigDsl$AnimalConfigBuilder are in unnamed module of loader java.net.URLClassLoader @18e69ca8)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at woof.core.bot.animal.dsl.AnimalConfigDsl$.animalConfig(AnimalConfigDsl.scala:18)
    at repl.MdocSession$MdocApp.<init>(dsl.worksheet.sc:133)
    at repl.MdocSession$.app(dsl.worksheet.sc:3)

Swoorup avatar Aug 16 '22 09:08 Swoorup

The latest change was just a minor tweak, unfortunately it wouldn't fix anything. Mdoc should pick up the classpath with the compiled artifacts and should be able to run normally. There are sometimes issues with more complicated classpath loading issues such as akka, but otherwise there shouldn't be any issue.

This looks like the code compiled and failed to run, which is unexpected. Does the code run normally though? Would ClassCastException have any merit?

tgodzik avatar Aug 16 '22 09:08 tgodzik

Coming to this after a longer time, the only option I see is that the worksheets do not wait for things to get fully compiled. We should check that and see if this can be still reproduced.

tgodzik avatar Dec 13 '23 09:12 tgodzik

It seems we always recompile the build target and wait for the compilation to finish before evaluating the worksheet, and I can't reproduce this behaviour. If this is still an issue, have you been able to construct a reproduction that you could share?

kasiaMarek avatar Jan 29 '24 13:01 kasiaMarek

This issue was closed because no new information was added for the last 30 days. If you have any relevant information, feel free to add it and reopen the issue.

github-actions[bot] avatar Feb 29 '24 10:02 github-actions[bot]