scalameta / nvim-metals

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

Error messages about "Code navigation will not work" are confusing #662

Open jqno opened 3 months ago

jqno commented 3 months ago

Describe the bug

I'm not 100% sure if this issue belongs here or with Metals proper. Please don't hesitate to close if I mis-posted.

I re-installed my machine the other day and ran into some issues getting my workspace up-and-running.

First, I ran into this message: Screenshot from 2024-04-09 13-08-45 (A) Not sure I can fault nvim-metals for this one, as it's the dressing.nvim plugin that clips the error message at an unfortunate spot, but on the other hand, if I pick "More information", I don't get the full error message either.

With dressing disabled, I do get the full message: Screenshot from 2024-04-09 13-16-32

But when I select More information, it's still not clear what I need to do:

## Metals Info
  - Metals Server version: 1.2.2
  - Metals Java: 21.0.2 from Private Build located at /usr/lib/jvm/java-21-openjdk-amd64

Below are listed the build targets for this workspace. One build target corresponds to one classpath. For example, normally one sbt project maps to two build targets: main and test.

## Workspaces

### Workspace: /home/jqno/w/dhl/dhl-parcel-transformation-service
 - Build definition is coming from sbt.
 - Build server currently being used is Bloop v1.5.15.

## Build Targets

### root
  - target type: Scala 3.3.3
  - goto functionality: metalsDecode:file:///home/jqno/w/my-project/root.metals-buildtarget
  - compilation: ✅ 
  - diagnostics: ✅ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ✅ 
  - java: ✅ 
  - recommendation: Goto definition for Java classes will not work, please install jdk sources in java home. Searched: /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/lib/src.zip

(...snipped lots of modules with green checkboxes...)

### my-project-build
  - target type: sbt 1.9.9
  - goto functionality: metalsDecode:file:///home/jqno/w/my-project/my-project-build.metals-buildtarget
  - compilation: ✅ 
  - diagnostics: ⚠️ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ❌
  - java: ✅ 
  - recommendation: Goto definition for Java classes will not work, please install jdk sources in java home. Searched: /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/lib/src.zip

### my-project-service-build-build
  - target type: sbt 1.9.9
  - goto functionality: metalsDecode:file:///home/jqno/w/my-project/my-project-build-build.metals-buildtarget
  - compilation: ✅ 
  - diagnostics: ⚠️ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ❌
  - java: ✅ 
  - recommendation: Goto definition for Java classes will not work, please install jdk sources in java home. Searched: /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/src.zip, /usr/lib/jvm/java-21-openjdk-amd64/lib/src.zip

I was thrown off the path for a bit by the diagnostics: ⚠️ and debugging: ❌ lines, because it turns out they weren't relevant for the problem I was trying to solve. The jdk sources from the recommendation were the culprit.

(B) /usr/lib/jvm/java-21-openjdk-amd64/src.zip exists, but it turns out that it's a symlink to a file that didn't exist until I installed the openjdk-21-source package. Took me a while to figure this out.

(C) I manage my JDKs through SDKman, so I also didn't expect I'd need to install native Ubuntu packages for Java.

Expected behavior

(A) Can we have a way to see the full message somewhere? It's pretty long and it sometimes gets clipped, which results in confusion. Also, sometimes I press Escape before I really read the message, and then when I regret my sloppiness, there's no way to get the message back (it's not in :messages, for example)

(B) The Metals Doctor says "recommendation: Goto definition for Java classes will not work, please install jdk sources in java home." I think that should be phrased a little stronger, because 1) it's not just for Java classes, but Scala classes as well, not just the ones in external dependencies but often even classes in my own project, and 2) Metals becomes almost unusable without this, so the word 'recommendation' is kind of weak.

(C) Is it possible to configure (nvim-)Metals to point to my SDKMan directories? The error message doesn't say anything about it, and I couldn't really find it in the documentation either (though I fully admit I might have missed it; in which case I apologise)

Operating system

Linux

Version of Metals

v1.2.2

Commit of nvim-metals

4f9bf0c