1427 private CompletionProvider helpCompletion() { |
1427 private CompletionProvider helpCompletion() { |
1428 return (code, cursor, anchor) -> { |
1428 return (code, cursor, anchor) -> { |
1429 List<Suggestion> result; |
1429 List<Suggestion> result; |
1430 int pastSpace = code.indexOf(' ') + 1; // zero if no space |
1430 int pastSpace = code.indexOf(' ') + 1; // zero if no space |
1431 if (pastSpace == 0) { |
1431 if (pastSpace == 0) { |
|
1432 // initially suggest commands (with slash) and subjects, |
|
1433 // however, if their subject starts without slash, include |
|
1434 // commands without slash |
|
1435 boolean noslash = code.length() > 0 && !code.startsWith("/"); |
1432 result = new FixedCompletionProvider(commands.values().stream() |
1436 result = new FixedCompletionProvider(commands.values().stream() |
1433 .filter(cmd -> cmd.kind.showInHelp || cmd.kind == CommandKind.HELP_SUBJECT) |
1437 .filter(cmd -> cmd.kind.showInHelp || cmd.kind == CommandKind.HELP_SUBJECT) |
1434 .map(c -> c.command + " ") |
1438 .map(c -> ((noslash && c.command.startsWith("/")) |
|
1439 ? c.command.substring(1) |
|
1440 : c.command) + " ") |
1435 .toArray(String[]::new)) |
1441 .toArray(String[]::new)) |
1436 .completionSuggestions(code, cursor, anchor); |
1442 .completionSuggestions(code, cursor, anchor); |
1437 } else if (code.startsWith("/se")) { |
1443 } else if (code.startsWith("/se")) { |
1438 result = new FixedCompletionProvider(SET_SUBCOMMANDS) |
1444 result = new FixedCompletionProvider(SET_SUBCOMMANDS) |
1439 .completionSuggestions(code.substring(pastSpace), cursor - pastSpace, anchor); |
1445 .completionSuggestions(code.substring(pastSpace), cursor - pastSpace, anchor); |
2085 |
2091 |
2086 boolean cmdHelp(String arg) { |
2092 boolean cmdHelp(String arg) { |
2087 ArgTokenizer at = new ArgTokenizer("/help", arg); |
2093 ArgTokenizer at = new ArgTokenizer("/help", arg); |
2088 String subject = at.next(); |
2094 String subject = at.next(); |
2089 if (subject != null) { |
2095 if (subject != null) { |
|
2096 // check if the requested subject is a help subject or |
|
2097 // a command, with or without slash |
2090 Command[] matches = commands.values().stream() |
2098 Command[] matches = commands.values().stream() |
2091 .filter(c -> c.command.startsWith(subject)) |
2099 .filter(c -> c.command.startsWith(subject) |
|
2100 || c.command.substring(1).startsWith(subject)) |
2092 .toArray(Command[]::new); |
2101 .toArray(Command[]::new); |
2093 if (matches.length == 1) { |
2102 if (matches.length == 1) { |
2094 String cmd = matches[0].command; |
2103 String cmd = matches[0].command; |
2095 if (cmd.equals("/set")) { |
2104 if (cmd.equals("/set")) { |
2096 // Print the help doc for the specified sub-command |
2105 // Print the help doc for the specified sub-command |
2111 hard(""); |
2120 hard(""); |
2112 hardrb(c.helpKey); |
2121 hardrb(c.helpKey); |
2113 } |
2122 } |
2114 return true; |
2123 return true; |
2115 } else { |
2124 } else { |
|
2125 // failing everything else, check if this is the start of |
|
2126 // a /set sub-command name |
|
2127 String[] subs = Arrays.stream(SET_SUBCOMMANDS) |
|
2128 .filter(s -> s.startsWith(subject)) |
|
2129 .toArray(String[]::new); |
|
2130 if (subs.length > 0) { |
|
2131 for (String sub : subs) { |
|
2132 hardrb("help.set." + sub); |
|
2133 hard(""); |
|
2134 } |
|
2135 return true; |
|
2136 } |
2116 errormsg("jshell.err.help.arg", arg); |
2137 errormsg("jshell.err.help.arg", arg); |
2117 } |
2138 } |
2118 } |
2139 } |
2119 hardmsg("jshell.msg.help.begin"); |
2140 hardmsg("jshell.msg.help.begin"); |
2120 hardPairs(commands.values().stream() |
2141 hardPairs(commands.values().stream() |