Skip to content

#1392: Smart completions#1859

Open
HenokLachmann wants to merge 52 commits into
devonfw:mainfrom
HenokLachmann:feature/#1392-smart-completions
Open

#1392: Smart completions#1859
HenokLachmann wants to merge 52 commits into
devonfw:mainfrom
HenokLachmann:feature/#1392-smart-completions

Conversation

@HenokLachmann
Copy link
Copy Markdown
Contributor

@HenokLachmann HenokLachmann commented Apr 27, 2026

This PR fixes #1392

Implemented changes:

Auto-completion is extended for the Mvn commandlet. It enables autocompletion for the ShellCommandlet as well as for bash. Completion is supported for the last word as well as intermittent words on a commandline. Completion covers the following:

  • Typical maven goals like clean, install, package
  • Boolean flags like --fail-fast
  • Definitions like -Dexec.mainClass=<classname>

Whitespace is excluded after a completed trailing = by differentiating partial from full completions. Merged short options are also supported as they are for present options.

Completion is based on Property instances, but properties are also used as stand-in replacements. Examples are the repository property for RepositoryCommandlet or the commandlet property for HelpCommandlet. These are not literal, they should not participate in autocompletion. A new boolean property placeholder is introduced to exclude them from completion.

A bug existed in the current implementation that would complete the exit subcommand infinitely. This is fixed by this PR by making exit an ordinary KeywordProperty and dynamically adding it when a shell session is started.


Checklist for this PR

Make sure everything is checked before merging this PR. For further info please also see
our DoD.

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary» (e.g. #921: fixed setup.bat). If no issue ID exists, title only.
  • PR top-level comment summarizes what has been done and contains link to addressed issue(s)
  • PR and issue(s) have suitable labels
  • Issue is set to In Progress and assigned to you or there is no issue (might happen for very small PRs)
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc unless issue is labeled
    with internal

@github-project-automation github-project-automation Bot moved this to 🆕 New in IDEasy board Apr 27, 2026
@HenokLachmann HenokLachmann self-assigned this Apr 27, 2026
@HenokLachmann HenokLachmann added completion auto-completion in bash or build in CLI shell build-in shell with advanced completion labels Apr 27, 2026
@HenokLachmann HenokLachmann force-pushed the feature/#1392-smart-completions branch from 499ecbe to d4ae88b Compare May 13, 2026 13:33
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented May 19, 2026

Coverage Report for CI Build 26101908636

Coverage increased (+0.003%) to 70.982%

Details

  • Coverage increased (+0.003%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 240 coverage regressions across 23 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

240 previously-covered lines in 23 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
com/devonfw/tools/ide/context/AbstractIdeContext.java 102 63.77%
com/devonfw/tools/ide/property/Property.java 28 71.9%
com/devonfw/tools/ide/tool/mvn/Mvn.java 19 83.84%
com/devonfw/tools/ide/property/PathProperty.java 16 11.27%
com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java 10 84.21%
com/devonfw/tools/ide/completion/CompletionCandidateCollectorAdapter.java 9 0.0%
com/devonfw/tools/ide/context/IdeContext.java 9 77.78%
com/devonfw/tools/ide/cli/CliArguments.java 8 69.64%
com/devonfw/tools/ide/cli/Ideasy.java 5 51.43%
com/devonfw/tools/ide/commandlet/Commandlet.java 5 85.71%

Coverage Stats

Coverage Status
Relevant Lines: 15567
Covered Lines: 11521
Line Coverage: 74.01%
Relevant Branches: 6964
Covered Branches: 4472
Branch Coverage: 64.22%
Branches in Coverage %: Yes
Coverage Strength: 3.14 hits per line

💛 - Coveralls

@HenokLachmann HenokLachmann marked this pull request as ready for review May 19, 2026 13:26
@tineff96 tineff96 moved this from 🆕 New to Team Review in IDEasy board May 20, 2026
Copy link
Copy Markdown
Contributor

@tineff96 tineff96 left a comment

Choose a reason for hiding this comment

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

Reviewed and tested.

  • mvn clean test passed
  • verified mvn CLI behavior and completion

The changes look solid and work as expected.

I’m still relatively new to the project, but everything seems correct from my side.

Looks good to me.

@tineff96 tineff96 moved this from Team Review to 👀 In review in IDEasy board May 22, 2026
Copy link
Copy Markdown
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

@HenokLachmann thanks for this PR and adding great improvements for auto-completion 👍
However, during the review I found several problems where we will need some rework and partially also change the design.
Since you are not available any more, I suggest we will discuss with the team in the next daily how to proceed so that someone else from the team can take over so we can bring this to a merge-able state.

* @param commandlet the {@link Commandlet} owning the {@link Property}.
*/
void add(String text, String description, Property<?> property, Commandlet commandlet);
void add(String text, String description);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO you were mislead by IntelliJ linting that is sometimes stupid.
Because the implementation of this method is (currently) not using these 2 arguments does not automatically mean that we should remove them.
This was designed for the feature in the ide shell where we can use these parameters to automatically derive the localised help texts and display them together with the auto-completion suggestions in the tailtip widget.
However, this story was never completed when @jan-vcapgemini left our team.

return this.multivalued;
}

public boolean isPlaceholder() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please add JavaDoc so we all know and understand what this means?
I can somehow conclude that this is for properties where the value can be autocompleted.

BTW: The better pattern to introduce such method is to better not add a field and a constructor argument.
If I am reading your change properly most sub-classes are not affected and never need the dynamic field.
Wouldn't it be better and easier to do the following instead:

/**
 * @return {@code true} if the property value is a placeholder that can be auto-completed.
 */
public boolean isPlaceholder() {
  return false;
}

Then you can override it in MvnArgProperty or other sublcasses typically like this:

@Override
public boolean isPlaceholder() {
  return true;
}

However, I am not yet convinced that we need this method at all.

Comment on lines +90 to +93
this.alsoMake = this.add(new FlagProperty("--also-make", false, "-am"));
this.alsoMakeDependents = this.add(new FlagProperty("--also-make-dependents", false, "-amd"));
this.failAtEnd = this.add(new FlagProperty("--fail-at-end", false, "-fae"));
this.failFast = this.add(new FlagProperty("--fail-fast", false, "-ff"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will not work. Our CLI parser is compatible with the POSIX standard.
Therefore -ftb is a short-cut for -f -t -b.
With this change the end-user will never be able to use these POSIX incompatible "short options" for maven any more or in other words:
Currently ide mvn -fae install is the same as mvn -fae install but after this change it will fail with with such error message what will totally confuse the end-user (since mvn -f -a -e install was actually called):

POM file -a specified with the -f/--file command line argument does not exist

Comment on lines +159 to +169
opt.--also-make=Build projects required by the list.
opt.--also-make-dependents=Build projects that depend on projects on the list.
opt.--batch=enable batch mode (non-interactive).
opt.--code=clone given code repository containing a settings folder into workspaces so that settings can be committed alongside code changes.
opt.--debug=enable debug logging.
opt.--define\ deployAtEnd=Deploy all artifacts at the end of the multi-module build.
opt.--define\ exec.args\==Arguments for the exec:java plugin.
opt.--define\ exec.mainClass\==Main class for the exec:java plugin.
opt.--define\ skipTests=Skip test compilation and execution.
opt.--fail-at-end=Only fail the build at the end; allow all non-impacted builds to continue.
opt.--fail-fast=Stop at first failure in reactorized builds.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO we should not start adding and maintaining all the options of all commandlets that we integrate.
This will open the door to hell.


// assert
assertThat(context).logAtDebug().hasMessage("Step 'ide' ended with failure.");
assertThat(context).logAtDebug().hasMessage("Step 'ide' ended successfully.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks correct to me:

$ cd /
$ ide --debug env
Running commandlet EnvironmentCommandlet[env]
...
Step 'ide' ended successfully.

But why it this related to #1392?

I ran the test on main and got

The environment variable IDE_ROOT is undefined. Please reinstall IDEasy or manually repair IDE_ROOT variable.
Step 'ide' ended with failure.

Funny, so it seems you actually fixed something that was rather odd on main.
I am still curious to find out what change in this PR changed the IDE_ROOT error to go away.

Comment on lines +107 to +121
protected void setFirstKeyword(String keyword, String alias) {
KeywordProperty property = new KeywordProperty(keyword, true, alias);

this.firstKeyword = property;
this.add(property);
}

/**
* Create a new keyword property without an alias and set it as the first keyword property.
*
* @param keyword the string to create the property from
*/
protected void setFirstKeyword(String keyword) {
this.setFirstKeyword(keyword, null);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we are setting the firstKeyword automatically and implicitly by addKeyword method here:

protected void addKeyword(String keyword, String alias) {
KeywordProperty property = new KeywordProperty(keyword, true, alias);
if (this.firstKeyword == null) {
if (!this.properties.isEmpty()) {
throw new IllegalStateException(property + " must be first property in " + getClass().getSimpleName());
}
this.firstKeyword = property;
}
add(property);
}

This guarantees that our properties are ordered and firstKeyword is also the first entry in our propertiesList that is an instanceof KeywordProperty.

When we use this method we are betraying that contract and IMHO cause a slightly inconsistent situation.
Isn't that odd and to be avoided?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

completion auto-completion in bash or build in CLI shell build-in shell with advanced completion

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Smart completion

4 participants