--- a/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Fri Feb 23 16:28:19 2018 +0000
+++ b/src/jdk.internal.le/share/classes/jdk/internal/jline/extra/EditingHistory.java Fri Feb 23 10:25:22 2018 -0800
@@ -367,11 +367,11 @@
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());
}
}
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java Fri Feb 23 16:28:19 2018 +0000
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java Fri Feb 23 10:25:22 2018 -0800
@@ -151,8 +151,8 @@
}
@Override
- public Iterable<String> currentSessionHistory() {
- return history.currentSessionEntries();
+ public Iterable<String> history(boolean currentSession) {
+ return history.entries(currentSession);
}
@Override
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java Fri Feb 23 16:28:19 2018 +0000
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java Fri Feb 23 10:25:22 2018 -0800
@@ -40,7 +40,7 @@
public abstract boolean interactiveOutput();
- public abstract Iterable<String> currentSessionHistory();
+ public abstract Iterable<String> history(boolean currentSession);
public abstract boolean terminalEditorRunning();
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Fri Feb 23 16:28:19 2018 +0000
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Fri Feb 23 10:25:22 2018 -0800
@@ -1457,6 +1457,7 @@
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 @@
};
}
+ // /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 @@
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 @@
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 @@
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 @@
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 @@
}
@Override
- public Iterable<String> currentSessionHistory() {
+ public Iterable<String> history(boolean currentSession) {
return Collections.emptyList();
}
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Fri Feb 23 16:28:19 2018 +0000
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Fri Feb 23 10:25:22 2018 -0800
@@ -454,9 +454,14 @@
/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]
--- a/test/langtools/jdk/jshell/CommandCompletionTest.java Fri Feb 23 16:28:19 2018 +0000
+++ b/test/langtools/jdk/jshell/CommandCompletionTest.java Fri Feb 23 10:25:22 2018 -0800
@@ -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
@@ -124,6 +124,14 @@
}
@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"},
a -> assertCompletion(a, "/d|", false, "/drop "),
--- a/test/langtools/jdk/jshell/ToolBasicTest.java Fri Feb 23 16:28:19 2018 +0000
+++ b/test/langtools/jdk/jshell/ToolBasicTest.java Fri Feb 23 10:25:22 2018 -0800
@@ -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
@@ -652,6 +652,10 @@
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"),
a -> assertCommand(a, "/-2", "System.err.println(1)", "", null, "", "1\n"),
@@ -661,6 +665,16 @@
"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"),