8166232: jshell tool: cannot access previous history
Reviewed-by: jlahoda
This commit is contained in:
parent
5ccc696fd2
commit
f23f23fc76
@ -367,11 +367,11 @@ public abstract class EditingHistory implements History {
|
||||
return count;
|
||||
}
|
||||
|
||||
public List<String> currentSessionEntries() {
|
||||
public List<String> entries(boolean currentSession) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
for (Entry e : fullHistory) {
|
||||
if (!(e.value() instanceof PersistentEntryMarker)) {
|
||||
if (!currentSession || !(e.value() instanceof PersistentEntryMarker)) {
|
||||
result.add(e.value().toString());
|
||||
}
|
||||
}
|
||||
|
@ -151,8 +151,8 @@ class ConsoleIOContext extends IOContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> currentSessionHistory() {
|
||||
return history.currentSessionEntries();
|
||||
public Iterable<String> history(boolean currentSession) {
|
||||
return history.entries(currentSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +40,7 @@ abstract class IOContext implements AutoCloseable {
|
||||
|
||||
public abstract boolean interactiveOutput();
|
||||
|
||||
public abstract Iterable<String> currentSessionHistory();
|
||||
public abstract Iterable<String> history(boolean currentSession);
|
||||
|
||||
public abstract boolean terminalEditorRunning();
|
||||
|
||||
|
@ -1457,6 +1457,7 @@ public class JShellTool implements MessageHandler {
|
||||
static final CompletionProvider EMPTY_COMPLETION_PROVIDER = new FixedCompletionProvider();
|
||||
private static final CompletionProvider SNIPPET_HISTORY_OPTION_COMPLETION_PROVIDER = new FixedCompletionProvider("-all", "-start ", "-history");
|
||||
private static final CompletionProvider SAVE_OPTION_COMPLETION_PROVIDER = new FixedCompletionProvider("-all ", "-start ", "-history ");
|
||||
private static final CompletionProvider HISTORY_OPTION_COMPLETION_PROVIDER = new FixedCompletionProvider("-all");
|
||||
private static final CompletionProvider SNIPPET_OPTION_COMPLETION_PROVIDER = new FixedCompletionProvider("-all", "-start " );
|
||||
private static final FixedCompletionProvider COMMAND_LINE_LIKE_OPTIONS_COMPLETION_PROVIDER = new FixedCompletionProvider(
|
||||
"-class-path ", "-module-path ", "-add-modules ", "-add-exports ");
|
||||
@ -1657,6 +1658,11 @@ public class JShellTool implements MessageHandler {
|
||||
};
|
||||
}
|
||||
|
||||
// /history command completion
|
||||
private static CompletionProvider historyCompletion() {
|
||||
return optionCompletion(HISTORY_OPTION_COMPLETION_PROVIDER);
|
||||
}
|
||||
|
||||
// /reload command completion
|
||||
private static CompletionProvider reloadCompletion() {
|
||||
return optionCompletion(RELOAD_OPTIONS_COMPLETION_PROVIDER);
|
||||
@ -1781,8 +1787,8 @@ public class JShellTool implements MessageHandler {
|
||||
this::cmdReload,
|
||||
reloadCompletion()));
|
||||
registerCommand(new Command("/history",
|
||||
arg -> cmdHistory(),
|
||||
EMPTY_COMPLETION_PROVIDER));
|
||||
this::cmdHistory,
|
||||
historyCompletion()));
|
||||
registerCommand(new Command("/debug",
|
||||
this::cmdDebug,
|
||||
EMPTY_COMPLETION_PROVIDER,
|
||||
@ -2423,9 +2429,14 @@ public class JShellTool implements MessageHandler {
|
||||
hardrb(key);
|
||||
}
|
||||
|
||||
private boolean cmdHistory() {
|
||||
private boolean cmdHistory(String rawArgs) {
|
||||
ArgTokenizer at = new ArgTokenizer("/history", rawArgs.trim());
|
||||
at.allowedOptions("-all");
|
||||
if (!checkOptionsAndRemainingInput(at)) {
|
||||
return false;
|
||||
}
|
||||
cmdout.println();
|
||||
for (String s : input.currentSessionHistory()) {
|
||||
for (String s : input.history(!at.hasOption("-all"))) {
|
||||
// No number prefix, confusing with snippet ids
|
||||
cmdout.printf("%s\n", s);
|
||||
}
|
||||
@ -2935,7 +2946,7 @@ public class JShellTool implements MessageHandler {
|
||||
|
||||
private boolean cmdList(String arg) {
|
||||
if (arg.length() >= 2 && "-history".startsWith(arg)) {
|
||||
return cmdHistory();
|
||||
return cmdHistory("");
|
||||
}
|
||||
Stream<Snippet> stream = argsOptionsToSnippets(state::snippets,
|
||||
this::mainActive, arg, "/list");
|
||||
@ -3183,7 +3194,7 @@ public class JShellTool implements MessageHandler {
|
||||
CREATE, TRUNCATE_EXISTING, WRITE)) {
|
||||
if (at.hasOption("-history")) {
|
||||
// they want history (commands and snippets), ignore the snippet stream
|
||||
for (String s : input.currentSessionHistory()) {
|
||||
for (String s : input.history(true)) {
|
||||
writer.write(s);
|
||||
writer.write("\n");
|
||||
}
|
||||
@ -3862,7 +3873,7 @@ abstract class NonInteractiveIOContext extends IOContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> currentSessionHistory() {
|
||||
public Iterable<String> history(boolean currentSession) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
@ -454,9 +454,14 @@ For example:\n\n\t\
|
||||
/env -add-modules com.greetings
|
||||
|
||||
help.history.summary = history of what you have typed
|
||||
help.history.args =
|
||||
help.history.args = [-all]
|
||||
help.history =\
|
||||
Display the history of snippet and command input since this jshell tool was launched.
|
||||
Display the history of snippet and command input.\n\
|
||||
\n\
|
||||
/history\n\t\
|
||||
List the history of snippet and command input since this jshell tool was launched\n\n\
|
||||
/history -all\n\t\
|
||||
List all the history of snippet and command input from this and previous sessions
|
||||
|
||||
help.debug.summary = toggle debugging of the jshell tool
|
||||
help.debug.args = [0][r][g][f][c][d][e]
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8144095 8164825 8169818 8153402 8165405 8177079 8178013 8167554
|
||||
* @bug 8144095 8164825 8169818 8153402 8165405 8177079 8178013 8167554 8166232
|
||||
* @summary Test Command Completion
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -123,6 +123,14 @@ public class CommandCompletionTest extends ReplToolTesting {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistory() {
|
||||
test(false, new String[] {"--no-startup"},
|
||||
a -> assertCompletion(a, "/hi|", false, "/history "),
|
||||
a -> assertCompletion(a, "/history |", false, "-all")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDrop() {
|
||||
test(false, new String[] {"--no-startup"},
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508
|
||||
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232
|
||||
* @summary Tests for Basic tests for REPL tool
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -651,6 +651,10 @@ public class ToolBasicTest extends ReplToolTesting {
|
||||
}
|
||||
|
||||
public void testHistoryReference() {
|
||||
test(false, new String[]{"--no-startup"},
|
||||
a -> assertCommand(a, "System.err.println(99)", "", "", null, "", "99\n"),
|
||||
a -> assertCommand(a, "/exit", "")
|
||||
);
|
||||
test(false, new String[]{"--no-startup"},
|
||||
a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"),
|
||||
a -> assertCommand(a, "System.err.println(2)", "", "", null, "", "2\n"),
|
||||
@ -661,6 +665,16 @@ public class ToolBasicTest extends ReplToolTesting {
|
||||
"System.err.println(2)\n" +
|
||||
"System.err.println(1)\n" +
|
||||
"/history\n"),
|
||||
a -> assertCommand(a, "/history -all",
|
||||
"/debug 0\n" +
|
||||
"System.err.println(99)\n" +
|
||||
"/exit\n" +
|
||||
"/debug 0\n" +
|
||||
"System.err.println(1)\n" +
|
||||
"System.err.println(2)\n" +
|
||||
"System.err.println(1)\n" +
|
||||
"/history\n" +
|
||||
"/history -all\n"),
|
||||
a -> assertCommand(a, "/-2", "System.err.println(2)", "", null, "", "2\n"),
|
||||
a -> assertCommand(a, "/!", "System.err.println(2)", "", null, "", "2\n"),
|
||||
a -> assertCommand(a, "/2", "System.err.println(2)", "", null, "", "2\n"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user