Skip to content

Commit

Permalink
Set JAVA_HOME for LS and DA
Browse files Browse the repository at this point in the history
Fixes #97
  • Loading branch information
fwcd committed Apr 26, 2022
1 parent 59f09d0 commit 591771f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/debugSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ export async function registerDebugAdapter({ context, status, config, javaInstal
child_process.exec(`chmod +x ${startScriptPath}`);
}

vscode.debug.registerDebugAdapterDescriptorFactory("kotlin", new KotlinDebugAdapterDescriptorFactory(startScriptPath));
vscode.debug.registerDebugAdapterDescriptorFactory("kotlin", new KotlinDebugAdapterDescriptorFactory(startScriptPath, {
JAVA_HOME: javaInstallation.javaHome
}));
}

/**
* A factory that creates descriptors which point
* to the Kotlin debug adapter start script.
*/
export class KotlinDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
private startScriptPath: string;

public constructor(startScriptPath: string) {
this.startScriptPath = startScriptPath;
}
public constructor(
private startScriptPath: string,
private env?: any
) {}

async createDebugAdapterDescriptor(session: vscode.DebugSession, executable: vscode.DebugAdapterExecutable | undefined): Promise<vscode.DebugAdapterDescriptor> {
return new vscode.DebugAdapterExecutable(this.startScriptPath);
return new vscode.DebugAdapterExecutable(this.startScriptPath, null, {
env: this.env
});
}
}
8 changes: 4 additions & 4 deletions src/languageSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export async function activateLanguageServer({ context, status, config, javaInst

const transportLayer = config.get("languageServer.transport");
let tcpPort: number = null;
let env: any = undefined;
let env: any = {
JAVA_HOME: javaInstallation.javaHome
};

if (transportLayer == "tcp") {
tcpPort = config.get("languageServer.port");
Expand All @@ -50,9 +52,7 @@ export async function activateLanguageServer({ context, status, config, javaInst
if (config.get("languageServer.debugAttach.enabled")) {
const autoSuspend = config.get("languageServer.debugAttach.autoSuspend");
const attachPort = config.get("languageServer.debugAttach.port");
env = {
KOTLIN_LANGUAGE_SERVER_OPTS: `-Xdebug -agentlib:jdwp=transport=dt_socket,address=${attachPort},server=y,quiet=y,suspend=${autoSuspend ? "y" : "n"}`
};
env['KOTLIN_LANGUAGE_SERVER_OPTS'] = `-Xdebug -agentlib:jdwp=transport=dt_socket,address=${attachPort},server=y,quiet=y,suspend=${autoSuspend ? "y" : "n"}`;
}
} else {
LOG.info(`Unknown transport layer: ${transportLayer}`);
Expand Down

0 comments on commit 591771f

Please sign in to comment.