|
1 | | -# Java LSIF indexer  |
2 | | - |
3 | | -Visit https://lsif.dev/ to learn about LSIF. |
4 | | - |
5 | | -## Usage |
6 | | - |
7 | | -⚠️ This project is under development so there is nothing to try out at the |
8 | | -moment. |
9 | | - |
10 | | -### Supported tools and versions |
11 | | - |
12 | | -Currently, only Java 8 with the build tool sbt is supported. We hope to increase |
13 | | -compatibility with more Java language versions and build tools as the project |
14 | | -evolves. |
15 | | - |
16 | | -| Language version | Support | |
17 | | -| ---------------- | --------------------------------- | |
18 | | -| Java 7 | ❌ | |
19 | | -| Java 8 | ✅ | |
20 | | -| Java 11 | ✅ | |
21 | | -| Java 12 | Not tested in CI, but should work | |
22 | | -| Java 13 | Not tested in CI, but should work | |
23 | | -| Java 14 | Not tested in CI, but should work | |
24 | | -| Java 15 | ✅ | |
25 | | -| Java 16 | Not tested in CI, but should work | |
26 | | -| Java 17 | Not tested in CI, but should work | |
27 | | - |
28 | | -| Build tool | Support | |
29 | | -| ---------- | ------- | |
30 | | -| Gradle | ✅ | |
31 | | -| Maven | ✅ | |
32 | | -| Bazel | ❌ | |
33 | | -| Buck | ❌ | |
34 | | -| sbt | ✅ | |
35 | | - |
36 | | -## Overview |
37 | | - |
38 | | -This project is implemented as a |
39 | | -[Java compiler plugin](https://docs.oracle.com/en/java/javase/11/docs/api/jdk.compiler/com/sun/source/util/Plugin.html) |
40 | | -that generates one |
41 | | -[SemanticDB](https://scalameta.org/docs/semanticdb/specification.html) file for |
42 | | -every `*.java` source file. After compilation completes, the SemanticDB files |
43 | | -are processed to produce LSIF. |
44 | | - |
45 | | - |
46 | | - |
47 | | -### Why Java compiler plugin? |
48 | | - |
49 | | -There are several benefits to implementing lsif-java as a compiler plugin: |
50 | | - |
51 | | -- **Simple installation**: compiler plugins are enabled with the `-Xplugin` |
52 | | - compiler option. All Java build tools support a way to customize compiler |
53 | | - options, simplifying installation. |
54 | | -- **Language fidelity**: by using the Java compiler to produce semantic |
55 | | - information, we ensure that the produced LSIF data is accurate even as new |
56 | | - Java language versions with new language features are released. |
57 | | -- **Environment fidelity**: by hooking into the compilation process of the build |
58 | | - tool, we minimize the risk of diverging from the CI build environment such as |
59 | | - installed system dependencies, custom compiler options and custom annotation |
60 | | - processors. |
61 | | - |
62 | | -### Why SemanticDB? |
63 | | - |
64 | | -SemanticDB is Protobuf schema for information about symbols and types in Java |
65 | | -programs, Scala programs and other languages. There are several benefits to |
66 | | -using SemanticDB as an intermediary representation for LSIF: |
67 | | - |
68 | | -- **Simplicity**: It's easy to translate a single Java source file into a single |
69 | | - SemanticDB file inside a compiler plugin. It's more complicated to produce |
70 | | - LSIF because compiler plugins does not have access to a project-wide context, |
71 | | - which is necessary to produce accurate definitions and hovers in multi-module |
72 | | - projects with external library dependencies. |
73 | | -- **Performance**: SemanticDB is fast to write and read. Each compilation unit |
74 | | - can be processed independently to keep memory usage low. The final conversion |
75 | | - from SemanticDB to LSIF can be safely parallelized. |
76 | | -- **Cross-language**: SemanticDB has a |
77 | | - [spec](https://scalameta.org/docs/semanticdb/specification.html) for Java and |
78 | | - Scala enabling cross-language navigation in hybrid Java/Scala codebases. |
79 | | -- **Cross-repository**: Compiler plugins have access to both source code and the |
80 | | - classpath (compiled bytecode of upstream dependencies). SemanticDB has been |
81 | | - designed so that it's also possible to generate spec-compliant symbols from |
82 | | - the classpath alone (no source code) and from the syntax tree of an individual |
83 | | - source file (no classpath). This flexibility allows the |
84 | | - [Metals](https://scalameta.org/metals/) language server to index codebases |
85 | | - from a variety of different inputs, and will be helpful for lsif-java in the |
86 | | - future to unblock cross-repository navigation. |
87 | | - |
88 | | -## Contributing |
89 | | - |
90 | | -The following sections provide tips on how to contribute to this codebase. |
91 | | - |
92 | | -### System dependencies |
93 | | - |
94 | | -- `java`: any version should work |
95 | | -- `git`: any version should work |
96 | | -- `lsif-semanticdb`: |
97 | | - `go get github.com/sourcegraph/lsif-semanticdb/cmd/lsif-semanticdb` |
98 | | -- `gradle`: `brew install gradle`, or see |
99 | | - [general installation guide](https://gradle.org/install/). |
100 | | -- `mvn`: `brew install maven`, or see |
101 | | - [general installation guide](https://www.baeldung.com/install-maven-on-windows-linux-mac). |
102 | | - |
103 | | -### Project structure |
104 | | - |
105 | | -These are the main components of the project. |
106 | | - |
107 | | -- `semanticdb-javac/src/main/java`: the Java compiler plugin that creates |
108 | | - SemanticDB files. |
109 | | -- `tests/minimized`: minimized Java source files that reproduce interesting test |
110 | | - cases. |
111 | | -- `tests/unit`: fast running unit tests that are helpful for local edit-and-test |
112 | | - workflows. |
113 | | -- `tests/snapshots`: slow running |
114 | | - ["snapshot tests"](https://jestjs.io/docs/en/snapshot-testing) that index a |
115 | | - corpus of published Java libraries. |
116 | | -- `build.sbt`: the sbt build definition. |
117 | | -- `project/plugins.sbt`: plugins for the sbt build. |
118 | | - |
119 | | -### Helpful commands |
120 | | - |
121 | | -| Command | Where | Description | |
122 | | -| ------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------- | |
123 | | -| `./sbt` | terminal | Start interactive sbt shell with Java 11. Takes a while to load on the first run. | |
124 | | -| `unit/test` | sbt | Run fast unit tests. | |
125 | | -| `~unit/test` | sbt | Start watch mode to run tests on file save, good for local edit-and-test workflows. | |
126 | | -| `buildTools/test` | sbt | Run slow build tool tests (Gradle, Maven). | |
127 | | -| `snapshots/testOnly tests.MinimizedSnapshotSuite` | sbt | Runs fast snapshot tests. Indexes a small set of files under `tests/minimized`. | |
128 | | -| `snapshots/testOnly tests.MinimizedSnapshotSuite -- *InnerClasses*` | sbt | Runs only individual tests cases matching the name "InnerClasses". | |
129 | | -| `snapshots/testOnly tests.LibrarySnapshotSuite` | sbt | Runs slow snapshot tests. Indexes a corpus of external Java libraries. | |
130 | | -| `snapshots/test` | sbt | Runs all snapshot tests. | |
131 | | -| `snapshots/run` | sbt | Update snapshot tests. Use this command after you have fixed a bug. | |
132 | | -| `cli/run --cwd DIRECTORY` | sbt | Run `lsif-java` command-line tool against a given Gradle/Maven build. | |
133 | | -| `fixAll` | sbt | Run Scalafmt, Scalafix and Javafmt on all sources. Run this before opening a PR. | |
134 | | - |
135 | | -### Import the project into IntelliJ |
136 | | - |
137 | | -It's recommended to use IntelliJ when editing code in this codebase. |
138 | | - |
139 | | -First, install the |
140 | | -[IntelliJ Community Edition](https://www.jetbrains.com/idea/download/). The |
141 | | -community edition is |
142 | | -[open source](https://github.com/JetBrains/intellij-community) and free to use. |
143 | | - |
144 | | -Next, install the IntelliJ Scala plugin. |
145 | | - |
146 | | -Finally, run "File > Project From Existing Sources" to import the sbt build into |
147 | | -IntelliJ. Select the "sbt" option if it asks you to choose between |
148 | | -sbt/BSP/Bloop. |
149 | | - |
150 | | -It's best to run tests from the sbt shell, not from the IntelliJ UI. |
151 | | - |
152 | | -### Don't use VS Code/Vim/Sublime Text/Emacs |
153 | | - |
154 | | -If you want to use completions and precise code navigation, it's not recommended |
155 | | -to use other editors than IntelliJ. IntelliJ is the only IDE that properly |
156 | | -supports hybrid Java/Scala codebases at the moment, although that may change |
157 | | -soon thanks to lsif-java :) |
158 | | - |
159 | | -### Tests are written in Scala |
160 | | - |
161 | | -This codebases uses the Scala library [MUnit](https://scalameta.org/munit/) to |
162 | | -write tests because: |
163 | | - |
164 | | -- MUnit has built-in assertions that print readable multiline diffs in color. |
165 | | -- MUnit makes it easy to implement |
166 | | - [snapshot testing](https://jestjs.io/docs/en/snapshot-testing), which is a |
167 | | - testing technique that's heavily used in this codebase. |
168 | | -- Multiline literal strings in Scala make it easy to write unit tests for source |
169 | | - code (which is always multiline). Modern versions of Java support multiline |
170 | | - string literals, but they're not supported in Java 8, which is supported by |
171 | | - lsif-java. |
172 | | - |
173 | | -## Benchmarks |
174 | | - |
175 | | -See [docs/benchmarks.md] for benchmark results. |
| 1 | +# Java indexer for the Language Server Index Format (LSIF)  |
| 2 | + |
| 3 | +| Documentation | Link | |
| 4 | +| -------------------- | ---------------------------------------------------------------------- | |
| 5 | +| Landing page | https://sourcegraph.github.io/lsif-java | |
| 6 | +| Getting started | https://sourcegraph.github.io/lsif-java/docs/getting-started.html | |
| 7 | +| Manual configuration | https://sourcegraph.github.io/lsif-java/docs/manual-configuration.html | |
| 8 | +| Contributing | https://sourcegraph.github.io/lsif-java/docs/contributing.html | |
| 9 | +| Design | https://sourcegraph.github.io/lsif-java/docs/design.html | |
0 commit comments