scalameta / metals

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

Protobuf generated (Java) package not detected #4057

Open vishalovercome opened 2 years ago

vishalovercome commented 2 years ago

Describe the bug

I have lots of Java classes generated using protobuf that I use in my Scala project. My code used to compile with metals earlier. It still works with sbt shell. However, it seems to not be able to detect the package with all the generated code. Something seems to have regressed between 0.11.4 to 0.11.6. Below is sample error message in logs:

2022.06.23 01:07:29 WARN Could not load snapshot text for ...

Error in "problems" section: package XXX does not exist

Restarting/re-importing/clean compile hasn't helped.

Expected behavior

Code compiles cleanly.

Operating system

Linux

Editor/Extension

VS Code

Version of Metals

v0.11.6

Extra context or search terms

No response

vishalovercome commented 2 years ago

Not sure if this is related to #4053 but deleting .bloop folder and reimporting seems to have worked 🤷🏽‍♂️

tanishiking commented 2 years ago

@vishalovercome Thank you for reporting!

Error in "problems" section: package XXX does not exist

Do you mean package XXX is the package of the generated Java files (from protobuf), and you get this error on the source code that refers to the generated Java packages (XXX) right? Also, 2022.06.23 01:07:29 WARN Could not load snapshot text for ... is shown in the file that refers to the generated Java packages?

Something seems to have regressed between 0.11.4 to 0.11.6.

Do you mean, that downgrading the Metals server to 0.11.4 makes it work again?

.bloop folder and reimporting seems to have worked 🤷🏽‍♂️

You mean ~/.bloop or $PROJECT/.bloop? If you mean ~/.bloop It might be related to #4053, but if it means $PROJECT/.bloop it might be just like a stale bloop diagnosis problem and it's not related to #4053


Also, how did you generate the protobuf code, and what the project structure looks like? I think it's better to create a minimal reproducible project setup to debug, and that information would be helpful.

vishalovercome commented 2 years ago

Do you mean package XXX is the package of the generated Java files (from protobuf), and you get this error on the source code that refers to the generated Java packages (XXX) right?

Yes

Also, 2022.06.23 01:07:29 WARN Could not load snapshot text for ... is shown in the file that refers to the generated Java packages?

I saw this in the bloop logs.

Something seems to have regressed between 0.11.4 to 0.11.6.

Do you mean, that downgrading the Metals server to 0.11.4 makes it work again?

Yes

.bloop folder and reimporting seems to have worked 🤷🏽‍♂️

You mean ~/.bloop or $PROJECT/.bloop? If you mean ~/.bloop It might be related to #4053, but if it means $PROJECT/.bloop it might be just like a stale bloop diagnosis problem and it's not related to #4053

I had to delete the folder inside the project. Haven't tried deleting the other one but the problem has resurfaced, so maybe I should delete that also?

Also, how did you generate the protobuf code, and what the project structure looks like? I think it's better to create a minimal reproducible project setup to debug, and that information would be helpful.

  • Did you use some specific sbt plugins like sbt-protoc, or generate by CLI and copy-pasted?

Yes. I use the sbt-protoc plugin to generate java classes via sbt shell. Once created, they remain as part of the repository.

  • Are those files in src-managed directory? No
tgodzik commented 2 years ago

That might be some stale compilation I think. Maybe the reproduction step would be to gnerate the protobuf files after indexing everything in Metals? I think metals workspace itself sometimes has issues with the generated BuildInfo files

vishalovercome commented 2 years ago

Metals never had any such issues earlier and this combined with some other issues with bloop (repeated java upgrade / restart prompts, etc.) leads me to believe that something has regressed recently. Hopefully the recently added fixes to bloop will make it go away. For now, deleting both .bloop folders is the only way to make things work

tanishiking commented 2 years ago

That might be some stale compilation I think. Maybe the reproduction step would be to gnerate the protobuf files after indexing everything in Metals?

:+1:

Hopefully the recently added fixes to bloop will make it go away

Oh, is there a relevant fix in bloop?

tgodzik commented 2 years ago

That might be some stale compilation I think. Maybe the reproduction step would be to gnerate the protobuf files after indexing everything in Metals?

+1

Hopefully the recently added fixes to bloop will make it go away

Oh, is there a relevant fix in bloop?

Clean compiler should now properly remove the old class directory.