scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.09k stars 332 forks source link

LSP rename causes build server error #5834

Open ghostbuster91 opened 11 months ago

ghostbuster91 commented 11 months ago

Describe the bug

Full project to reproduce the issue: https://github.com/ghostbuster91/demos/tree/build-server

Video showing the problem: Kooha-2023-11-13-11-09-39.webm

Steps to reproduce:

  1. import project
  2. go to backend file
  3. try to rename backend trait
2023.11.13 11:09:51 ERROR text document: file:///home/kghost/workspace/demos/modules/http4s/src/main/scala/com/example/http/middleware/Backend.scala
java.nio.file.NoSuchFileException: /home/kghost/workspace/demos/modules/http4s/src/main/scala/com/example/http/middleware/Backend.scala
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
    at java.nio.file.Files.newByteChannel(Files.java:380)
    at java.nio.file.Files.newByteChannel(Files.java:432)
    at java.nio.file.Files.readAllBytes(Files.java:3287)
    at scala.meta.internal.io.PlatformFileIO$.slurp(PlatformFileIO.scala:45)
    at scala.meta.internal.io.FileIO$.slurp(FileIO.scala:24)
    at scala.meta.internal.mtags.Semanticdbs$.loadResolvedTextDocument(Semanticdbs.scala:70)
    at scala.meta.internal.mtags.Semanticdbs$.loadTextDocument(Semanticdbs.scala:51)
    at scala.meta.internal.metals.FileSystemSemanticdbs.textDocument(FileSystemSemanticdbs.scala:55)
    at scala.meta.internal.metals.AggregateSemanticdbs.loop$1(AggregateSemanticdbs.scala:30)
    at scala.meta.internal.metals.AggregateSemanticdbs.textDocument(AggregateSemanticdbs.scala:36)
    at scala.meta.internal.decorations.SyntheticsDecorationProvider.currentDocument(SyntheticsDecorationProvider.scala:296)
    at scala.meta.internal.decorations.SyntheticsDecorationProvider.syntheticDecorations(SyntheticsDecorationProvider.scala:181)
    at scala.meta.internal.decorations.SyntheticsDecorationProvider.$anonfun$publishSynthetics$1(SyntheticsDecorationProvider.scala:78)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.lang.Thread.run(Thread.java:1589)

2023.11.13 11:09:51 ERROR Build server error: source file not found: /home/kghost/workspace/demos/modules/http4s/src/main/scala/com/example/http/middleware/Backend.scala

Expected behavior

Trait should be renamed and no issue should occur

Operating system

Linux

Editor/Extension

Nvim (nvim-metals)

Version of Metals

v1.1.0

Extra context or search terms

No response

jkciesluk commented 10 months ago

Thanks for reporting! This is a tough case, there is probably a race condition. I've added a check https://github.com/scalameta/metals/pull/5908 so LSP shouldn’t throw, but we will probably need to fallback to InteractiveSemanticdbs when it gets out of sync. For now, changing anything else in the renamed file should fix the issue by recalculating semanticdb.