fix: NPE (fixes #1046)

This commit is contained in:
Carl-Robert Linnupuu 2025-06-08 09:12:51 +01:00
parent 5aa120bdca
commit f6ccf201f4

View file

@ -2,6 +2,7 @@ package ee.carlrobert.codegpt.conversations;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.diagnostic.Logger;
import ee.carlrobert.codegpt.completions.ChatCompletionParameters;
import ee.carlrobert.codegpt.conversations.message.Message;
import ee.carlrobert.codegpt.settings.GeneralSettings;
@ -24,6 +25,8 @@ import org.jetbrains.annotations.NotNull;
@Service
public final class ConversationService {
private static final Logger LOG = Logger.getInstance(ConversationService.class);
private final ConversationsState conversationState = ConversationsState.getInstance();
private ConversationService() {
@ -111,7 +114,13 @@ public final class ConversationService {
}
public Conversation startConversation() {
var completionCode = GeneralSettings.getSelectedService().getCompletionCode();
var selectedService = GeneralSettings.getSelectedService();
if (selectedService == null) {
LOG.warn("Selected service is not defined, falling back to ProxyAI.");
selectedService = ServiceType.CODEGPT;
}
var completionCode = selectedService.getCompletionCode();
var conversation = createConversation(completionCode);
conversationState.setCurrentConversation(conversation);
addConversation(conversation);