`scala-cli` support
👋🏼 hello! I wanted to drop this off here since I got this working and think it's pretty neat. Lately I've been using scala-cli quite a bit and I was curious if I could get precise code navigation working with it. It was actually somewhat simple, but I did hit on a couple small things that maybe having built-in support for index would help with.
- You can see the navigation for the project working here: https://sourcegraph.com/github.com/ckipp01/exists@main/-/blob/src/Main.scala
- You can see how I set it up with GitHub Actions here: https://github.com/ckipp01/exists/blob/main/.github/workflows/sourcegraph.yml
Producing semanticdb with scala-cli is as easy as just compiling your project with --semantic-db as a flag like: scala-cli compile --semantic-db ., which makes it easy for lsif index-semanticdb . to pick it up. However there are a few gotchas, or things that aren't working yet that I'll list below for others that maybe stumble on this.
- Wherever you point
scala-clito ends up being your sourceroot, which can lead to the wrong path in yourdump.lsif. For example in my project if I doscala-cli --semantic-db compile src/the semanticdb will be created and found, but it will think thatsrc/is the sourceroot and then if you are runninglsif-javafrom.you can run into issues. So just being careful and making sure where I pointscala-clito is also where I runlsif-javafrom fixed this. This might be trickier than it other build tools since there is no "build file". - There really isn't a way to export the
javacopts.txtinformation afaik. I asked about this here in hopes of figuring out a non-hacky way of getting this info to enable cross-repository navigation - Lastly I used directives right in my file, so for these use cases it's super easy to get this all to work and I can imagine adding a
ScalaCliBuildTool.scalahere would be quite simple, but you'd run into issue pretty quickly if users are not using directives and instead passing in deps viascala-cli -d <dependency>which is also valid. It wouldn't work in those cases. Either way, this might be a great feature
Thank you for reporting! This is exciting.
maybe having built-in support for index would help
Is there a way to automatically detect which files are compiled with scala-cli? We currently detect sbt builds with project/build.properties and we would need something similar for scala-cli scripts.
instead passing in deps via scala-cli -d
which is also valid.
I think it's OK to not support this use-case to begin with.
Is there a way to automatically detect which files are compiled with scala-cli?
I don't think it super straightforward unless you just assume any *.sc or *.scala file under where you are looking is valid, which maybe isn't a bad thing in this situation since a scala-cli workspaces are sort of just a bag of scala files. The only way to be able to get a better idea would be to check out where the .scala/ dir is placed, but that's not created until ran, and even then it won't tell you really the "source" dirs but give you the package structure and all the class/tasty/etc files.