Skip to content

Commit 97dee5d

Browse files
authored
Merge pull request #485 from shivam71/fix-jshell-launch-windows
Launch JShell by creating jshell terminal directly
2 parents e067f22 + f98039c commit 97dee5d

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

vscode/src/commands/notebook.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,11 @@ const openJshellInContextOfProject = async (ctx: any) => {
130130
if (await isNbCommandRegistered(nbCommands.openJshellInProject)) {
131131
const additionalContext = window.activeTextEditor?.document.uri.toString();
132132
const res = await commands.executeCommand<openJshellNbResponse>(nbCommands.openJshellInProject, ctx?.toString(), additionalContext);
133-
const { envMap, finalArgs } = passArgsToTerminal(res.vmOptions);
134-
const jshellPath = res.jdkPath ? path.join(res.jdkPath, "bin", "jshell") : "jshell";
135-
// Direct sendText is not working since it truncates the command exceeding a certain length.
136-
// Open issues on vscode: 130688, 134324 and many more
137-
// So, workaround by setting env variables.
133+
const jshell = os.type() === 'Windows_NT' ? 'jshell.exe' : 'jshell';
134+
const jshellPath = res.jdkPath ? path.join(res.jdkPath, "bin", jshell) : "jshell";
138135
const terminal = window.createTerminal({
139-
name: "Jshell instance", env: envMap
136+
name: "Jshell instance", shellPath: jshellPath, shellArgs: res.vmOptions
140137
});
141-
terminal.sendText(`${jshellPath} ${finalArgs.join(' ')}`, true);
142138
terminal.show();
143139
} else {
144140
throw l10n.value("jdk.extension.error_msg.doesntSupportJShellExecution", { client: client?.name });
@@ -148,20 +144,6 @@ const openJshellInContextOfProject = async (ctx: any) => {
148144
LOGGER.error(`Error occurred while launching jshell in project context : ${isError(error) ? error.message : error}`);
149145
}
150146
}
151-
152-
const passArgsToTerminal = (args: string[]): { envMap: { [key: string]: string }, finalArgs: string[] } => {
153-
const envMap: { [key: string]: string } = {};
154-
const finalArgs = args.map((arg, index) => {
155-
if (arg.startsWith('-') || arg.startsWith('--')) {
156-
return arg;
157-
}
158-
const envName = `jshellArgsEnv${index}`;
159-
envMap[envName] = arg;
160-
return `$${envName}`;
161-
});
162-
return { envMap, finalArgs };
163-
}
164-
165147
const notebookChangeProjectContextHandler = async (ctx: INotebookToolbar) => {
166148
try {
167149
const uri: Uri = ctx.notebookEditor.notebookUri;

0 commit comments

Comments
 (0)