Skip to content

Commit 028b0b3

Browse files
ethanyhouCopilot
andcommitted
refactor: optimize initialization of command, template, and agent lists
Co-authored-by: Copilot <copilot@github.com>
1 parent 92a9af8 commit 028b0b3

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatAssistProcessor.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
package com.microsoft.copilot.eclipse.ui.chat;
55

6+
import java.util.AbstractMap.SimpleEntry;
67
import java.util.ArrayList;
78
import java.util.Arrays;
89
import java.util.Comparator;
910
import java.util.List;
11+
import java.util.Map.Entry;
1012
import java.util.Objects;
1113

1214
import org.apache.commons.lang3.StringUtils;
@@ -123,28 +125,25 @@ public ICompletionProposal[] createCopilotCompletionTemplateProposals(String pre
123125
String lowerPrefix = prefix.toLowerCase();
124126

125127
// 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();
130131
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);
137136
}
138137

139138
/**
140139
* Returns a priority for how well the template matches the prefix (lower is better),
141140
* or -1 if it does not match at all.
142141
*
143142
* <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
148147
*/
149148
private int getMatchPriority(ConversationTemplate template, String lowerPrefix) {
150149
if (lowerPrefix.isEmpty()) {

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/ChatCompletionService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ private void syncCommands(String status) {
228228
fetchAsync();
229229
break;
230230
default:
231-
allCommands.clear();
232-
templates.clear();
233-
agents.clear();
231+
this.allCommands = new HashSet<>();
232+
this.templates = new ArrayList<>();
233+
this.agents = new ArrayList<>();
234234
break;
235235
}
236236
}

0 commit comments

Comments
 (0)