-
Notifications
You must be signed in to change notification settings - Fork 69
#1392: Smart completions #1859
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
base: main
Are you sure you want to change the base?
#1392: Smart completions #1859
Changes from all commits
1ebcaf5
608c40c
2daba5d
dac795f
f63af46
682226c
bf984c1
0830786
6e66a96
7d9135a
6408e05
d827ecc
365c648
5ca5927
18d84a7
31c5fc3
d08b45d
001b5ee
b0197e8
be38f45
ecf7f18
d011275
d4ae88b
f16bb6b
dae126e
72d8f5c
10334bf
5f91447
2219994
ed31941
5dd62f7
5621a66
27e15f4
d7a52e6
10599c6
cf75b91
43b8e5c
7dda3a3
dbee248
4695542
a8981c7
4eef828
9ba614a
6b637b6
56bd7cd
d57804e
f34f667
06c8b9e
290dd95
cf4a7f7
54d8f39
bd8f495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,24 @@ | ||
| package com.devonfw.tools.ide.completion; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Candidate for auto-completion. | ||
| * | ||
| * @param text the text to suggest (CLI argument value). | ||
| * @param description the description of the candidate. | ||
| */ | ||
| public record CompletionCandidate(String text, String description) implements Comparable<CompletionCandidate> { | ||
| public record CompletionCandidate(List<String> entries, | ||
| String description, | ||
| boolean complete) implements Comparable<CompletionCandidate> { | ||
|
|
||
| @Override | ||
| public int compareTo(CompletionCandidate o) { | ||
|
|
||
| return this.text.compareTo(o.text); | ||
| return this.text().compareTo(o.text()); | ||
| } | ||
|
|
||
| public String text() { | ||
| return String.join(" ", this.entries); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,20 @@ | |
| */ | ||
| public interface CompletionCandidateCollector { | ||
|
|
||
| /** | ||
| * Directly add a {@link CompletionCandidate}. | ||
| * | ||
| * @param completion the {@link CompletionCandidate} to add | ||
| */ | ||
| void add(CompletionCandidate completion); | ||
|
|
||
| /** | ||
| * @param text the suggested word to add to auto-completion. | ||
| * @param description the description of the suggestion candidate or {@code null} to determine automatically form the given parameters. | ||
| * @param property the {@link Property} that triggered this suggestion. | ||
| * @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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO you were mislead by IntelliJ linting that is sometimes stupid. |
||
|
|
||
| /** | ||
| * @param text the suggested word to add to auto-completion. | ||
|
|
@@ -27,12 +34,13 @@ public interface CompletionCandidateCollector { | |
| * @param commandlet the {@link Commandlet} owning the {@link Property}. | ||
| * @return the {@link CompletionCandidate} for the given parameters. | ||
| */ | ||
| default CompletionCandidate createCandidate(String text, String description, Property<?> property, Commandlet commandlet) { | ||
|
|
||
| default CompletionCandidate createCandidate(String text, String description, boolean complete) { | ||
| if (description == null) { | ||
| // compute description from property + commandlet like in HelpCommandlet? | ||
| } | ||
| CompletionCandidate candidate = new CompletionCandidate(text, description); | ||
|
|
||
| CompletionCandidate candidate = new CompletionCandidate(Arrays.asList(text.split(" ")), | ||
| description, complete); | ||
| return candidate; | ||
| } | ||
|
|
||
|
|
@@ -47,7 +55,7 @@ default int addAllMatches(String text, String[] sortedCandidates, Property<?> pr | |
|
|
||
| if (text.isEmpty()) { | ||
| for (String candidate : sortedCandidates) { | ||
| add(candidate, "", property, commandlet); | ||
| add(candidate, ""); | ||
| } | ||
| return sortedCandidates.length; | ||
| } | ||
|
|
@@ -56,7 +64,7 @@ default int addAllMatches(String text, String[] sortedCandidates, Property<?> pr | |
| .collect(Collectors.toList()); | ||
|
|
||
| for (String match : prefixWords) { | ||
| add(match, "", property, commandlet); | ||
| add(match, ""); | ||
| } | ||
|
|
||
| return prefixWords.size(); | ||
|
|
||
There was a problem hiding this comment.
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
addKeywordmethod here:IDEasy/cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java
Lines 105 to 115 in 3f2de9e
This guarantees that our properties are ordered and
firstKeywordis also the first entry in ourpropertiesListthat is an instanceofKeywordProperty.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?