eclipse / buildship

The Eclipse Plug-ins for Gradle project.
530 stars 169 forks source link

Support of Kotlin DSL files [google summer of code] #1259

Closed D0zee closed 1 year ago

D0zee commented 1 year ago

This PR adds support for .build.kts files inside the Eclipse IDE. This plugin is a wrapper that checks whether the user has the required Java version and launches the KTS language server.

About implementation of language server. Kotlin-language-server was used as a basis. My fixes and modifications are located here. The following work has been done:

How Language Server Works?

Each Kotlin build file has its own compilation environment to provide accurate diagnostics to the user. I decided to create a Map< File, Set<Path> > where the set of paths represents the classpath. This is necessary because if a user adds plugins, the classpath changes, and therefore the language server must update the compilation environment.

An important point to note is that the updating of the compilation environment happens when the user saves the file. In this scenario, the server checks two invariants to avoid unnecessary Tooling API (TAPI) calls:

The Tooling API is invoked on each project and includes compilation information about subprojects and included builds. The language server decides whether to make the call based on two criteria: 1) If a subproject has a parent or is the root, the language server makes a TAPI call on the root project. 2) if 1st statement is false, but the directory contains settings.gradle.kts then language server invokes TAPI on this subproject.

How are Errors Processed? If an error occurs during the initialization stage of the language server, the user receives a detailed description of the issue on each opened build file. Compilation doesn't proceed until the user fixes the errors and saves the files with problems. To obtain the most up-to-date and accurate diagnostics, the user must re-lint the file by either saving or editing it.

donat commented 1 year ago

Excellent contribution, thank you @D0zee for making this happen!