Skip to content

Autocompletion does not work correctly for arguments. #1346

@bagelben

Description

@bagelben

As Mentioned in my other issue I raised ( #1344 ), I am upgrading to Spring Shell 4.0.2 and Spring Boot 4.0.5. I am also using spring-shell-jline.

I have defined custom completion Resolvers for one of my commands in the following way:
Note - this is just one example, I have seen this behaviour on all commands I have tried

   @Bean(FLOW_CONTROL_LIST_COMPLETER)
    public CompletionProvider flowControlListCompleter() {
        return this::completeFlowControlList;
    }

    private List<CompletionProposal> completeFlowControlList(final CompletionContext context) {
        final int wordIndex = context.getWordIndex();

        LOGGER.info("Word Index [{}]", wordIndex);

        if (wordIndex < 0) {
            return Collections.emptyList();
        }

        if (wordIndex == 1) {
            return directions;
        } else if (wordIndex == 2) {
            if (context.getWords().contains(OUTBOUND.toString())) {
                return List.of(new CompletionProposal(VALUE_HERE));
            }
        }

        return Collections.emptyList();
    }

Previously this type of logic used to work as expected (as per #1344 we were using options in Spring Shell 3), however in Spring Shell 4.0.2 we observe slightly odd behaviour. If I type the command and hit tab, the autocomplete will work as expected and show me my desired set of options. However if I type any letters of the first word and try to tab to complete it, no autocomplete occurs, and I can see from my added logging that my method is not getting called in this case. In fact as soon as any text is added after the command name it seems to stop calling the completion resolver.

This seems to only occur if the arguments appear immediately after the command name. If the first value after the command name begins with a hyphen, the autocomplete seems to work as expected.

EDIT - unfortunately my image upload is not working so I can't share the screenshot of the command working as expected. however I will give a few examples of what is working and not

Given a command called command-line and an autocomplete containing INBOUND and OUTBOUND

command-line - Tab pressed now gives you the option of INBOUND and OUTBOUND to choose from
command-line IN - Tab pressed now does nothing, does not call registered completion resolver
command-line INBOUND - Tab pressed now does nothing, does not call registered completion resolver
command-line anytext - Tab pressed now does nothing, does not call registered completion resolver
command-line - - Tab pressed now actually gives you the option to override the hyphen to INBOUND or OUTBOUND
command-line -- - Tab pressed now gives you the option of INBOUND and OUTBOUND to choose from
command-line --some-option - Tab pressed now gives you the option of INBOUND and OUTBOUND to choose from
command-line --some-option INBOUND - Tab pressed now gives you the option of INBOUND and OUTBOUND to choose from
command-line - INBOUND INBOUND - Tab pressed now gives you the option of INBOUND and OUTBOUND to choose from

and so on. Basically it seems to depend on whether the argument immediately following the command name starts with a hyphen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageTeam needs to triage and take a first look

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions