diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java index 8d152d4678a4c4d820d687f50849e7022f71efa0..9de6bab752d119a0da441dba3c4d201bab937afb 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java @@ -237,7 +237,11 @@ class ConsoleIOContext extends IOContext { .distinct() .count() == 2; boolean tooManyItems = suggestions.size() > in.getAutoprintThreshold(); - CompletionTask ordinaryCompletion = new OrdinaryCompletionTask(suggestions, anchor[0], !command && !doc.isEmpty(), hasSmart); + CompletionTask ordinaryCompletion = + new OrdinaryCompletionTask(suggestions, + anchor[0], + !command && !doc.isEmpty(), + hasBoth); CompletionTask allCompletion = new AllSuggestionsCompletionTask(suggestions, anchor[0]); todo = new ArrayList<>(); @@ -439,16 +443,16 @@ class ConsoleIOContext extends IOContext { private final List suggestions; private final int anchor; private final boolean cont; - private final boolean smart; + private final boolean showSmart; public OrdinaryCompletionTask(List suggestions, int anchor, boolean cont, - boolean smart) { + boolean showSmart) { this.suggestions = suggestions; this.anchor = anchor; this.cont = cont; - this.smart = smart; + this.showSmart = showSmart; } @Override @@ -460,7 +464,7 @@ class ConsoleIOContext extends IOContext { public Result perform(String text, int cursor) throws IOException { List toShow; - if (smart) { + if (showSmart) { toShow = suggestions.stream() .filter(Suggestion::matchesType) @@ -487,7 +491,7 @@ class ConsoleIOContext extends IOContext { String prefixStr = prefix.orElse("").substring(cursor - anchor); in.putString(prefixStr); - boolean showItems = toShow.size() > 1 || smart; + boolean showItems = toShow.size() > 1 || showSmart; if (showItems) { in.println(); @@ -495,7 +499,7 @@ class ConsoleIOContext extends IOContext { } if (!prefixStr.isEmpty()) - return showItems ? Result.SKIP : Result.SKIP_NOREPAINT; + return showItems ? Result.FINISH : Result.SKIP_NOREPAINT; return cont ? Result.CONTINUE : Result.FINISH; } diff --git a/test/langtools/jdk/jshell/ToolTabCommandTest.java b/test/langtools/jdk/jshell/ToolTabCommandTest.java index aea35c8fd959400bd66ae52cf2db5e2fb942509e..36caa77672f6831a7fc3622c98c271bab46793b2 100644 --- a/test/langtools/jdk/jshell/ToolTabCommandTest.java +++ b/test/langtools/jdk/jshell/ToolTabCommandTest.java @@ -84,10 +84,6 @@ public class ToolTabCommandTest extends UITesting { inputSink.write("\u0003/env \011"); waitOutput(out, "\u0005/env -\n" + "-add-exports -add-modules -class-path -module-path \n" + - "\r\u0005/env -"); - - inputSink.write("\011"); - waitOutput(out, "-add-exports -add-modules -class-path -module-path \n" + "\n" + Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n" + "\r\u0005/env -"); diff --git a/test/langtools/jdk/jshell/ToolTabSnippetTest.java b/test/langtools/jdk/jshell/ToolTabSnippetTest.java index be916b6b6db09e37fc925bf302fb151731907690..996d121705d35afd46f20b5351ab420a239e46a1 100644 --- a/test/langtools/jdk/jshell/ToolTabSnippetTest.java +++ b/test/langtools/jdk/jshell/ToolTabSnippetTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8177076 8185426 + * @bug 8177076 8185426 8189595 * @modules * jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main @@ -227,6 +227,31 @@ public class ToolTabSnippetTest extends UITesting { }); } + public void testNoRepeat() throws Exception { + doRunTest((inputSink, out) -> { + inputSink.write("String xyzAA;\n"); + waitOutput(out, "\u0005"); + + //xyz + inputSink.write("String s = xyz\011"); + waitOutput(out, "^String s = xyzAA"); + inputSink.write("."); + waitOutput(out, "^\\."); + + inputSink.write("\u0003"); + waitOutput(out, "\u0005"); + + inputSink.write("double xyzAB;\n"); + waitOutput(out, "\u0005"); + + //xyz + inputSink.write("String s = xyz\011"); + String allCompletions = + Pattern.quote(getResource("jshell.console.completion.all.completions")); + waitOutput(out, ".*xyzAA.*" + allCompletions + ".*\u0005String s = xyzA"); + }); + } + private Path prepareZip() { String clazz1 = "package jshelltest;\n" +