Skip to content

nicolas-guichard/scip-kotlin

 
 

Repository files navigation

Kotlin SemanticDB support

This codebase implements a Kotlin compiler plugin that can be used together with scip-java to emit SCIP indexes for Kotlin projects.

This is forked from github.com/mozsearch/semanticdb-kotlinc with added support for Kotlin 2+ for use in Searchfox.

Getting started

This project must be used together with scip-java. Visit scip-java for instructions on how to index Kotlin projects with scip-java. Note that scip-java indexes Kotlin sources even if you have no Java code.

Kotlin version compatibility

Because this plugin uses compiler internals, any given release of semanticdb-kotlinc only supports one version of Kotlin. Use the table below to find the version of semanticdb-kotlinc that matches the Kotlin version you are using in your project.

Kotlin version semanticdb-kotlinc version
1.8.x 0.3.2
1.9.x 0.4.0
2.1.20 0.5.0
2.2.0 0.6.0

The default main branch targets the next Kotlin release. The kotlin-x.y.z branches target the relevant Kotlin version. Bugfixes and improvements will only be backported to branches targeting Kotlin releases used by Searchfox.

SemanticDB support

This project is implemented as a SemanticDB compiler plugin. To generate SCIP, you first compile the Kotlin sources with the SemanticDB compiler plugin and then convert SemanticDB files into SCIP using scip-java index-semanticdb. See Low-level usage for more details on how to generate SemanticDB files and convert SemanticDB into SCIP.

Low-level usage

First, fetch the jar file of the SemanticDB compiler plugin: com.sourcegraph:semanticdb-kotlinc:VERSION. For example, you can use Coursier to download the jar file.

curl -fLo coursier https://github.com/coursier/launchers/raw/master/coursier && chmod +x ./coursier
export SEMANTICDB_KOTLIN_VERSION="latest.release" # or replace with a particular version
export SEMANTICDB_KOTLIN_JAR=$(./coursier fetch com.sourcegraph:semanticdb-kotlinc:$SEMANTICDB_KOTLIN_VERSION)

Once you have the jar file, you need to determine two compiler options:

  • sourceroot: the absolute path to the root directory of your codebase. All source files that you want to index should be under this directory. For Gradle codebases, this is typically the toplevel build.gradle file. For Maven codebases, this is typically the toplevel pom.xml file.
  • targetroot: the absolute path to the directory where you want the compiler plugin to write SemanticDB files. This can be any directory on your computer.

Now you have all the necessary parameters to invoke the Kotlin compiler with the SemanticDB compiler plugin.

kotlinc -Xplugin=${SEMANTICDB_KOTLIN_JAR} \
  -P plugin:semanticdb-kotlinc:sourceroot=SOURCEROOT_DIRECTORY \
  -P plugin:semanticdb-kotlinc:targetroot=TARGETROOT_DIRECTORY

Once the compilation is complete, the targetroot should contain *.semanticdb files in the META-INF/semanticdb sub-directory.

To convert the SemanticDB files into SCIP, run scip-java index TARGETROOT_DIRECTORY. If you have Coursier installed, you can run scip-java directly like this

cd $SOURCEROOT_DIRECTORY
./coursier launch --contrib scip-java -- index-semanticdb TARGETROOT_DIRECTORY

About

SCIP indexer for Kotlin. Implemented as a SemanticDB compiler plugin.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 96.2%
  • Java 3.8%