Skip to content

Commit 01d28ae

Browse files
committed
fixed jshell flow
1 parent a278597 commit 01d28ae

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

nbcode/notebooks/src/org/netbeans/modules/nbcode/java/project/CommandHandler.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ public class CommandHandler {
3535
public static CompletableFuture<List<String>> openJshellInProjectContext(List<Object> args) {
3636
LOG.log(Level.FINER, "Request received for opening Jshell instance with project context {0}", args);
3737

38-
String uri = NotebookUtils.getArgument(args, 0, String.class);
39-
40-
CompletableFuture<Project> prjFuture = uri == null ? ProjectContext.getProject()
41-
: CompletableFuture.completedFuture(ProjectContext.getProject(uri));
42-
38+
String context = NotebookUtils.getArgument(args, 0, String.class);
39+
String additionalContext = NotebookUtils.getArgument(args, 1, String.class);
40+
CompletableFuture<Project> prjFuture;
41+
42+
if (context != null) {
43+
prjFuture = CompletableFuture.completedFuture(ProjectContext.getProject(context));
44+
} else {
45+
Project editorPrj = additionalContext != null ? ProjectContext.getProject(additionalContext) : null;
46+
prjFuture = editorPrj != null
47+
? ProjectContext.getProject(false, new ProjectContextInfo(editorPrj))
48+
: ProjectContext.getProject();
49+
}
50+
4351
return prjFuture.thenCompose(prj -> {
4452
if (prj == null) {
4553
return CompletableFuture.completedFuture(new ArrayList<>());
@@ -48,7 +56,7 @@ public static CompletableFuture<List<String>> openJshellInProjectContext(List<Ob
4856
.thenCompose(isBuildSuccess -> {
4957
if (isBuildSuccess) {
5058
List<String> vmOptions = ProjectConfigurationUtils.launchVMOptions(prj);
51-
LOG.log(Level.INFO, "Opened Jshell instance with project context {0}", uri);
59+
LOG.log(Level.INFO, "Opened Jshell instance with project context {0}", context);
5260
return CompletableFuture.completedFuture(vmOptions);
5361
} else {
5462
CompletableFuture<List<String>> failed = new CompletableFuture<>();

vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@
603603
"command": "jdk.notebook.change.project",
604604
"title": "%jdk.notebook.change.project%",
605605
"category": "Java",
606-
"icon" : "$(pencil)"
606+
"icon": "$(pencil)"
607607
}
608608
],
609609
"keybindings": [

vscode/src/commands/notebook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ const openJshellInContextOfProject = async (ctx: any) => {
120120
try {
121121
let client: LanguageClient = await globalState.getClientPromise().client;
122122
if (await isNbCommandRegistered(nbCommands.openJshellInProject)) {
123-
const res: string[] = await commands.executeCommand(nbCommands.openJshellInProject, ctx?.toString());
123+
const additionalContext = window.activeTextEditor?.document.uri.toString();
124+
const res = await commands.executeCommand<string[]>(nbCommands.openJshellInProject, ctx?.toString(), additionalContext);
124125
const { envMap, finalArgs } = passArgsToTerminal(res);
125126
// Direct sendText is not working since it truncates the command exceeding a certain length.
126127
// Open issues on vscode: 130688, 134324 and many more

0 commit comments

Comments
 (0)