Skip to content

Commit 075340e

Browse files
authored
Merge pull request #73 from olafurpg/olafurpg/readme
Update readme
2 parents cbbf452 + 9818b6a commit 075340e

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

README.md

+66-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,74 @@
11
# Kotlin SCIP support
2+
<img src="https://img.shields.io/maven-central/v/com.sourcegraph/semanticdb-kotlinc?style=flat-square" />
23

3-
This codebase implements a Kotlin compiler plugin that can be used together
4-
with [scip-java](https://sourcegraph.github.io/scip-java) to emit
4+
This codebase implements a Kotlin compiler plugin that can be used together with
5+
[scip-java](https://sourcegraph.github.io/scip-java) to emit
56
[SCIP](https://github.com/sourcegraph/scip) indexes for Kotlin projects.
67

78
## Getting started
89

910
This project must be used together with scip-java. Visit
10-
[scip-java](https://sourcegraph.github.io/scip-java/) for instructions on how
11-
to index Kotlin projects with scip-java. Note that scip-java indexes Kotlin
12-
sources even if you have no Java code.
11+
[scip-java](https://sourcegraph.github.io/scip-java/) for instructions on how to
12+
index Kotlin projects with scip-java. Note that scip-java indexes Kotlin sources
13+
even if you have no Java code.
14+
15+
## SemanticDB support
16+
17+
This project is implemented as a
18+
[SemanticDB](https://scalameta.org/docs/semanticdb/specification.html) compiler
19+
plugin. To generate SCIP, you first compile the Kotlin sources with the
20+
SemanticDB compiler plugin and then convert SemanticDB files into SCIP using
21+
`scip-java index-semanticdb`. See [Low-level usage](#low-level-usage) for more
22+
details on how to generate SemanticDB files and convert SemanticDB into SCIP.
23+
24+
## Low-level usage
25+
26+
27+
First, fetch the jar file of the SemanticDB compiler plugin:
28+
[`com.sourcegraph:semanticdb-kotlinc:VERSION`](https://mvnrepository.com/artifact/com.sourcegraph/semanticdb-kotlinc).
29+
For example, you can use
30+
[Coursier](https://get-coursier.io) to download the jar file.
31+
32+
```sh
33+
curl -fLo coursier https://github.com/coursier/launchers/raw/master/coursier && chmod +x ./coursier
34+
export SEMANTICDB_KOTLIN_VERSION="latest.release" # or replace with a particular version
35+
export SEMANTICDB_KOTLIN_JAR=$(./coursier fetch com.sourcegraph:semanticdb-kotlinc:$SEMANTICDB_KOTLIN_VERSION)
36+
```
37+
38+
Once you have the jar file, you need to determine two compiler options:
39+
40+
- `sourceroot`: the absolute path to the root directory of your codebase. All
41+
source files that you want to index should be under this directory. For Gradle
42+
codebases, this is typically the toplevel `build.gradle` file. For Maven
43+
codebases, this is typically the toplevel `pom.xml` file.
44+
- `targetroot`: the absolute path to the directory where you want the compiler
45+
plugin to write SemanticDB files. This can be any directory on your computer.
46+
47+
Now you have all the necessary parameters to invoke the Kotlin compiler with
48+
the SemanticDB compiler plugin.
49+
50+
```sh
51+
kotlinc -Xplugin=${SEMANTICDB_KOTLIN_JAR} \
52+
-P plugin:semanticdb-kotlinc:sourceroot=SOURCEROOT_DIRECTORY \
53+
-P plugin:semanticdb-kotlinc:targetroot=TARGETROOT_DIRECTORY
54+
```
55+
56+
Once the compilation is complete, the targetroot should contain `*.semanticdb`
57+
files in the `META-INF/semanticdb` sub-directory.
58+
59+
To convert the SemanticDB files into SCIP, run `scip-java index TARGETROOT_DIRECTORY`.
60+
If you have Coursier installed, you can run scip-java directly like this
61+
62+
```sh
63+
cd $SOURCEROOT_DIRECTORY
64+
./coursier launch --contrib scip-java -- index-semanticdb TARGETROOT_DIRECTORY
65+
```
66+
67+
68+
69+
70+
71+
72+
73+
1374

0 commit comments

Comments
 (0)