Support Type System in the language server
Currently the Gradle for Java extension provides basic support for Gradle script editing, which has room to improve. We can adopt the Groovy type system in the language server and provide more precise information for each location in the script.
Framework
There are two basic choices about framework.
- Just use Groovy API, which provides a Groovy complier, AST parser and others. The current solution in this extension is using the pure Groovy API to provide AST information of the given location. There is another example of Groovy language server using Groovy API directly, see https://github.com/GroovyLanguageServer/groovy-language-server
- advantage: tiny and clear
- disadvantage: We might implement the project/file/element management system ourselves (we already have a very simple one)
- Use groovy-eclipse framework. It patches both JDT and Groovy, provides a groovy compiler and transforms the result into JDT/eclipse style. If we continue this way, we will build a languages server more like eclipse.jdt.ls.(but a bit smaller)
- advantage: view Groovy elements from the Java perspective, we can also make use of GDT(JDT patch)
- disadvantage: we need to register a OSGI bundle (like other eclipse plugins)
Questions
Handling classpath of build script
Now we use Gradle API DefaultScriptHandler.getScriptClassPath() to get the classpaths of the build script. In the Groovy compile side, we use CompilerConfiguration.setClasspathList() to add these classpaths into the groovy compile configuration.
In this way, we just add the classpaths into a Gradle script, and regard it as a normal groovy script. Not sure if there is any gap in structure Gradle files (e.g, a Gradle file references a variable defined in another one)
Delegate mechanism
we now have a hard-coded delegate list, see https://github.com/microsoft/vscode-gradle/blob/develop/gradle-language-server/src/main/java/com/microsoft/gradle/delegate/GradleDelegate.java, and looking for a way to get delegating method in the runtime. So far I didn't find any API to get this information.
There is a related work item in the Gradle side: https://github.com/gradle/gradle/pull/20614, we might benefit from this.