Skip to content

Commit

Permalink
feat: Added support for java.jdt.ls.java.home vs-code configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ravihara authored Feb 28, 2022
1 parent e326106 commit f295c0e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ build

# build plugin jar files
gradle-server/src/main/resources/*.jar

# Ignore user-specified .tool-versions file (asdf-vm configuration)
.tool-versions
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ We will continue improving the auto completion feature to support more cases in

</details>

## VS Code Settings
## Extension Settings

This extension contributes the following settings:

Expand Down Expand Up @@ -241,15 +241,18 @@ Use an environment manager like [direnv](https://direnv.net/) to set project spe

## Compatibility with the [Java language support](https://github.com/redhat-developer/vscode-java) extension

### VS Code Settings
### Java-Specific Settings

This extension supports the following settings which are contributed by the [Java language support](https://github.com/redhat-developer/vscode-java) extension:

- `java.home`: Absolute path to JDK home folder used to launch the Gradle daemons
- `java.home`: (**deprecated** Please use `java.jdt.ls.java.home` as given below) Absolute path to JDK home folder used to launch the Gradle daemons
- `java.jdt.ls.java.home`: Absolute path to JDK home folder as per the latest VS code, used to launch the Gradle daemons
- `java.import.gradle.java.home`: Absolute path to JDK home folder used to launch the Gradle daemons (if set, this value takes precedence over `java.home`)
- `java.import.gradle.user.home`: Setting for `GRADLE_USER_HOME`
- `java.import.gradle.jvmArguments`: JVM arguments to pass to Gradle
> Note: There should be a space ` ` between two arguments

>Note: There should be a `space` between two arguments
- `java.import.gradle.wrapper.enabled`: Enable/disable the Gradle wrapper
- `java.import.gradle.version`: Gradle version, used if the Gradle wrapper is missing or disabled
- `java.import.gradle.home`: Use Gradle from the specified local installation directory or GRADLE_HOME if the Gradle wrapper is missing or disabled and no 'java.import.gradle.version' is specified.
Expand Down
1 change: 1 addition & 0 deletions extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export class Extension {
vscode.workspace.onDidChangeConfiguration(async (event: vscode.ConfigurationChangeEvent) => {
if (
event.affectsConfiguration("java.home") ||
event.affectsConfiguration("java.jdt.ls.java.home") ||
event.affectsConfiguration("java.import.gradle.java.home")
) {
await this.restartServer();
Expand Down
7 changes: 5 additions & 2 deletions extension/src/languageServer/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ export async function startLanguageServer(
if (!javaHome) {
void vscode.window
.showErrorMessage(
'There is no valid JAVA_HOME setting to launch Gradle Language Server. Please check your "java.home" setting.',
'There is no valid JAVA_HOME setting to launch Gradle Language Server. Please check your "java.jdt.ls.java.home" setting.',
"Open Settings"
)
.then((answer) => {
if (answer === "Open Settings") {
void vscode.commands.executeCommand("workbench.action.openSettings", "java.home");
void vscode.commands.executeCommand(
"workbench.action.openSettings",
"java.jdt.ls.java.home"
);
}
});
return;
Expand Down
6 changes: 5 additions & 1 deletion extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ export function getConfigJavaHome(): string | null {
return vscode.workspace.getConfiguration("java").get<string | null>("home", null);
}

export function getJdtlsConfigJavaHome(): string | null {
return vscode.workspace.getConfiguration("java").get<string | null>("jdt.ls.java.home", null);
}

export function getConfigJavaImportGradleJavaHome(): string | null {
return vscode.workspace.getConfiguration("java").get<string | null>("import.gradle.java.home", null);
}

export function getConfigGradleJavaHome(): string | null {
return getConfigJavaImportGradleJavaHome() || getConfigJavaHome();
return getConfigJavaImportGradleJavaHome() || getJdtlsConfigJavaHome() || getConfigJavaHome();
}

export function getConfigJavaImportGradleUserHome(): string | null {
Expand Down
4 changes: 2 additions & 2 deletions gradle-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jar {
}

application {
mainClassName = 'com.github.badsyntax.gradle.GradleServer'
mainClass = 'com.github.badsyntax.gradle.GradleServer'
}

startScripts.enabled = false
Expand All @@ -108,7 +108,7 @@ task serverStartScripts(type: CreateStartScripts) {
dependsOn jar
dependsOn 'copyRuntimeLibs'
outputDir = file(libsDir)
mainClassName = 'com.github.badsyntax.gradle.GradleServer'
mainClass = 'com.github.badsyntax.gradle.GradleServer'
applicationName = project.name
classpath = jar.outputs.files
defaultJvmOpts = ["-Dfile.encoding=UTF-8"]
Expand Down

0 comments on commit f295c0e

Please sign in to comment.