Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to definition in Chipyard with vim-lsp #6097

Closed
gonsolo opened this issue Feb 6, 2024 · 7 comments
Closed

Jump to definition in Chipyard with vim-lsp #6097

gonsolo opened this issue Feb 6, 2024 · 7 comments
Milestone

Comments

@gonsolo
Copy link

gonsolo commented Feb 6, 2024

I tried to get "Jump to definition" working with vim, vim-lsp for chipyard.
Chipyard is a complicated multi-gitsubmodule project.
I set up coursier, metals, bloop, etcetera and nothing works.
I am able to run http://127.0.0.1:5031 but nothing helps.
I followed the advice at https://www.scala-lang.org/blog/2020/10/27/bsp-in-sbt.html and nothing helps.
I think I had it running once with bloop but as soon as I went away and returned to the computer it was not working again.

Also this always show up when editing:

Code navigation will not work for 2 build targets in this workspace due to mis-configuration. Select 'More information' to learn how to fix this prob
lem.
1 - [Scala Language Server] More information
2 - [Scala Language Server] Don't show again

Selecting 1 fires up doctor in a browser window.

Universal Ctags is somewhat working but a working LSP would be better.

Any help? I'm able to try out any advice.

Expected behaviour:

Hit Ctrl-] in vim and jump to the definition of the class.

Operating system:
Linux

Java version:
17.0.9

Editor/extension:
vim-lsp

Metals version:
1.2.0

Workspace information:

  • Scala versions: 3.3.1
  • Build tools: 0. scala-cli
  • Build servers:
    0. scala-cli v1.1.2
  • All build tools in workspace:
@kasiaMarek
Copy link
Contributor

Thanks for the report. Do you have anything meaningful in metals logs .metals/metals.log?

@gonsolo
Copy link
Author

gonsolo commented Feb 8, 2024

Thanks for taking your time.

2024.02.08 08:40:15 INFO Started: Metals version 1.2.0 in folders '/home/gonsolo/src/chipyard/generators/tio/src/main/scala' for client vim-lsp .�[0m
2024.02.08 08:40:15 INFO Attempting to connect to the build server...�[0m
2024.02.08 08:40:15 INFO Running BSP server List(/home/gonsolo/.cache/scalacli/local-repo/bin/scala-cli/scala-cli, bsp, --json-options, /home/gonsolo/src/chipyard/generators/tio/src/main/scala/.scala-build/ide-options-v2.json, /home/gonsolo/src/chipyard/generators/tio/src/main/scala)�[0m
2024.02.08 08:40:15 INFO tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/gonsolo/src/chipyard/generators/tio/src/main/scala/.metals/bsp.trace.json or /home/gonsolo/.cache/metals/bsp.trace.json�[0m
2024.02.08 08:40:16 INFO BSP server: Starting compilation server�[0m
2024.02.08 08:40:18 INFO time: Connected to build server in 2.93s�[0m
2024.02.08 08:40:18 INFO Connected to Build server: scala-cli v1.1.2�[0m
2024.02.08 08:40:18 INFO time: Imported build in 0.12s�[0m
2024.02.08 08:40:19 INFO compiling scala_bd2c96d2de (1 scala source)�[0m
2024.02.08 08:40:19 INFO no build target found for /home/gonsolo/src/chipyard/generators/tio/src/main/scala/Tio.scala. Using presentation compiler with project's scala-library version: 3.3.1�[0m
2024.02.08 08:40:19 WARN Unable to run doctor. Make sure isHttpEnabled is set to true.�[0m
2024.02.08 08:40:21 ERROR SemanticDB not found: Tio.scala
scala.meta.internal.metals.ScalafixProvider$ScalafixRunException: SemanticDB not found: Tio.scala
at scala.meta.internal.metals.ScalafixProvider.$anonfun$runScalafixRules$1(ScalafixProvider.scala:163)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.lang.Thread.run(Thread.java:840)
�[0m
2024.02.08 08:40:21 INFO compiling scala_bd2c96d2de (1 scala source)�[0m
2024.02.08 08:40:21 WARN Could not find java sources in /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/lib/src.zip. Java symbols will not be available.�[0m
2024.02.08 08:40:21 INFO time: compiled scala_bd2c96d2de in 0.44s�[0m
2024.02.08 08:40:21 WARN Could not find java sources in /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/lib/src.zip. Java symbols will not be available.�[0m
2024.02.08 08:40:21 WARN Could not find java sources in /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/src.zip, /usr/lib/jvm/java-17-openjdk-amd64/lib/src.zip. Java symbols will not be available.�[0m
2024.02.08 08:40:21 INFO time: indexed workspace in 2.3s�[0m
2024.02.08 08:40:21 INFO compiling scala_bd2c96d2de (1 scala source)�[0m
2024.02.08 08:40:23 INFO time: compiled scala_bd2c96d2de in 1.29s�[0m
2024.02.08 08:40:23 INFO Selected port 5031�[0m
Feb. 08, 2024 8:40:23 AM io.undertow.Undertow start
INFO: starting server: Undertow - 2.2.20.Final
Feb. 08, 2024 8:40:23 AM org.xnio.Xnio
INFO: XNIO version 3.8.12.Final
Feb. 08, 2024 8:40:23 AM org.xnio.nio.NioXnio
INFO: XNIO NIO Implementation Version 3.8.12.Final
2024.02.08 08:40:23 INFO compiling scala_bd2c96d2de (1 scala source)�[0m
Feb. 08, 2024 8:40:23 AM org.jboss.threads.Version
INFO: JBoss Threads version 3.1.0.Final
2024.02.08 08:40:23 INFO Started Metals http server at http://127.0.0.1:5031�[0m
2024.02.08 08:40:23 INFO time: compiled scala_bd2c96d2de in 0.29s�[0m
2024.02.08 08:40:30 INFO Can not organize imports if file has error�[0m

@gonsolo
Copy link
Author

gonsolo commented Feb 8, 2024

I also filed an issue with vim-lsp to get all relevant parties onboard.

As I mentioned there, a hello world scala project works flawlessly, so basic vim-lsp and metals do work.

I'm willing to take the time to debug and would be happy for advice.

@kasiaMarek
Copy link
Contributor

This is starting scala-cli as build server. We use it as a fallback, if no build tool is configured but if you're in a project that uses sbt, then sbt should be used (I assume you have build.sbt in your root folder). You need to change your build tool and build server choice, you should be able to do this using metals doctor (though I'm not sure about vim-lsp). If not, probably easiest if you close the editor delete .metals and reopen. Upon open it should ask you if you want to use sbt or scala-cli choose sbt and then it should show smth like this: New sbt workspace detected, would you like to import the build?. Click Import build and it will import the build to bloop and run bloop as build server.

@gonsolo
Copy link
Author

gonsolo commented Feb 8, 2024

Thanks, that was helpful. I somewhat got it building.

After installing and running bloop server, import the build in metals doctor I am able to "jump to definition", but only if I start vim at the root directory and open files from there. Going to generators/.../src/main/scala and opening a scala file from there again gives me an error about scala-cli.
Also, opening a file and trying to "jump to definition" always fails for the first time with "No definition found", waiting for a second, then trying again works.

@kasiaMarek
Copy link
Contributor

but only if I start vim at the root director and open files from there

Yes, only then metals will import the sbt project and have all the information from sbt build needed.

Also, opening a file and trying to "jump to definition" always fails for the first time with "No definition found", waiting for a second, then trying again works.

This might just require an initial compile to finish for the submodule (build target) to work. So if you come back to a submodule you've work in before it should work right away.

@gonsolo
Copy link
Author

gonsolo commented Feb 8, 2024

Yes, only then metals will import the sbt project and have all the information from sbt build needed.

Ok, that will waste many people many hours, an error message might be nice. But thanks anyway.

This might just require an initial compile to finish for the submodule (build target) to work. So if you come back to a submodule you've work in before it should work right away.

Nope, it's fragile. Closing and opening the file and trying again, might or might not work, sometimes takes a second, sometings hangs forever, then you have to go to a different class and try that one which usually works, then you can go back, try the original one which then works most of the time.

Anyway, thank you very much, I got it working now, your help is much appreciated.

I'm closing this now. (And hopefully this issue will help people in the future searching for this issue.)

@gonsolo gonsolo closed this as completed Feb 8, 2024
@jkciesluk jkciesluk added this to the Metals v1.2.2 milestone Feb 15, 2024
@tgodzik tgodzik modified the milestones: Metals v1.2.2, Metals v1.3.0 Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants