Skip to content

Commit 07969b7

Browse files
jdneoCopilot
andcommitted
Address auto model review feedback
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 39119849-5c11-476e-941b-4c3574c369cf
1 parent 92410c1 commit 07969b7

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageClientTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.microsoft.copilot.eclipse.core.FeatureFlags;
4040
import com.microsoft.copilot.eclipse.core.chat.service.IChatServiceManager;
4141
import com.microsoft.copilot.eclipse.core.chat.service.IReferencedFileService;
42+
import com.microsoft.copilot.eclipse.core.events.CopilotEventConstants;
4243
import com.microsoft.copilot.eclipse.core.lsp.protocol.ConversationCapabilities;
4344
import com.microsoft.copilot.eclipse.core.lsp.protocol.ConversationContextParams;
4445
import com.microsoft.copilot.eclipse.core.lsp.protocol.CurrentEditorContext;
@@ -151,7 +152,6 @@ void testOnDidChangePolicy_publishesAutoModelPolicyEventOnlyWhenValueChanges() t
151152
.get(IEventBroker.class);
152153
assertNotNull(eventBroker);
153154

154-
String autoModelPolicyTopic = "com/microsoft/copilot/eclipse/POLICY/AUTO_MODEL_ENABLED";
155155
CountDownLatch eventReceived = new CountDownLatch(1);
156156
CountDownLatch duplicateEventReceived = new CountDownLatch(1);
157157
AtomicInteger eventCount = new AtomicInteger();
@@ -164,7 +164,7 @@ void testOnDidChangePolicy_publishesAutoModelPolicyEventOnlyWhenValueChanges() t
164164
duplicateEventReceived.countDown();
165165
}
166166
};
167-
eventBroker.subscribe(autoModelPolicyTopic, eventHandler);
167+
eventBroker.subscribe(CopilotEventConstants.TOPIC_DID_CHANGE_AUTO_MODEL_POLICY, eventHandler);
168168

169169
DidChangePolicyParams params = new Gson().fromJson("""
170170
{

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ private void validateAndSetActiveModelForMode(Map<String, CopilotModel> modelsFo
295295
&& modelsForCurrentMode.containsKey(currentActive.getModelKey());
296296
if (currentActive == null || !isCurrentModelAvailable) {
297297
// Try to restore user's preferred model if it's available in current mode
298-
String restoredModelId = restoreActiveModel();
299-
if (restoredModelId != null && modelsForCurrentMode.containsKey(restoredModelId)) {
300-
ensureRealm(() -> activeModelObservable.setValue(modelsForCurrentMode.get(restoredModelId)));
298+
String restoredModelKey = restoreActiveModel();
299+
if (restoredModelKey != null && modelsForCurrentMode.containsKey(restoredModelKey)) {
300+
ensureRealm(() -> activeModelObservable.setValue(modelsForCurrentMode.get(restoredModelKey)));
301301
return;
302302
}
303303
CopilotModel replacementModel = selectReplacementModel(modelsForCurrentMode);
@@ -359,20 +359,11 @@ private void onDidCopilotStatusChange(CopilotStatusResult copilotStatusResult) {
359359
public void setActiveModel(String modelName) {
360360
Map<String, CopilotModel> currentModels = modelObservable.getValue();
361361

362-
// Find model by model name and get its composite key
363-
String compositeKey = null;
364-
final CopilotModel model;
365-
CopilotModel foundModel = null;
366-
367-
for (Map.Entry<String, CopilotModel> entry : currentModels.entrySet()) {
368-
if (entry.getValue().getModelName().equals(modelName)) {
369-
compositeKey = entry.getKey();
370-
foundModel = entry.getValue();
371-
break;
372-
}
373-
}
374-
model = foundModel;
375-
if (model != null && compositeKey != null) {
362+
final CopilotModel model = currentModels.values().stream()
363+
.filter(candidateModel -> candidateModel.getModelName().equals(modelName))
364+
.findFirst()
365+
.orElse(null);
366+
if (model != null) {
376367
// Persist asynchronously to avoid deadlock: persistUserPreference() calls
377368
// persistence().get() which blocks waiting for the LSP listener thread.
378369
// If called on the UI thread while the listener is in syncExec, both threads

0 commit comments

Comments
 (0)