|
3 | 3 |
|
4 | 4 | package com.microsoft.copilot.eclipse.ui.chat; |
5 | 5 |
|
| 6 | +import java.util.AbstractMap.SimpleEntry; |
6 | 7 | import java.util.ArrayList; |
7 | 8 | import java.util.Arrays; |
8 | 9 | import java.util.Comparator; |
9 | 10 | import java.util.List; |
| 11 | +import java.util.Map.Entry; |
10 | 12 | import java.util.Objects; |
11 | 13 |
|
12 | 14 | import org.apache.commons.lang3.StringUtils; |
@@ -123,28 +125,25 @@ public ICompletionProposal[] createCopilotCompletionTemplateProposals(String pre |
123 | 125 | String lowerPrefix = prefix.toLowerCase(); |
124 | 126 |
|
125 | 127 | // Sort results by match quality, then build proposals. |
126 | | - return Arrays.stream(templates) |
127 | | - .filter(t -> getMatchPriority(t, lowerPrefix) >= 0) |
128 | | - .sorted(Comparator.comparingInt(t -> getMatchPriority(t, lowerPrefix))) |
129 | | - .map(t -> { |
| 128 | + return Arrays.stream(templates).map(t -> new SimpleEntry<>(t, getMatchPriority(t, lowerPrefix))) |
| 129 | + .filter(e -> e.getValue() >= 0).sorted(Comparator.comparingInt(Entry::getValue)).map(e -> { |
| 130 | + ConversationTemplate t = e.getKey(); |
130 | 131 | boolean isSkill = t.source() == TemplateSource.SKILL; |
131 | | - String displayName = isSkill && StringUtils.isNotBlank(t.shortDescription()) |
132 | | - ? t.shortDescription() : t.id(); |
133 | | - return (ICompletionProposal) new ChatCompletionProposal( |
134 | | - ChatCompletionService.TEMPLATE_MARK, t.id(), displayName, t.description()); |
135 | | - }) |
136 | | - .toArray(ICompletionProposal[]::new); |
| 132 | + String displayName = isSkill && StringUtils.isNotBlank(t.shortDescription()) ? t.shortDescription() : t.id(); |
| 133 | + return (ICompletionProposal) new ChatCompletionProposal(ChatCompletionService.TEMPLATE_MARK, t.id(), |
| 134 | + displayName, t.description()); |
| 135 | + }).toArray(ICompletionProposal[]::new); |
137 | 136 | } |
138 | 137 |
|
139 | 138 | /** |
140 | 139 | * Returns a priority for how well the template matches the prefix (lower is better), |
141 | 140 | * or -1 if it does not match at all. |
142 | 141 | * |
143 | 142 | * <p>Priority buckets: |
144 | | - * 0 – id starts with prefix (or prefix is empty) |
145 | | - * 1 – id contains prefix (or skill shortDescription contains prefix) |
146 | | - * 2 – description starts with prefix |
147 | | - * 3 – description contains prefix |
| 143 | + * 0 – id starts with prefix (or prefix is empty) |
| 144 | + * 1 – id contains prefix (or skill shortDescription contains prefix) |
| 145 | + * 2 – description starts with prefix |
| 146 | + * 3 – description contains prefix |
148 | 147 | */ |
149 | 148 | private int getMatchPriority(ConversationTemplate template, String lowerPrefix) { |
150 | 149 | if (lowerPrefix.isEmpty()) { |
|
0 commit comments