scip-java icon indicating copy to clipboard operation
scip-java copied to clipboard

`scala-cli` support

Open ckipp01 opened this issue 3 years ago • 2 comments

👋🏼 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-cli to ends up being your sourceroot, which can lead to the wrong path in your dump.lsif. For example in my project if I do scala-cli --semantic-db compile src/ the semanticdb will be created and found, but it will think that src/ is the sourceroot and then if you are running lsif-java from . you can run into issues. So just being careful and making sure where I point scala-cli to is also where I run lsif-java from 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.txt information 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.scala here would be quite simple, but you'd run into issue pretty quickly if users are not using directives and instead passing in deps via scala-cli -d <dependency> which is also valid. It wouldn't work in those cases. Either way, this might be a great feature

ckipp01 avatar Jan 17 '22 09:01 ckipp01

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.

olafurpg avatar Jan 17 '22 09:01 olafurpg

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.

ckipp01 avatar Jan 17 '22 09:01 ckipp01