The Unified and Autonomous Development Platform
Display input hint of code assist
robin shine86bfda147186
diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.javaindex 1eab4c5a0f..fb061dc68a 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/CodeAssist.java@@ -82,19 +82,23 @@ public abstract class CodeAssist implements Serializable {*/Map<String, List<ElementCompletion>> grouped = new LinkedHashMap<>();for (ElementCompletion elementCompletion: suggest(rule, inputStatus, count)) {- /*- * key will be the new input (without considering mandatories of course), and we use- * this to group suggestions to facilitate mandatories calculation and exclusion- * logic- */- String key = inputContent.substring(0, elementCompletion.getReplaceBegin())- + elementCompletion.getReplaceContent() + inputContent.substring(elementCompletion.getReplaceEnd());- List<ElementCompletion> value = grouped.get(key);- if (value == null) {- value = new ArrayList<>();- grouped.put(key, value);+ if (elementCompletion.getReplaceContent().length() == 0) { // if this is input hint+ inputCompletions.add(new InputCompletion(elementCompletion));+ } else {+ /*+ * key will be the new input (without considering mandatories of course), and we use+ * this to group suggestions to facilitate mandatories calculation and exclusion+ * logic+ */+ String key = inputContent.substring(0, elementCompletion.getReplaceBegin())+ + elementCompletion.getReplaceContent() + inputContent.substring(elementCompletion.getReplaceEnd());+ List<ElementCompletion> value = grouped.get(key);+ if (value == null) {+ value = new ArrayList<>();+ grouped.put(key, value);+ }+ value.add(elementCompletion);}- value.add(elementCompletion);}for (Map.Entry<String, List<ElementCompletion>> entry: grouped.entrySet()) {@@ -183,11 +187,14 @@ public abstract class CodeAssist implements Serializable {*/Set<String> suggestedContents = Sets.newHashSet(inputStatus.getContent());for (Iterator<InputCompletion> it = inputCompletions.iterator(); it.hasNext();) {- String content = it.next().complete(inputStatus).getContent();- if (suggestedContents.contains(content))- it.remove();- else- suggestedContents.add(content);+ InputCompletion completion = it.next();+ if (completion.getReplaceContent().length() != 0) { // remove non-hint duplicate suggestions+ String content = completion.complete(inputStatus).getContent();+ if (suggestedContents.contains(content))+ it.remove();+ else+ suggestedContents.add(content);+ }}return inputCompletions;}@@ -286,7 +293,8 @@ public abstract class CodeAssist implements Serializable {inputSuggestions = suggest(element, matchWith, count);if (inputSuggestions != null) {for (Iterator<InputSuggestion> it = inputSuggestions.iterator(); it.hasNext();) {- if (it.next().getContent().equals(matchWith))+ InputSuggestion suggestion = it.next();+ if (suggestion.getContent().length() != 0 && suggestion.getContent().equals(matchWith))it.remove();}if (!inputSuggestions.isEmpty())diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputCompletion.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputCompletion.javaindex 4cdd26df03..00bd37834c 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputCompletion.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputCompletion.java@@ -30,6 +30,11 @@ public class InputCompletion implements Serializable {this.highlight = highlight;}+ public InputCompletion(InputCompletion completion) {+ this(completion.getReplaceBegin(), completion.getReplaceEnd(), completion.getReplaceContent(),+ completion.getCaret(), completion.getDescription(), completion.getHighlight());+ }+public int getReplaceBegin() {return replaceBegin;}diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputSuggestion.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputSuggestion.javaindex 9a7b84cd76..0883769c8b 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputSuggestion.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/InputSuggestion.java@@ -62,4 +62,8 @@ public class InputSuggestion extends InputStatus {return highlight;}+ public static InputSuggestion hint(String hint) {+ return new InputSuggestion("", -1, false, hint, null);+ }+}diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.javaindex 70d38394b8..a49a8d31f8 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java@@ -50,20 +50,24 @@ public abstract class SurroundingAware {boolean matchWithIncluded = false;for (InputSuggestion suggestion: suggestions) {String content = suggestion.getContent();- int caret = suggestion.getCaret();- if (!matches(spec, content)) {- content = prefix + content + suffix;- Highlight highlight = suggestion.getHighlight();- if (caret != -1)- caret += prefix.length();- if (highlight != null)- highlight = new Highlight(highlight.getFrom()+prefix.length(), highlight.getTo()+prefix.length());- checkedSuggestions.add(new InputSuggestion(content, caret, true, suggestion.getDescription(), highlight));+ if (content.length() != 0) { // process non-hint suggestions+ int caret = suggestion.getCaret();+ if (!matches(spec, content)) {+ content = prefix + content + suffix;+ Highlight highlight = suggestion.getHighlight();+ if (caret != -1)+ caret += prefix.length();+ if (highlight != null)+ highlight = new Highlight(highlight.getFrom()+prefix.length(), highlight.getTo()+prefix.length());+ checkedSuggestions.add(new InputSuggestion(content, caret, true, suggestion.getDescription(), highlight));+ } else {+ checkedSuggestions.add(suggestion);+ }+ if (suggestion.getContent().equals(matchWith))+ matchWithIncluded = true;} else {checkedSuggestions.add(suggestion);}- if (suggestion.getContent().equals(matchWith))- matchWithIncluded = true;}if (checkedSuggestions.isEmpty()) {diff --git a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.javaindex c17ab23dea..1493f755eb 100644--- a/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java+++ b/commons.antlr/src/test/java/com/pmease/commons/antlr/codeassist/test/CodeAssistTest2.java@@ -113,10 +113,9 @@ public class CodeAssistTest2 {assertEquals("branch(feature2):16", suggestions.get(3).toString());suggestions = suggest(new InputStatus("branch( fea"), "query");- assertEquals(3, suggestions.size());+ assertEquals(2, suggestions.size());assertEquals("branch(feature1):16", suggestions.get(0).toString());assertEquals("branch(feature2):16", suggestions.get(1).toString());- assertEquals("branch(fea):11", suggestions.get(2).toString());suggestions = suggest(new InputStatus("tag"), "query");assertEquals(1, suggestions.size());diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.htmlindex ee57ece2ca..5b45167282 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.html+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.html@@ -13,6 +13,7 @@</tr></table></div>+ <div wicket:id="contextHelps" class="context-help"></div><div class="help"></div></div></wicket:panel>\ No newline at end of filediff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.javaindex 0f68b5d7b6..a29e7b4f28 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/AssistPanel.java@@ -45,8 +45,14 @@ class AssistPanel extends Panel {suggestionsView = new RepeatingView("suggestions");add(suggestionsView);- for (InputCompletion suggestion: suggestions)- suggestionsView.add(newSuggestionItem(suggestionsView.newChildId(), suggestion));+ RepeatingView contextHelpsView = new RepeatingView("contextHelps");+ add(contextHelpsView);+ for (InputCompletion suggestion: suggestions) {+ if (suggestion.getReplaceContent().length() != 0)+ suggestionsView.add(newSuggestionItem(suggestionsView.newChildId(), suggestion));+ else if (suggestion.getDescription() != null)+ contextHelpsView.add(new Label(contextHelpsView.newChildId(), suggestion.getDescription()));+ }add(new AbstractDefaultAjaxBehavior() {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.javaindex 072574d984..6cdb434f62 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/InputAssistBehavior.java@@ -225,6 +225,10 @@ public abstract class InputAssistBehavior extends AbstractDefaultAjaxBehavior {}protected abstract List<InputCompletion> getSuggestions(InputStatus inputStatus, int count);++ protected String getHelp(InputStatus inputStatus) {+ return null;+ }protected abstract List<InputError> getErrors(String inputContent);diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.cssindex 44d63ceee4..7adc3cacda 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.css+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/inputassist/input-assist.css@@ -34,6 +34,12 @@background: #EEE;padding: 0 4px;}+.input-assist .context-help {+ margin-top: 8px;+ margin-bottom: -8px;+ background: #EEE;+ padding: 0 4px;+}.input-error-mark {position: absolute;background: url(wave.png) bottom repeat-x;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.javaindex 65ebb55390..33a513c5ba 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java@@ -7,6 +7,7 @@ import java.nio.file.Paths;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;+import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.List;@@ -325,7 +326,19 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryListList<Path> paths = new ArrayList<>();for (String file: (Set<String>)SerializationUtils.deserialize(bytes))paths.add(Paths.get(file));- Collections.sort(paths);+ Collections.sort(paths, new Comparator<Path>() {++ @Override+ public int compare(Path path1, Path path2) {+ int count1 = path1.getNameCount();+ int count2 = path2.getNameCount();+ if (count1 != count2)+ return count1 - count2;+ else+ return path1.compareTo(path2);+ }++ });List<String> files = new ArrayList<>();for (Path path: paths)files.add(path.toString().replace('\\', '/'));diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.javaindex c44eeb8d9b..a2b62fa8be 100644--- a/gitplex.product/src/test/java/gitplex/product/Test.java+++ b/gitplex.product/src/test/java/gitplex/product/Test.java@@ -1,24 +1,37 @@package gitplex.product;import java.io.IOException;+import java.nio.file.Path;+import java.nio.file.Paths;+import java.util.ArrayList;+import java.util.Collections;+import java.util.Comparator;import java.util.List;-import org.antlr.v4.runtime.Token;--import com.pmease.commons.antlr.grammar.Grammar;-import com.pmease.commons.antlr.grammar.RuleSpec;-import com.pmease.commons.antlr.parser.EarleyParser;-import com.pmease.commons.lang.extractors.java.JavaLexer;-public class Test {@org.junit.Testpublic void test() throws IOException {- Grammar grammar = new Grammar(JavaLexer.class);- List<Token> tokens = grammar.lex("1");- RuleSpec rule = grammar.getRule("compilationUnit");- EarleyParser parser = new EarleyParser(rule, tokens);- System.out.println(parser.matches());+ List<Path> paths = new ArrayList<>();+ paths.add(Paths.get("a/b"));+ paths.add(Paths.get("a/b/c"));+ paths.add(Paths.get("a/c"));+ paths.add(Paths.get("a/c/d"));+ Collections.sort(paths, new Comparator<Path>() {++ @Override+ public int compare(Path path1, Path path2) {+ int count1 = path1.getNameCount();+ int count2 = path2.getNameCount();+ if (count1 != count2)+ return count1 - count2;+ else+ return path1.compareTo(path2);+ }++ });+ for (Path path: paths)+ System.out.println(path);}}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/LogCommandDecorator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/LogCommandDecorator.javaindex ddac9dff77..a2c251d542 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/LogCommandDecorator.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/LogCommandDecorator.java@@ -5,6 +5,7 @@ import org.antlr.v4.runtime.BailErrorStrategy;import org.antlr.v4.runtime.CommonTokenStream;import org.antlr.v4.runtime.tree.ParseTreeProperty;import org.antlr.v4.runtime.tree.TerminalNode;+import org.apache.commons.lang3.StringUtils;import com.pmease.commons.git.command.LogCommand;import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.AfterContext;@@ -71,7 +72,9 @@ public class LogCommandDecorator extends CommitQueryBaseListener {@Overridepublic void exitAuthor(AuthorContext ctx) {- logCommand.authors().add(getValue(ctx.Value()));+ String value = getValue(ctx.Value());+ value = StringUtils.replace(value, "*", ".*");+ logCommand.authors().add(value);}@Overridediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.javaindex 87f0899d19..e1537171c5 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java@@ -1,8 +1,6 @@package com.pmease.gitplex.web.page.repository.commit;import java.util.ArrayList;-import java.util.Collections;-import java.util.Comparator;import java.util.LinkedHashSet;import java.util.List;import java.util.Set;@@ -54,28 +52,29 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {@Overrideprotected List<InputSuggestion> match(String matchWith) {- matchWith = matchWith.toLowerCase();+ String lowerCaseMatchWith = matchWith.toLowerCase();int numSuggestions = 0;List<InputSuggestion> suggestions = new ArrayList<>();int tokenType = element.getRoot().getLastMatchedToken().getType();if (tokenType == CommitQueryParser.BRANCH) {for (String value: repoModel.getObject().getBranches()) {- int index = value.toLowerCase().indexOf(matchWith);+ int index = value.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+matchWith.length());+ Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}} else if (tokenType == CommitQueryParser.TAG) {for (String value: repoModel.getObject().getTags()) {- int index = value.toLowerCase().indexOf(matchWith);+ int index = value.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+matchWith.length());+ Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}} else if (tokenType == CommitQueryParser.AUTHOR|| tokenType == CommitQueryParser.COMMITTER) {+ suggestions.add(InputSuggestion.hint("Use * to match any string"));Set<String> suggestedInputs = new LinkedHashSet<>();AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);List<NameAndEmail> contributors = auxiliaryManager.getContributors(repoModel.getObject());@@ -85,7 +84,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {content = contributor.getName() + " <" + contributor.getEmailAddress() + ">";elsecontent = contributor.getName();- String wildcarded = WildcardUtils.applyWildcard(content, matchWith, false);+ String wildcarded = WildcardUtils.applyWildcard(content, lowerCaseMatchWith, false);if (wildcarded != null) {suggestedInputs.add(wildcarded);if (suggestedInputs.size() == count)@@ -94,28 +93,26 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {}for (String suggestedInput: suggestedInputs) {- int index = suggestedInput.toLowerCase().indexOf(matchWith.toLowerCase());- Highlight highlight = new Highlight(index, index+matchWith.length());+ int index = suggestedInput.toLowerCase().indexOf(lowerCaseMatchWith.toLowerCase());+ Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());suggestions.add(new InputSuggestion(suggestedInput, -1, true, null, highlight));}} else if (tokenType == CommitQueryParser.BEFORE|| tokenType == CommitQueryParser.AFTER) {- if (!matchWith.endsWith(")")) {+ if (!lowerCaseMatchWith.endsWith(")")) {suggestions.add(new InputSuggestion(Constants.DATETIME_FORMATTER.print(System.currentTimeMillis())));suggestions.add(new InputSuggestion(Constants.DATE_FORMATTER.print(System.currentTimeMillis())));for (String dateExample: DATE_EXAMPLES)suggestions.add(new InputSuggestion(dateExample));}} else if (tokenType == CommitQueryParser.PATH) {- Set<String> suggestedInputSet = new LinkedHashSet<>();-- System.out.println("===============================");- long time = System.currentTimeMillis();+ suggestions.add(InputSuggestion.hint("Use * to match any string"));+ Set<String> suggestedInputs = new LinkedHashSet<>();AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);for (String path: auxiliaryManager.getFiles(repoModel.getObject())) {- String wildcarded = WildcardUtils.applyWildcard(path, matchWith, false);+ String wildcarded = WildcardUtils.applyWildcard(path, lowerCaseMatchWith, false);if (wildcarded != null) {- int matchEnd = wildcarded.toLowerCase().indexOf(matchWith) + matchWith.length();+ int matchEnd = wildcarded.toLowerCase().indexOf(lowerCaseMatchWith) + lowerCaseMatchWith.length();String suffix = wildcarded.substring(matchEnd);int index = suffix.indexOf('/');String suggestedInput = wildcarded.substring(0, matchEnd);@@ -123,36 +120,24 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {suggestedInput += suffix.substring(0, index) + "/";elsesuggestedInput += suffix;- suggestedInputSet.add(suggestedInput);+ suggestedInputs.add(suggestedInput);+ if (suggestedInputs.size() == count)+ break;}}- System.out.println(System.currentTimeMillis()-time);- List<String> suggestedInputList = new ArrayList<>(suggestedInputSet);- final String matchWithStr = matchWith;- Collections.sort(suggestedInputList, new Comparator<String>() {-- @Override- public int compare(String o1, String o2) {- return o1.toLowerCase().indexOf(matchWithStr) - o2.toLowerCase().indexOf(matchWithStr);- }-- });- System.out.println(System.currentTimeMillis()-time);-- for (String suggestedInput: suggestedInputList) {+ for (String suggestedInput: suggestedInputs) {int caret;if (suggestedInput.endsWith("/"))caret = suggestedInput.length();elsecaret = -1;- int index = suggestedInput.toLowerCase().indexOf(matchWith.toLowerCase());- Highlight highlight = new Highlight(index, index+matchWith.length());+ int index = suggestedInput.toLowerCase().indexOf(lowerCaseMatchWith.toLowerCase());+ Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());suggestions.add(new InputSuggestion(suggestedInput, caret, true, null, highlight));if (suggestions.size() == count)break;}- System.out.println(System.currentTimeMillis()-time);}return suggestions;}