Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-4916] Unclear attribute name completion for LIST type #5415

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public Collection<String> getCandidates(ModelNode attrsDescr, boolean writeOnly)
candidateIndex += chunk.length();
}
candidates.add("[");
} else if (modelType.equals(ModelType.STRING) || modelType.equals(ModelType.INT) || modelType.equals(ModelType.BOOLEAN)){
if (candidates.isEmpty()) {
candidateIndex += chunk.length();
}
candidates.add("");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jboss.as.cli.parsing.StateParser.SubstitutedLine;
import org.jboss.logging.Logger;


/**
*
* @author Alexey Loubyansky
Expand Down Expand Up @@ -401,22 +400,24 @@ private int completeWithValueCompleter(CommandContext ctx, ParsedCommandLine par
// Implies a single candidate to inline, the value is complete.
// propose the property separator if more properties to come
// or the propertyListEnd if no more properties.
if (suggestionEqualsUserEntry(candidates, chunk, valueResult)) {
if (suggestionEqualsUserEntry(candidates, chunk, valueResult)|| areIncludedCandidatesForSpecificValueTypes(candidates)) {
final CommandLineFormat format = parsedCmd.getFormat();
if (format != null) {
for (CommandArgument arg : allArgs) {
try {
if (arg.canAppearNext(ctx)) {
candidates.set(0, "" + format.getPropertySeparator());
candidates.add("" + format.getPropertySeparator());
return buffer.length();
}
} catch (CommandFormatException e) {
return -1;
}
}
// inline the end of properties.
candidates.set(0, format.getPropertyListEnd());
// at the end of the input.
if((buffer.charAt(buffer.length() - 1))!='='){
candidates.add(format.getPropertyListEnd());
}
return buffer.length();
}
}
Expand Down Expand Up @@ -717,12 +718,26 @@ private boolean suggestionEqualsUserEntry(List<String> candidates, String chunk,
return false;
}

if (suggestionOffset > 0) {
if (suggestionOffset > 0 && candidates.get(0)!="") {
// user entry before suggestionOffset is always the same - compare only part after offset
return chunk.substring(suggestionOffset).equals(candidates.get(0));
} else {
return chunk.equals(candidates.get(0));
if(chunk.equals(candidates.get(0))){
candidates.clear();
return true;
}
return false;
}
}

boolean areIncludedCandidatesForSpecificValueTypes(List<String> candidates){
if(candidates.contains("[") || candidates.contains(".")){
return true;
}else if(candidates.contains("")){
candidates.remove("");
return true;
}
return false;
}

protected CommandLineCompleter getValueCompleter(CommandContext ctx, Iterable<CommandArgument> allArgs, final String argName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ protected List<CommandArgument> getPropertiesFromPropList(List<Property> propLis
if(ctx.getParsedCommandLine().getLastParsedPropertyValue() == null) {
radical = ctx.getParsedCommandLine().getLastParsedPropertyName();
//Check if the property is completely specified and is negated
if(ctx.getParsedCommandLine().isLastPropertyNegated()) {
if(ctx.getParsedCommandLine().isLastPropertyNegated() || radical!=null) {
for (Property prop : propList) {
if(radical.equals(prop.getName())){
radical = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void testMain() throws Exception {

candidates.clear();
i = completer.complete(null, "str", 0, candidates);
assertEquals(Arrays.asList("str2"), candidates);
assertEquals(Arrays.asList("", "str2"), candidates);
assertEquals(0, i);

candidates.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,10 +1140,12 @@ public void testCommandsCompletion2() throws Exception {
List<String> candidates = new ArrayList<>();
ctx.getDefaultCommandCompleter().complete(ctx, cmd,
cmd.length(), candidates);
assertTrue(candidates.toString(), candidates.size() == 1);
assertTrue(candidates.toString(), candidates.size() == 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristinaDsl , why do we have 2 elements there? We should have namespaces only.
For example if you type: read-attribute name, you should get read-attribute namespaces, I can see an added "" character that breaks this completion.

Copy link
Contributor Author

@ChristinaDsl ChristinaDsl Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise If you type read-attribute name, I thought that it would be right to have two choices:
Either you are allowed to leave it as it is "read-attribute name" or
End up in "read-attribute namespaces"
That is why I added empty space as another possible completion.
If there is no such a case I will erase it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristinaDsl , Thank-you, I see, I feel that we should keep the original behavior, this change would be outside the scope of the fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will fix it then, thank you too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise
With my existed modifications, after chunks which has Model Type:
list
string or
object
it is possible to add a property separator (if completed chunk concerns operation) or "" (if it is a command). Thus, because "name" lies to the case of a completed string and command, in the same time, an empty space is proposed. This new addition concerns the general case of proposing a comma or empty space after a completed string (which is right behavior) and if it's changed then the issue should be resolved in a completely other way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise You are right. management-minor-version such as management-micro-version and management-major-version in chunkDescr has ModelType "INT". My modifications apply to three types: List, Object and String(in this last type is "name" included). Would you like me to add INT too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristinaDsl , thank-you for the explaination. Did you limit to String in purpose? What would be the side effect to also applies it to INT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise I didn't limit it on purpose. Very few cases are on the INT type, while most of them are Strings. I was mainly testing it in Strings and that is why I did not take into consideration INT. I need to search it further in order to see if would be unwanted side effects in applying it to INT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise What do you believe I need to do next?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to apply to INT?

assertTrue(candidates.toString(), candidates.contains(" "));
assertTrue(candidates.toString(), candidates.contains("namespaces"));
candidates = complete(ctx, cmd, false, cmd.length() - "name".length());
assertTrue(candidates.toString(), candidates.size() == 1);
candidates = complete(ctx, cmd, false, cmd.length());
assertTrue(candidates.toString(), candidates.size() == 2);
assertTrue(candidates.toString(), candidates.contains(" "));
assertTrue(candidates.toString(), candidates.contains("namespaces"));
}

Expand All @@ -1157,6 +1159,17 @@ public void testCommandsCompletion2() throws Exception {
assertTrue(candidates.toString(), candidates.isEmpty());
}

{
String cmd = "read-attribute management-minor-version";
List<String> candidates = new ArrayList<>();
ctx.getDefaultCommandCompleter().complete(ctx, cmd,
cmd.length(), candidates);
assertTrue(candidates.toString(), candidates.size() == 1);
assertTrue(candidates.toString(), candidates.contains(" "));
candidates = complete(ctx, cmd, false, cmd.length());
assertTrue(candidates.toString(), candidates.contains(" "));
}

{
String cmd = "read-operation --node";
List<String> candidates = new ArrayList<>();
Expand Down