Skip to content

Commit 90620e8

Browse files
committed
fixed issue of command truncation
1 parent 33aaac4 commit 90620e8

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static boolean checkEmptyString(String input) {
108108

109109
@SuppressWarnings("unchecked")
110110
public static <T> T getArgument(List<Object> arguments, int index, Class<T> type) {
111-
if (arguments.size() > index && arguments.get(index) != null) {
111+
if (arguments != null && arguments.size() > index && arguments.get(index) != null) {
112112
Object arg = arguments.get(index);
113113

114114
if (arg instanceof JsonElement) {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.netbeans.api.project.FileOwnerQuery;
2525
import org.netbeans.api.project.Project;
2626
import org.netbeans.modules.java.lsp.server.Utils;
27+
import org.netbeans.modules.nbcode.java.notebook.NotebookUtils;
2728
import org.openide.filesystems.FileObject;
2829
import org.openide.util.Exceptions;
2930

@@ -39,16 +40,14 @@ public static CompletableFuture<List<String>> openJshellInProjectContext(List<Ob
3940
CompletableFuture<List<String>> future = new CompletableFuture<>();
4041

4142
LOG.log(Level.FINER, "Request received for opening Jshell instance with project context {0}", args);
42-
43-
final String uri = args != null && args.get(0) != null && args.get(0) instanceof JsonPrimitive
44-
? ((JsonPrimitive) args.get(0)).getAsString()
45-
: null;
4643

44+
String uri = NotebookUtils.getArgument(args, 0, String.class);
45+
4746
if (uri == null) {
4847
future.completeExceptionally(new IllegalArgumentException("uri is required. It cannot be null"));
4948
return future;
5049
}
51-
50+
5251
Project prj = getProject(uri);
5352
if (prj != null) {
5453
return ProjectConfigurationUtils.buildProject(prj)
@@ -71,19 +70,15 @@ public static CompletableFuture<List<String>> openJshellInProjectContext(List<Ob
7170
}
7271

7372
public static boolean openNotebookInProjectContext(List<Object> args) {
74-
LOG.log(Level.FINER, "Request received for opening Jshell instance with project context {0}", args);
73+
LOG.log(Level.FINER, "Request received for opening notebook with project context {0}", args);
7574

76-
String uri = null, notebookUri = null;
77-
if (args != null && !args.isEmpty() && args.get(0) != null && args.get(0) instanceof JsonPrimitive) {
78-
uri = ((JsonPrimitive) args.get(0)).getAsString();
79-
}
80-
if (args != null && args.size() > 1 && args.get(1) != null && args.get(1) instanceof JsonPrimitive) {
81-
notebookUri = ((JsonPrimitive) args.get(1)).getAsString();
82-
}
75+
String uri = NotebookUtils.getArgument(args, 0, String.class);
76+
String notebookUri = NotebookUtils.getArgument(args, 1, String.class);
77+
8378
Project prj = getProject(uri);
8479
if (prj != null) {
8580
List<String> remoteVmOptions = ProjectConfigurationUtils.launchVMOptions(prj);
86-
List<String> compileOptions = ProjectConfigurationUtils.compileOptions(prj);
81+
List<String> compileOptions = ProjectConfigurationUtils.compilerOptions(prj);
8782

8883
LOG.log(Level.INFO, "Opened Notebook instance with project context {0}", uri);
8984
return true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static List<String> launchVMOptions(Project project) {
142142
}
143143

144144
@NonNull
145-
public static List<String> compileOptions(Project project) {
145+
public static List<String> compilerOptions(Project project) {
146146
if (project == null) {
147147
return new ArrayList<>();
148148
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ public static List<String> getVmOptions(Project project) {
251251
));
252252

253253
vmOptions.addAll(getModuleConfigurations(project));
254-
255254
}
256255

257256
return vmOptions;

vscode/src/commands/notebook.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,15 @@ const openJshellInContextOfProject = async (ctx: any) => {
119119
let client: LanguageClient = await globalState.getClientPromise().client;
120120
if (await isNbCommandRegistered(nbCommands.openJshellInProject)) {
121121
const res: string[] = await commands.executeCommand(nbCommands.openJshellInProject, getContextUri(ctx)?.toString());
122-
123-
const args = res.join(" ");
124-
const terminal = window.createTerminal("Jshell instance");
122+
const { envMap, finalArgs } = passArgsToTerminal(res);
123+
// Direct sendText is not working since it truncates the command exceeding a certain length.
124+
// Open issues on vscode: 130688, 134324 and many more
125+
// So, workaround by setting env variables.
126+
const terminal = window.createTerminal({
127+
name: "Jshell instance", env: envMap
128+
});
129+
terminal.sendText(`jshell ${finalArgs.join(' ')}`, true);
125130
terminal.show();
126-
terminal.sendText(`jshell ${args}`, true);
127131
} else {
128132
throw l10n.value("jdk.extension.error_msg.doesntSupportGoToTest", { client });
129133
}
@@ -133,6 +137,18 @@ const openJshellInContextOfProject = async (ctx: any) => {
133137
}
134138
}
135139

140+
const passArgsToTerminal = (args: string[]): { envMap: { [key: string]: string }, finalArgs: string[] } => {
141+
const envMap: { [key: string]: string } = {};
142+
const finalArgs = args.map((arg, index) => {
143+
if (arg.startsWith('-') || arg.startsWith('--')) {
144+
return arg;
145+
}
146+
const envName = `jshellArgsEnv${index}`;
147+
envMap[envName] = arg;
148+
return `$${envName}`;
149+
});
150+
return { envMap, finalArgs };
151+
}
136152

137153
export const registerNotebookCommands: ICommand[] = [
138154
{

0 commit comments

Comments
 (0)