mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 14:10:29 +00:00
Remove Quartz Scheduler, You.com model change topic, theme utils, and include other basic refactoring
This commit is contained in:
parent
73870cca40
commit
53bdbcd4f5
57 changed files with 385 additions and 507 deletions
|
|
@ -3,79 +3,29 @@ package ee.carlrobert.codegpt;
|
|||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil;
|
||||
import ee.carlrobert.codegpt.completions.CompletionLookupService;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.AuthenticationHandler;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.SessionVerificationJob;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationError;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationService;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
import ee.carlrobert.codegpt.credentials.YouCredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.SimpleScheduleBuilder;
|
||||
import org.quartz.TriggerBuilder;
|
||||
import org.quartz.impl.StdSchedulerFactory;
|
||||
|
||||
public class PluginStartupActivity implements StartupActivity {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(PluginStartupActivity.class);
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Override
|
||||
public void runActivity(@NotNull Project project) {
|
||||
project.getService(CompletionLookupService.class).subscribeToLookupTopic();
|
||||
EditorActionsUtil.refreshActions();
|
||||
|
||||
var authenticationResponse = YouUserManager.getInstance().getAuthenticationResponse();
|
||||
if (authenticationResponse == null) {
|
||||
handleYouServiceAuthentication();
|
||||
} else {
|
||||
startSessionVerificationJob();
|
||||
}
|
||||
|
||||
ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {
|
||||
@Override
|
||||
public void projectClosing(@NotNull Project project) {
|
||||
if (scheduler != null) {
|
||||
try {
|
||||
scheduler.shutdown();
|
||||
} catch (SchedulerException e) {
|
||||
LOG.error("Could not shut down scheduler.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startSessionVerificationJob() {
|
||||
try {
|
||||
scheduler = StdSchedulerFactory.getDefaultScheduler();
|
||||
scheduler.start();
|
||||
|
||||
var job = JobBuilder.newJob(SessionVerificationJob.class)
|
||||
.withIdentity("authenticationVerifierJob", "authenticationVerifier")
|
||||
.build();
|
||||
var trigger = TriggerBuilder.newTrigger()
|
||||
.forJob(job)
|
||||
.withIdentity("authenticationVerifierTrigger", "authenticationVerifier")
|
||||
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
|
||||
.withIntervalInMinutes(30)
|
||||
.repeatForever())
|
||||
.startNow()
|
||||
.build();
|
||||
|
||||
scheduler.scheduleJob(job, trigger);
|
||||
} catch (SchedulerException e) {
|
||||
LOG.error("Couldn't start authentication verifier job", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,22 +41,21 @@ public class PluginStartupActivity implements StartupActivity {
|
|||
.signInAsync(settings.getEmail(), password, new AuthenticationHandler() {
|
||||
@Override
|
||||
public void handleAuthenticated(YouAuthenticationResponse authenticationResponse) {
|
||||
OverlayUtils.showNotification(
|
||||
OverlayUtil.showNotification(
|
||||
"Authentication successful.",
|
||||
NotificationType.INFORMATION);
|
||||
startSessionVerificationJob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleGenericError() {
|
||||
OverlayUtils.showNotification(
|
||||
OverlayUtil.showNotification(
|
||||
"Something went wrong while trying to authenticate.",
|
||||
NotificationType.ERROR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(YouAuthenticationError youAuthenticationError) {
|
||||
OverlayUtils.showNotification(
|
||||
OverlayUtil.showNotification(
|
||||
youAuthenticationError.getErrorMessage(),
|
||||
NotificationType.ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ee.carlrobert.codegpt.actions;
|
|||
|
||||
import static com.intellij.openapi.ui.Messages.OK;
|
||||
import static com.intellij.util.ObjectUtils.tryCast;
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtils.getResourceContent;
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtil.getResourceContent;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
|
|
@ -24,7 +24,7 @@ import ee.carlrobert.codegpt.Icons;
|
|||
import ee.carlrobert.codegpt.completions.CompletionClientProvider;
|
||||
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.state.OpenAISettingsState;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.llm.client.openai.completion.ErrorDetails;
|
||||
import ee.carlrobert.llm.client.openai.completion.chat.request.OpenAIChatCompletionMessage;
|
||||
import ee.carlrobert.llm.client.openai.completion.chat.request.OpenAIChatCompletionRequest;
|
||||
|
|
@ -66,7 +66,7 @@ public class GenerateGitCommitMessageAction extends AnAction {
|
|||
|
||||
var gitDiff = getGitDiff(project);
|
||||
var tokenCount = encodingManager.countTokens(gitDiff);
|
||||
if (tokenCount > 4096 && OverlayUtils.showTokenSoftLimitWarningDialog(tokenCount) != OK) {
|
||||
if (tokenCount > 4096 && OverlayUtil.showTokenSoftLimitWarningDialog(tokenCount) != OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ import com.intellij.util.ui.JBUI;
|
|||
import com.intellij.util.ui.UI;
|
||||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowContentManager;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
|
@ -32,7 +34,7 @@ class CustomPromptAction extends BaseEditorAction {
|
|||
protected void actionPerformed(Project project, Editor editor, String selectedText) {
|
||||
if (selectedText != null && !selectedText.isEmpty()) {
|
||||
var fileExtension =
|
||||
FileUtils.getFileExtension(((EditorImpl) editor).getVirtualFile().getName());
|
||||
FileUtil.getFileExtension(((EditorImpl) editor).getVirtualFile().getName());
|
||||
var dialog = new CustomPromptDialog(previousUserPrompt);
|
||||
if (dialog.showAndGet()) {
|
||||
previousUserPrompt = dialog.getUserPrompt();
|
||||
|
|
@ -69,7 +71,12 @@ class CustomPromptAction extends BaseEditorAction {
|
|||
userPromptTextArea.setLineWrap(true);
|
||||
userPromptTextArea.setWrapStyleWord(true);
|
||||
userPromptTextArea.setMargin(JBUI.insets(5));
|
||||
SwingUtils.addShiftEnterInputMap(userPromptTextArea, this::clickDefaultButton);
|
||||
UIUtil.addShiftEnterInputMap(userPromptTextArea, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
clickDefaultButton();
|
||||
}
|
||||
});
|
||||
|
||||
return FormBuilder.createFormBuilder()
|
||||
.addComponent(UI.PanelFactory.panel(userPromptTextArea)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.intellij.openapi.project.Project;
|
|||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowContentManager;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.text.CaseUtils;
|
||||
|
|
@ -55,7 +55,7 @@ public class EditorActionsUtil {
|
|||
var action = new BaseEditorAction(label, label) {
|
||||
@Override
|
||||
protected void actionPerformed(Project project, Editor editor, String selectedText) {
|
||||
var fileExtension = FileUtils.getFileExtension(
|
||||
var fileExtension = FileUtil.getFileExtension(
|
||||
((EditorImpl) editor).getVirtualFile().getName());
|
||||
var message = new Message(prompt.replace(
|
||||
"{{selectedCode}}",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import ee.carlrobert.codegpt.actions.ActionType;
|
|||
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil;
|
||||
import ee.carlrobert.codegpt.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DeleteConversationAction extends AnAction {
|
||||
|
|
@ -28,7 +28,7 @@ public class DeleteConversationAction extends AnAction {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent event) {
|
||||
if (OverlayUtils.showDeleteConversationDialog() == Messages.YES) {
|
||||
if (OverlayUtil.showDeleteConversationDialog() == Messages.YES) {
|
||||
var project = event.getProject();
|
||||
if (project != null) {
|
||||
TelemetryAction.IDE_ACTION.createActionMessage()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.intellij.openapi.actionSystem.AnAction;
|
|||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ReplaceCodeInMainEditorAction extends AnAction {
|
||||
|
|
@ -20,8 +20,8 @@ public class ReplaceCodeInMainEditorAction extends AnAction {
|
|||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
event.getPresentation().setEnabled(
|
||||
EditorUtils.isMainEditorTextSelected(requireNonNull(event.getProject()))
|
||||
&& EditorUtils.hasSelection(event.getData(PlatformDataKeys.EDITOR)));
|
||||
EditorUtil.isMainEditorTextSelected(requireNonNull(event.getProject()))
|
||||
&& EditorUtil.hasSelection(event.getData(PlatformDataKeys.EDITOR)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -29,7 +29,7 @@ public class ReplaceCodeInMainEditorAction extends AnAction {
|
|||
var project = event.getProject();
|
||||
var toolWindowEditor = event.getData(PlatformDataKeys.EDITOR);
|
||||
if (project != null && toolWindowEditor != null) {
|
||||
EditorUtils.replaceMainEditorSelection(
|
||||
EditorUtil.replaceMainEditorSelection(
|
||||
project,
|
||||
requireNonNull(toolWindowEditor.getSelectionModel().getSelectedText()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions;
|
||||
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.lookup.LookupManagerListener;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
public final class CompletionLookupService {
|
||||
|
||||
private final Project project;
|
||||
|
||||
private CompletionLookupService(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public void subscribeToLookupTopic() {
|
||||
project.getMessageBus()
|
||||
.connect()
|
||||
.subscribe(LookupManagerListener.TOPIC, getLookupManagerListener());
|
||||
}
|
||||
|
||||
private @Nullable String getCompletionResponse(String prompt) {
|
||||
var selectedService = SettingsState.getInstance().getSelectedService();
|
||||
switch (selectedService) {
|
||||
case OPENAI:
|
||||
case AZURE:
|
||||
return Optional.ofNullable(CompletionClientProvider.getOpenAIClient()
|
||||
.getChatCompletion(
|
||||
CompletionRequestProvider.buildOpenAILookupCompletionRequest(prompt))
|
||||
.getChoices())
|
||||
.map(choices -> choices.get(0).getMessage().getContent())
|
||||
.orElse(null);
|
||||
// TODO
|
||||
/*case LLAMA_CPP:
|
||||
var request = CompletionRequestProvider.buildLlamaLookupCompletionRequest(prompt);
|
||||
return CompletionClientProvider.getLlamaClient()
|
||||
.getChatCompletion(request)
|
||||
.getContent();*/
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addCompletionLookupValues(
|
||||
LookupImpl lookup,
|
||||
Application application,
|
||||
String prompt) {
|
||||
Optional.ofNullable(getCompletionResponse(prompt))
|
||||
.ifPresent(response -> {
|
||||
for (var value : response.split(",")) {
|
||||
application.runReadAction(() -> {
|
||||
lookup.addItem(
|
||||
LookupElementBuilder.create(value.trim()).withIcon(Icons.SparkleIcon),
|
||||
PrefixMatcher.ALWAYS_TRUE);
|
||||
});
|
||||
application.invokeLater(() -> lookup.refreshUi(true, true));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private LookupManagerListener getLookupManagerListener() {
|
||||
var application = ApplicationManager.getApplication();
|
||||
var configuration = ConfigurationState.getInstance();
|
||||
var credentialsManager = OpenAICredentialsManager.getInstance();
|
||||
return (oldLookup, newLookup) -> {
|
||||
if (!configuration.isMethodNameGenerationEnabled()
|
||||
|| !credentialsManager.isApiKeySet()
|
||||
|| !(newLookup instanceof LookupImpl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lookup = (LookupImpl) newLookup;
|
||||
Optional.ofNullable(lookup.getPsiElement())
|
||||
.map(PsiElement::getContext)
|
||||
.ifPresent(context ->
|
||||
application.runReadAction(() -> {
|
||||
var type = PsiUtilCore.getElementType(context);
|
||||
if ("METHOD".equals(type.toString())) {
|
||||
var selection = context.getText();
|
||||
application.executeOnPooledThread(
|
||||
() -> addCompletionLookupValues(lookup, application, selection));
|
||||
}
|
||||
}));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.completions;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtils.getResourceContent;
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtil.getResourceContent;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
package ee.carlrobert.codegpt.completions;
|
||||
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.AZURE;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
|
||||
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.lookup.LookupManagerListener;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MethodNameLookupListener implements LookupManagerListener {
|
||||
|
||||
@Override
|
||||
public void activeLookupChanged(@Nullable Lookup oldLookup, @Nullable Lookup newLookup) {
|
||||
var application = ApplicationManager.getApplication();
|
||||
var configuration = ConfigurationState.getInstance();
|
||||
var credentialsManager = OpenAICredentialsManager.getInstance();
|
||||
|
||||
if (!configuration.isMethodRefactoringEnabled()
|
||||
|| !credentialsManager.isApiKeySet()
|
||||
|| !(newLookup instanceof LookupImpl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lookup = (LookupImpl) newLookup;
|
||||
Optional.ofNullable(lookup.getPsiElement())
|
||||
.map(PsiElement::getContext)
|
||||
.ifPresent(context ->
|
||||
application.runReadAction(() -> {
|
||||
var type = PsiUtilCore.getElementType(context);
|
||||
if ("METHOD".equals(type.toString())) {
|
||||
var selection = context.getText();
|
||||
application.executeOnPooledThread(() ->
|
||||
addCompletionLookupValues(lookup, application, selection));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addCompletionLookupValues(
|
||||
LookupImpl lookup,
|
||||
Application application,
|
||||
String prompt) {
|
||||
Optional.ofNullable(getCompletionResponse(prompt))
|
||||
.ifPresent(response -> {
|
||||
for (var value : response.split(",")) {
|
||||
application.runReadAction(() -> {
|
||||
lookup.addItem(
|
||||
LookupElementBuilder.create(value.trim()).withIcon(Icons.SparkleIcon),
|
||||
PrefixMatcher.ALWAYS_TRUE);
|
||||
});
|
||||
application.invokeLater(() -> lookup.refreshUi(true, true));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private @Nullable String getCompletionResponse(String prompt) {
|
||||
var selectedService = SettingsState.getInstance().getSelectedService();
|
||||
if (selectedService == OPENAI || selectedService == AZURE) {
|
||||
return Optional.ofNullable(CompletionClientProvider.getOpenAIClient()
|
||||
.getChatCompletion(
|
||||
CompletionRequestProvider.buildOpenAILookupCompletionRequest(prompt))
|
||||
.getChoices())
|
||||
.map(choices -> choices.get(0).getMessage().getContent())
|
||||
.orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
|||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import ee.carlrobert.codegpt.CodeGPTPlugin;
|
||||
import ee.carlrobert.codegpt.settings.service.LlamaServiceSelectionForm;
|
||||
import ee.carlrobert.codegpt.settings.service.ServerProgressPanel;
|
||||
import ee.carlrobert.codegpt.settings.state.LlamaSettingsState;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -32,10 +33,7 @@ public final class LlamaServerAgent implements Disposable {
|
|||
private static @Nullable OSProcessHandler startServerProcessHandler;
|
||||
|
||||
public void startAgent(
|
||||
String modelPath,
|
||||
int contextLength,
|
||||
int threads,
|
||||
int port,
|
||||
LlamaServiceSelectionForm llamaServiceSelectionForm,
|
||||
ServerProgressPanel serverProgressPanel,
|
||||
Runnable onSuccess) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
|
|
@ -43,13 +41,7 @@ public final class LlamaServerAgent implements Disposable {
|
|||
serverProgressPanel.updateText("Building llama.cpp...");
|
||||
makeProcessHandler = new OSProcessHandler(getMakeCommandLinde());
|
||||
makeProcessHandler.addProcessListener(
|
||||
getMakeProcessListener(
|
||||
modelPath,
|
||||
contextLength,
|
||||
threads,
|
||||
port,
|
||||
serverProgressPanel,
|
||||
onSuccess));
|
||||
getMakeProcessListener(llamaServiceSelectionForm, serverProgressPanel, onSuccess));
|
||||
makeProcessHandler.startNotify();
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -70,10 +62,7 @@ public final class LlamaServerAgent implements Disposable {
|
|||
}
|
||||
|
||||
private ProcessListener getMakeProcessListener(
|
||||
String modelPath,
|
||||
int contextLength,
|
||||
int threads,
|
||||
int port,
|
||||
LlamaServiceSelectionForm serviceSelectionForm,
|
||||
ServerProgressPanel serverProgressPanel,
|
||||
Runnable onSuccess) {
|
||||
return new ProcessAdapter() {
|
||||
|
|
@ -87,9 +76,15 @@ public final class LlamaServerAgent implements Disposable {
|
|||
try {
|
||||
serverProgressPanel.updateText("Booting up server...");
|
||||
startServerProcessHandler = new OSProcessHandler(
|
||||
getServerCommandLine(modelPath, contextLength, threads, port));
|
||||
startServerProcessHandler.addProcessListener(
|
||||
getProcessListener(port, serverProgressPanel, onSuccess));
|
||||
getServerCommandLine(
|
||||
serviceSelectionForm.getLlamaModelPreferencesForm().getActualModelPath(),
|
||||
serviceSelectionForm.getContextSize(),
|
||||
serviceSelectionForm.getThreads(),
|
||||
serviceSelectionForm.getServerPort()));
|
||||
startServerProcessHandler.addProcessListener(getProcessListener(
|
||||
serviceSelectionForm.getServerPort(),
|
||||
serverProgressPanel,
|
||||
onSuccess));
|
||||
startServerProcessHandler.startNotify();
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -142,10 +137,10 @@ public final class LlamaServerAgent implements Disposable {
|
|||
}
|
||||
|
||||
private GeneralCommandLine getServerCommandLine(
|
||||
String modelPath,
|
||||
int contextLength,
|
||||
int threads,
|
||||
int port) {
|
||||
String modelPath,
|
||||
int contextLength,
|
||||
int threads,
|
||||
int port) {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine().withCharset(StandardCharsets.UTF_8);
|
||||
commandLine.setExePath("./server");
|
||||
commandLine.withWorkDirectory(CodeGPTPlugin.getLlamaSourcePath());
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import java.time.LocalDateTime;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
public class SessionVerificationJob implements Job {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(SessionVerificationJob.class);
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) {
|
||||
LOG.info("Refreshing token: " + LocalDateTime.now());
|
||||
// TODO: Not implemented
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import ee.carlrobert.codegpt.completions.you.YouApiClient;
|
|||
import ee.carlrobert.codegpt.completions.you.YouSubscriptionNotifier;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
|
|
@ -29,7 +29,9 @@ public final class YouAuthenticationService {
|
|||
return ApplicationManager.getApplication().getService(YouAuthenticationService.class);
|
||||
}
|
||||
|
||||
public void signInAsync(String email, String password,
|
||||
public void signInAsync(
|
||||
@NotNull String email,
|
||||
@NotNull String password,
|
||||
AuthenticationHandler authenticationHandler) {
|
||||
authClient.authenticate(email, password, new AuthenticationCallback(authenticationHandler));
|
||||
}
|
||||
|
|
@ -44,7 +46,7 @@ public final class YouAuthenticationService {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
OverlayUtils.showNotification("Authentication failed.", NotificationType.ERROR);
|
||||
OverlayUtil.showNotification("Authentication failed.", NotificationType.ERROR);
|
||||
LOG.error("Unable to retrieve session", e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import static com.intellij.openapi.ui.DialogWrapper.OK_EXIT_CODE;
|
|||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CodebaseIndexingAction extends AnAction {
|
||||
|
|
@ -19,7 +19,7 @@ public class CodebaseIndexingAction extends AnAction {
|
|||
var project = event.getProject();
|
||||
if (project != null) {
|
||||
var folderStructureTreePanel = new FolderStructureTreePanel(project);
|
||||
var show = OverlayUtils.showFileStructureDialog(project, folderStructureTreePanel);
|
||||
var show = OverlayUtil.showFileStructureDialog(project, folderStructureTreePanel);
|
||||
if (show == OK_EXIT_CODE) {
|
||||
new CodebaseIndexingTask(project, folderStructureTreePanel.getCheckedFiles()).run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@ import com.intellij.openapi.progress.ProgressManager;
|
|||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.CodeGPTPlugin;
|
||||
import ee.carlrobert.codegpt.completions.CompletionClientProvider;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import ee.carlrobert.embedding.CheckedFile;
|
||||
import ee.carlrobert.embedding.EmbeddingsService;
|
||||
import ee.carlrobert.vector.VectorStore;
|
||||
|
|
@ -55,10 +54,10 @@ public class CodebaseIndexingTask extends Task.Backgroundable {
|
|||
throw new RuntimeException("Unable to serialize json file");
|
||||
}
|
||||
|
||||
if (!FileUtil.exists(CodeGPTPlugin.getIndexStorePath())) {
|
||||
FileUtils.tryCreateDirectory(CodeGPTPlugin.getIndexStorePath());
|
||||
if (!com.intellij.openapi.util.io.FileUtil.exists(CodeGPTPlugin.getIndexStorePath())) {
|
||||
FileUtil.tryCreateDirectory(CodeGPTPlugin.getIndexStorePath());
|
||||
}
|
||||
FileUtils.createFile(
|
||||
FileUtil.createFile(
|
||||
CodeGPTPlugin.getProjectIndexStorePath(project), "index.json", fileContent);
|
||||
|
||||
try {
|
||||
|
|
@ -66,7 +65,7 @@ public class CodebaseIndexingTask extends Task.Backgroundable {
|
|||
List<Item<Object, double[]>> embeddings =
|
||||
embeddingsService.createEmbeddings(checkedFiles, indicator);
|
||||
VectorStore.getInstance(CodeGPTPlugin.getPluginBasePath()).save(embeddings);
|
||||
OverlayUtils.showNotification("Indexing completed", NotificationType.INFORMATION);
|
||||
OverlayUtil.showNotification("Indexing completed", NotificationType.INFORMATION);
|
||||
|
||||
project.getMessageBus()
|
||||
.syncPublisher(CodebaseIndexingCompletedNotifier.INDEXING_COMPLETED_TOPIC)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import com.intellij.ui.ScrollPaneFactory;
|
|||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import ee.carlrobert.embedding.CheckedFile;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
|
@ -124,7 +124,7 @@ public class FolderStructureTreePanel {
|
|||
panel.add(loadingFilesSpinner);
|
||||
} else {
|
||||
panel.add(new JBLabel("Total size: "
|
||||
+ FileUtils.convertFileSize(totalSize) + " ~ "
|
||||
+ FileUtil.convertFileSize(totalSize) + " ~ "
|
||||
+ (convertLongValue(totalSize / 4)) + " tokens " + " ~ "
|
||||
+ new DecimalFormat("#.##")
|
||||
.format(((double) (totalSize / 4) / 1000) * 0.0001) + " $"));
|
||||
|
|
@ -153,7 +153,7 @@ public class FolderStructureTreePanel {
|
|||
if (node.isChecked()) {
|
||||
node.setChecked(!changeListManager.isIgnoredFile(file)
|
||||
&& !ignoreManager.isPotentiallyIgnoredFile(file)
|
||||
&& FileUtils.isUtf8File(file.getPath())
|
||||
&& FileUtil.isUtf8File(file.getPath())
|
||||
&& fileSize < Math.pow(1024, 2));
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ public class FolderStructureTreePanel {
|
|||
.getFileTypeByFile((VirtualFileSystemEntry) userObject);
|
||||
getTextRenderer().setIcon(fileType.getIcon());
|
||||
getTextRenderer().append(
|
||||
" - " + FileUtils.convertFileSize(
|
||||
" - " + FileUtil.convertFileSize(
|
||||
((VirtualFileSystemEntry) userObject).getLength()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import ee.carlrobert.codegpt.settings.state.SettingsState;
|
|||
import ee.carlrobert.codegpt.settings.state.YouSettingsState;
|
||||
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowContentManager;
|
||||
import ee.carlrobert.codegpt.util.ApplicationUtils;
|
||||
import ee.carlrobert.codegpt.util.ApplicationUtil;
|
||||
import javax.swing.JComponent;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -53,22 +53,13 @@ public class SettingsConfigurable implements Configurable {
|
|||
var llamaSettings = LlamaSettingsState.getInstance();
|
||||
|
||||
var serviceSelectionForm = settingsComponent.getServiceSelectionForm();
|
||||
var llamaModelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
return !settingsComponent.getDisplayName().equals(settings.getDisplayName())
|
||||
|| isServiceChanged(settings)
|
||||
|| openAISettings.isModified(serviceSelectionForm)
|
||||
|| azureSettings.isModified(serviceSelectionForm)
|
||||
|| serviceSelectionForm.isDisplayWebSearchResults()
|
||||
!= YouSettingsState.getInstance().isDisplayWebSearchResults()
|
||||
|
||||
|| llamaSettings.isUseCustomModel() != llamaModelPreferencesForm.isUseCustomLlamaModel()
|
||||
|| llamaSettings.getServerPort() != serviceSelectionForm.getLlamaServerPort()
|
||||
|| llamaSettings.getContextSize() != serviceSelectionForm.getContextSize()
|
||||
|| llamaSettings.getThreads() != serviceSelectionForm.getThreads()
|
||||
|| llamaSettings.getHuggingFaceModel() != llamaModelPreferencesForm.getSelectedModel()
|
||||
|| !llamaSettings.getPromptTemplate().equals(llamaModelPreferencesForm.getPromptTemplate())
|
||||
|| !llamaSettings.getCustomLlamaModelPath()
|
||||
.equals(llamaModelPreferencesForm.getCustomLlamaModelPath());
|
||||
|| llamaSettings.isModified(serviceSelectionForm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -89,20 +80,11 @@ public class SettingsConfigurable implements Configurable {
|
|||
settings.setDisplayName(settingsComponent.getDisplayName());
|
||||
settings.setSelectedService(settingsComponent.getSelectedService());
|
||||
|
||||
var llamaModelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
var llamaSettings = LlamaSettingsState.getInstance();
|
||||
llamaSettings.setCustomLlamaModelPath(llamaModelPreferencesForm.getCustomLlamaModelPath());
|
||||
llamaSettings.setHuggingFaceModel(llamaModelPreferencesForm.getSelectedModel());
|
||||
llamaSettings.setUseCustomModel(llamaModelPreferencesForm.isUseCustomLlamaModel());
|
||||
llamaSettings.setPromptTemplate(llamaModelPreferencesForm.getPromptTemplate());
|
||||
llamaSettings.setServerPort(serviceSelectionForm.getLlamaServerPort());
|
||||
llamaSettings.setContextSize(serviceSelectionForm.getContextSize());
|
||||
llamaSettings.setThreads(serviceSelectionForm.getThreads());
|
||||
|
||||
var azureSettings = AzureSettingsState.getInstance();
|
||||
var openAISettings = OpenAISettingsState.getInstance();
|
||||
openAISettings.apply(serviceSelectionForm);
|
||||
azureSettings.apply(serviceSelectionForm);
|
||||
LlamaSettingsState.getInstance().apply(serviceSelectionForm);
|
||||
YouSettingsState.getInstance()
|
||||
.setDisplayWebSearchResults(serviceSelectionForm.isDisplayWebSearchResults());
|
||||
|
||||
|
|
@ -127,18 +109,9 @@ public class SettingsConfigurable implements Configurable {
|
|||
settingsComponent.setDisplayName(settings.getDisplayName());
|
||||
settingsComponent.setSelectedService(settings.getSelectedService());
|
||||
|
||||
var llamaSettings = LlamaSettingsState.getInstance();
|
||||
var llamaModelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
llamaModelPreferencesForm.setSelectedModel(llamaSettings.getHuggingFaceModel());
|
||||
llamaModelPreferencesForm.setCustomLlamaModelPath(llamaSettings.getCustomLlamaModelPath());
|
||||
llamaModelPreferencesForm.setUseCustomLlamaModel(llamaSettings.isUseCustomModel());
|
||||
llamaModelPreferencesForm.setPromptTemplate(llamaSettings.getPromptTemplate());
|
||||
serviceSelectionForm.setLlamaServerPort(llamaSettings.getServerPort());
|
||||
serviceSelectionForm.setContextSize(llamaSettings.getContextSize());
|
||||
serviceSelectionForm.setThreads(llamaSettings.getThreads());
|
||||
|
||||
OpenAISettingsState.getInstance().reset(serviceSelectionForm);
|
||||
AzureSettingsState.getInstance().reset(serviceSelectionForm);
|
||||
LlamaSettingsState.getInstance().reset(serviceSelectionForm);
|
||||
|
||||
serviceSelectionForm.setDisplayWebSearchResults(
|
||||
YouSettingsState.getInstance().isDisplayWebSearchResults());
|
||||
|
|
@ -158,7 +131,7 @@ public class SettingsConfigurable implements Configurable {
|
|||
|
||||
private void resetActiveTab() {
|
||||
ConversationsState.getInstance().setCurrentConversation(null);
|
||||
var project = ApplicationUtils.findCurrentProject();
|
||||
var project = ApplicationUtil.findCurrentProject();
|
||||
if (project == null) {
|
||||
throw new RuntimeException("Could not find current project.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.intellij.util.ui.FormBuilder;
|
|||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UI;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.net.Proxy;
|
||||
import javax.swing.BoxLayout;
|
||||
|
|
@ -151,20 +151,20 @@ public class AdvancedSettingsComponent {
|
|||
proxyPanel.setBorder(JBUI.Borders.emptyLeft(16));
|
||||
proxyPanel.setLayout(new BoxLayout(proxyPanel, BoxLayout.PAGE_AXIS));
|
||||
|
||||
var proxyTypePanel = SwingUtils.createPanel(
|
||||
var proxyTypePanel = UIUtil.createPanel(
|
||||
proxyTypeComboBox,
|
||||
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.typeComboBoxField.label"),
|
||||
false);
|
||||
var proxyHostPanel = SwingUtils.createPanel(
|
||||
var proxyHostPanel = UIUtil.createPanel(
|
||||
proxyHostField,
|
||||
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.hostField.label"),
|
||||
false);
|
||||
var proxyPortPanel = SwingUtils.createPanel(
|
||||
var proxyPortPanel = UIUtil.createPanel(
|
||||
proxyPortField,
|
||||
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.portField.label"),
|
||||
false);
|
||||
SwingUtils.setEqualLabelWidths(proxyTypePanel, proxyHostPanel);
|
||||
SwingUtils.setEqualLabelWidths(proxyPortPanel, proxyHostPanel);
|
||||
UIUtil.setEqualLabelWidths(proxyTypePanel, proxyHostPanel);
|
||||
UIUtil.setEqualLabelWidths(proxyPortPanel, proxyHostPanel);
|
||||
|
||||
proxyPanel.add(proxyTypePanel);
|
||||
proxyPanel.add(proxyHostPanel);
|
||||
|
|
@ -173,13 +173,13 @@ public class AdvancedSettingsComponent {
|
|||
.panel(proxyAuthCheckbox)
|
||||
.createPanel());
|
||||
|
||||
var proxyUsernamePanel = SwingUtils.createPanel(proxyAuthUsername,
|
||||
var proxyUsernamePanel = UIUtil.createPanel(proxyAuthUsername,
|
||||
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.usernameField.label"),
|
||||
false);
|
||||
var proxyPasswordPanel = SwingUtils.createPanel(proxyAuthPassword,
|
||||
var proxyPasswordPanel = UIUtil.createPanel(proxyAuthPassword,
|
||||
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.passwordField.label"),
|
||||
false);
|
||||
SwingUtils.setEqualLabelWidths(proxyPasswordPanel, proxyUsernamePanel);
|
||||
UIUtil.setEqualLabelWidths(proxyPasswordPanel, proxyUsernamePanel);
|
||||
|
||||
var proxyAuthPanel = FormBuilder.createFormBuilder()
|
||||
.addVerticalGap(4)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import com.intellij.util.ui.JBUI;
|
|||
import com.intellij.util.ui.UI;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.awt.Dimension;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
@ -103,7 +103,7 @@ public class ConfigurationComponent {
|
|||
configuration.isCreateNewChatOnEachAction());
|
||||
methodNameGenerationCheckBox = new JBCheckBox(
|
||||
CodeGPTBundle.get("configurationConfigurable.enableMethodNameGeneration.label"),
|
||||
configuration.isMethodNameGenerationEnabled());
|
||||
configuration.isMethodRefactoringEnabled());
|
||||
|
||||
mainPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(tablePanel)
|
||||
|
|
@ -157,7 +157,7 @@ public class ConfigurationComponent {
|
|||
UI.PanelFactory.panel(component)
|
||||
.resizeX(false)
|
||||
.withComment(CodeGPTBundle.get(commentKey))
|
||||
.withCommentHyperlinkListener(SwingUtils::handleHyperlinkClicked)
|
||||
.withCommentHyperlinkListener(UIUtil::handleHyperlinkClicked)
|
||||
.createPanel(),
|
||||
true
|
||||
);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class ConfigurationConfigurable implements Configurable {
|
|||
|| configurationComponent.isCreateNewChatOnEachAction()
|
||||
!= configuration.isCreateNewChatOnEachAction()
|
||||
|| configurationComponent.isMethodNameGenerationEnabled()
|
||||
!= configuration.isMethodNameGenerationEnabled();
|
||||
!= configuration.isMethodRefactoringEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -67,7 +67,7 @@ public class ConfigurationConfigurable implements Configurable {
|
|||
configurationComponent.setCreateNewChatOnEachAction(
|
||||
configuration.isCreateNewChatOnEachAction());
|
||||
configurationComponent.setDisableMethodNameGeneration(
|
||||
configuration.isMethodNameGenerationEnabled());
|
||||
configuration.isMethodRefactoringEnabled());
|
||||
EditorActionsUtil.refreshActions();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class ConfigurationState implements PersistentStateComponent<Configuratio
|
|||
this.ignoreGitCommitTokenLimit = ignoreGitCommitTokenLimit;
|
||||
}
|
||||
|
||||
public boolean isMethodNameGenerationEnabled() {
|
||||
public boolean isMethodRefactoringEnabled() {
|
||||
return methodNameGenerationEnabled;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import com.intellij.openapi.progress.Task;
|
|||
import com.intellij.openapi.project.Project;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
|
||||
import ee.carlrobert.codegpt.util.DownloadingUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.DownloadingUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -81,12 +81,12 @@ public class DownloadModelAction extends AnAction {
|
|||
long startTime = System.currentTimeMillis();
|
||||
|
||||
progressUpdateScheduler = executorService.scheduleAtFixedRate(() ->
|
||||
onUpdateProgress.accept(DownloadingUtils.getFormattedDownloadProgress(
|
||||
onUpdateProgress.accept(DownloadingUtil.getFormattedDownloadProgress(
|
||||
startTime,
|
||||
fileSize,
|
||||
bytesRead[0])),
|
||||
0, 1, TimeUnit.SECONDS);
|
||||
FileUtils.copyFileWithProgress(model.getFileName(), url, bytesRead, fileSize, indicator);
|
||||
FileUtil.copyFileWithProgress(model.getFileName(), url, bytesRead, fileSize, indicator);
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to open connection", ex);
|
||||
onFailed.accept(ex);
|
||||
|
|
|
|||
|
|
@ -264,6 +264,12 @@ public class LlamaModelPreferencesForm {
|
|||
return promptTemplateComboBox.getItem();
|
||||
}
|
||||
|
||||
public String getActualModelPath() {
|
||||
return isUseCustomLlamaModel()
|
||||
? getCustomLlamaModelPath()
|
||||
: CodeGPTPlugin.getLlamaModelsPath() + File.separator + getSelectedModel().getFileName();
|
||||
}
|
||||
|
||||
private ComboBox<LlamaModel> createModelComboBox(
|
||||
EnumComboBoxModel<LlamaModel> llamaModelEnumComboBoxModel,
|
||||
LlamaModel llamaModel,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import ee.carlrobert.codegpt.CodeGPTPlugin;
|
|||
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
|
||||
import ee.carlrobert.codegpt.completions.llama.LlamaServerAgent;
|
||||
import ee.carlrobert.codegpt.settings.state.LlamaSettingsState;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.File;
|
||||
import javax.swing.JButton;
|
||||
|
|
@ -51,14 +51,14 @@ public class LlamaServiceSelectionForm extends JPanel {
|
|||
threadsField.setEnabled(!serverRunning);
|
||||
|
||||
var serverProgressPanel = new ServerProgressPanel();
|
||||
var serverButton = getServerButton(serverRunning, llamaServerAgent, serverProgressPanel);
|
||||
var serverButton = getServerButton(llamaServerAgent, serverProgressPanel);
|
||||
var contextSizeHelpText = ComponentPanelBuilder.createCommentComponent(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.contextSize.comment"),
|
||||
true);
|
||||
contextSizeHelpText.setBorder(JBUI.Borders.empty(0, 4));
|
||||
var threadsHelpText = ComponentPanelBuilder.createCommentComponent(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.threads.comment"),
|
||||
true);
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.threads.comment"),
|
||||
true);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(FormBuilder.createFormBuilder()
|
||||
|
|
@ -121,72 +121,83 @@ public class LlamaServiceSelectionForm extends JPanel {
|
|||
return threadsField.getValue();
|
||||
}
|
||||
|
||||
private JButton getServerButton(boolean serverRunning, LlamaServerAgent llamaServerAgent,
|
||||
private JButton getServerButton(
|
||||
LlamaServerAgent llamaServerAgent,
|
||||
ServerProgressPanel serverProgressPanel) {
|
||||
var serverRunning = llamaServerAgent.isServerRunning();
|
||||
var serverButton = new JButton();
|
||||
serverButton.setText(serverRunning
|
||||
? CodeGPTBundle.get("settingsConfigurable.service.llama.stopServer.label")
|
||||
: CodeGPTBundle.get("settingsConfigurable.service.llama.startServer.label"));
|
||||
serverButton.setIcon(serverRunning ? Actions.Suspend : Actions.Execute);
|
||||
serverButton.addActionListener(event -> {
|
||||
if (llamaModelPreferencesForm.isUseCustomLlamaModel()) {
|
||||
var customModelPath = llamaModelPreferencesForm.getCustomLlamaModelPath();
|
||||
if (customModelPath == null || customModelPath.isEmpty()) {
|
||||
OverlayUtils.showBalloon(
|
||||
CodeGPTBundle.get("validation.error.fieldRequired"),
|
||||
MessageType.ERROR,
|
||||
llamaModelPreferencesForm.getCustomModelPathBrowserButton());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!isModelExists(llamaModelPreferencesForm.getSelectedModel())) {
|
||||
OverlayUtils.showBalloon(
|
||||
CodeGPTBundle.get(
|
||||
"settingsConfigurable.service.llama.overlay.modelNotDownloaded.text"),
|
||||
MessageType.ERROR,
|
||||
llamaModelPreferencesForm.getHuggingFaceModelComboBox());
|
||||
return;
|
||||
}
|
||||
if (!validateModelConfiguration()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (llamaServerAgent.isServerRunning()) {
|
||||
setFormEnabled(true);
|
||||
serverButton.setText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.startServer.label"));
|
||||
serverButton.setIcon(Actions.Execute);
|
||||
serverProgressPanel.updateText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.progress.stoppingServer"));
|
||||
enableForm(serverButton, serverProgressPanel);
|
||||
llamaServerAgent.stopAgent();
|
||||
} else {
|
||||
setFormEnabled(false);
|
||||
serverButton.setText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.stopServer.label"));
|
||||
serverButton.setIcon(Actions.Suspend);
|
||||
serverProgressPanel.startProgress(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.progress.startingServer"));
|
||||
|
||||
// TODO: Move to LlamaModelPreferencesForm
|
||||
var modelPath = llamaModelPreferencesForm.isUseCustomLlamaModel()
|
||||
? llamaModelPreferencesForm.getCustomLlamaModelPath()
|
||||
: CodeGPTPlugin.getLlamaModelsPath()
|
||||
+ File.separator
|
||||
+ llamaModelPreferencesForm.getSelectedModel().getFileName();
|
||||
llamaServerAgent.startAgent(
|
||||
modelPath,
|
||||
maxTokensField.getValue(),
|
||||
threadsField.getValue(),
|
||||
portField.getNumber(),
|
||||
serverProgressPanel,
|
||||
() -> {
|
||||
setFormEnabled(false);
|
||||
serverProgressPanel.displayComponent(
|
||||
new JBLabel("Server running", Actions.Checked, SwingConstants.LEADING));
|
||||
});
|
||||
disableForm(serverButton, serverProgressPanel);
|
||||
llamaServerAgent.startAgent(this, serverProgressPanel, () -> {
|
||||
setFormEnabled(false);
|
||||
serverProgressPanel.displayComponent(
|
||||
new JBLabel("Server running", Actions.Checked, SwingConstants.LEADING));
|
||||
});
|
||||
}
|
||||
});
|
||||
return serverButton;
|
||||
}
|
||||
|
||||
private boolean validateModelConfiguration() {
|
||||
return validateCustomModelPath() && validateSelectedModel();
|
||||
}
|
||||
|
||||
private boolean validateCustomModelPath() {
|
||||
if (llamaModelPreferencesForm.isUseCustomLlamaModel()) {
|
||||
var customModelPath = llamaModelPreferencesForm.getCustomLlamaModelPath();
|
||||
if (customModelPath == null || customModelPath.isEmpty()) {
|
||||
OverlayUtil.showBalloon(
|
||||
CodeGPTBundle.get("validation.error.fieldRequired"),
|
||||
MessageType.ERROR,
|
||||
llamaModelPreferencesForm.getCustomModelPathBrowserButton());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateSelectedModel() {
|
||||
if (!llamaModelPreferencesForm.isUseCustomLlamaModel() && !isModelExists(
|
||||
llamaModelPreferencesForm.getSelectedModel())) {
|
||||
OverlayUtil.showBalloon(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.overlay.modelNotDownloaded.text"),
|
||||
MessageType.ERROR,
|
||||
llamaModelPreferencesForm.getHuggingFaceModelComboBox());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void enableForm(JButton serverButton, ServerProgressPanel progressPanel) {
|
||||
setFormEnabled(true);
|
||||
serverButton.setText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.startServer.label"));
|
||||
serverButton.setIcon(Actions.Execute);
|
||||
progressPanel.updateText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.progress.stoppingServer"));
|
||||
}
|
||||
|
||||
private void disableForm(JButton serverButton, ServerProgressPanel progressPanel) {
|
||||
setFormEnabled(false);
|
||||
serverButton.setText(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.stopServer.label"));
|
||||
serverButton.setIcon(Actions.Suspend);
|
||||
progressPanel.startProgress(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.llama.progress.startingServer"));
|
||||
}
|
||||
|
||||
private boolean isModelExists(HuggingFaceModel model) {
|
||||
return FileUtil.exists(
|
||||
CodeGPTPlugin.getLlamaModelsPath() + File.separator + model.getFileName());
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
|||
import ee.carlrobert.codegpt.settings.state.AzureSettingsState;
|
||||
import ee.carlrobert.codegpt.settings.state.OpenAISettingsState;
|
||||
import ee.carlrobert.codegpt.settings.state.YouSettingsState;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import ee.carlrobert.llm.client.openai.completion.chat.OpenAIChatCompletionModel;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -151,7 +151,7 @@ public class ServiceSelectionForm {
|
|||
.resizeX(false)
|
||||
.withComment(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.openai.apiKey.comment"))
|
||||
.withCommentHyperlinkListener(SwingUtils::handleHyperlinkClicked)
|
||||
.withCommentHyperlinkListener(UIUtil::handleHyperlinkClicked)
|
||||
.createPanel();
|
||||
|
||||
return FormBuilder.createFormBuilder()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResp
|
|||
import ee.carlrobert.codegpt.completions.you.auth.response.YouUser;
|
||||
import ee.carlrobert.codegpt.credentials.YouCredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -134,7 +134,7 @@ public class YouServiceSelectionForm extends JPanel {
|
|||
}
|
||||
|
||||
private JTextPane createSignUpTextPane() {
|
||||
var textPane = SwingUtils.createTextPane(
|
||||
var textPane = UIUtil.createTextPane(
|
||||
"<html><a href=\"https://you.com/code\">Don't have an account? Sign up</a></html>");
|
||||
textPane.setBorder(JBUI.Borders.emptyLeft(4));
|
||||
textPane.setOpaque(false);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.intellij.openapi.components.Storage;
|
|||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
|
||||
import ee.carlrobert.codegpt.completions.llama.PromptTemplate;
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceSelectionForm;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -40,6 +41,39 @@ public class LlamaSettingsState implements PersistentStateComponent<LlamaSetting
|
|||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
public boolean isModified(ServiceSelectionForm serviceSelectionForm) {
|
||||
var modelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
return serverPort != serviceSelectionForm.getLlamaServerPort()
|
||||
|| contextSize != serviceSelectionForm.getContextSize()
|
||||
|| threads != serviceSelectionForm.getThreads()
|
||||
|| huggingFaceModel != modelPreferencesForm.getSelectedModel()
|
||||
|| !promptTemplate.equals(modelPreferencesForm.getPromptTemplate())
|
||||
|| useCustomModel != modelPreferencesForm.isUseCustomLlamaModel()
|
||||
|| !customLlamaModelPath.equals(modelPreferencesForm.getCustomLlamaModelPath());
|
||||
}
|
||||
|
||||
public void apply(ServiceSelectionForm serviceSelectionForm) {
|
||||
var modelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
customLlamaModelPath = modelPreferencesForm.getCustomLlamaModelPath();
|
||||
huggingFaceModel = modelPreferencesForm.getSelectedModel();
|
||||
useCustomModel = modelPreferencesForm.isUseCustomLlamaModel();
|
||||
promptTemplate = modelPreferencesForm.getPromptTemplate();
|
||||
serverPort = serviceSelectionForm.getLlamaServerPort();
|
||||
contextSize = serviceSelectionForm.getContextSize();
|
||||
threads = serviceSelectionForm.getThreads();
|
||||
}
|
||||
|
||||
public void reset(ServiceSelectionForm serviceSelectionForm) {
|
||||
var modelPreferencesForm = serviceSelectionForm.getLlamaModelPreferencesForm();
|
||||
modelPreferencesForm.setSelectedModel(huggingFaceModel);
|
||||
modelPreferencesForm.setCustomLlamaModelPath(customLlamaModelPath);
|
||||
modelPreferencesForm.setUseCustomLlamaModel(useCustomModel);
|
||||
modelPreferencesForm.setPromptTemplate(promptTemplate);
|
||||
serviceSelectionForm.setLlamaServerPort(serverPort);
|
||||
serviceSelectionForm.setContextSize(contextSize);
|
||||
serviceSelectionForm.setThreads(threads);
|
||||
}
|
||||
|
||||
public boolean isUseCustomModel() {
|
||||
return useCustomModel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.SwingUtils.createScrollPaneWithSmartScroller;
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.createScrollPaneWithSmartScroller;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
|
|
@ -24,8 +24,8 @@ import ee.carlrobert.codegpt.toolwindow.chat.components.TotalTokensPanel;
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.components.UserMessagePanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.UserPromptTextArea;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.UserPromptTextAreaHeader;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
|
|
@ -62,7 +62,7 @@ public abstract class BaseChatToolWindowTabPanel implements ChatToolWindowTabPan
|
|||
toolWindowScrollablePanel = new ChatToolWindowScrollablePanel(settings);
|
||||
totalTokensPanel = new TotalTokensPanel(
|
||||
conversation,
|
||||
EditorUtils.getSelectedEditorSelectedText(project),
|
||||
EditorUtil.getSelectedEditorSelectedText(project),
|
||||
this);
|
||||
userPromptTextArea = new UserPromptTextArea(this::handleSubmit, totalTokensPanel);
|
||||
rootPanel = createRootPanel(settings);
|
||||
|
|
@ -185,12 +185,12 @@ public abstract class BaseChatToolWindowTabPanel implements ChatToolWindowTabPan
|
|||
|
||||
private void handleSubmit(String text) {
|
||||
var message = new Message(text);
|
||||
var editor = EditorUtils.getSelectedEditor(project);
|
||||
var editor = EditorUtil.getSelectedEditor(project);
|
||||
if (editor != null) {
|
||||
var selectionModel = editor.getSelectionModel();
|
||||
var selectedText = selectionModel.getSelectedText();
|
||||
if (selectedText != null && !selectedText.isEmpty()) {
|
||||
var fileExtension = FileUtils.getFileExtension(
|
||||
var fileExtension = FileUtil.getFileExtension(
|
||||
((EditorImpl) editor).getVirtualFile().getName());
|
||||
message = new Message(text + format("\n```%s\n%s\n```", fileExtension, selectedText));
|
||||
message.setUserMessage(text);
|
||||
|
|
@ -207,9 +207,7 @@ public abstract class BaseChatToolWindowTabPanel implements ChatToolWindowTabPan
|
|||
JBUI.Borders.customLine(JBColor.border(), 1, 0, 0, 0),
|
||||
JBUI.Borders.empty(8)));
|
||||
panel.setBackground(getPanelBackgroundColor());
|
||||
panel.add(
|
||||
new UserPromptTextAreaHeader(project, settings, totalTokensPanel),
|
||||
BorderLayout.NORTH);
|
||||
panel.add(new UserPromptTextAreaHeader(settings, totalTokensPanel), BorderLayout.NORTH);
|
||||
panel.add(userPromptTextArea, BorderLayout.SOUTH);
|
||||
return panel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
|
||||
import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
|
||||
import com.intellij.openapi.roots.ui.componentsList.layout.VerticalStackLayout;
|
||||
|
|
@ -8,7 +8,7 @@ import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
|||
import ee.carlrobert.codegpt.settings.service.ServiceType;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.ResponsePanel;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -73,7 +73,7 @@ public class ChatToolWindowScrollablePanel extends ScrollablePanel {
|
|||
|
||||
// TODO: Move
|
||||
private JTextPane createYouCouponTextPane() {
|
||||
var textPane = SwingUtils.createTextPane(
|
||||
var textPane = UIUtil.createTextPane(
|
||||
"<html>\n"
|
||||
+ "<body>\n"
|
||||
+ " <p style=\"margin: 4px 0;\">Use CodeGPT coupon for free month of GPT-4.</p>\n"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.vladsch.flexmark.ast.BulletListItem;
|
||||
import com.vladsch.flexmark.ast.Code;
|
||||
|
|
@ -11,7 +12,6 @@ import com.vladsch.flexmark.html.renderer.NodeRendererContext;
|
|||
import com.vladsch.flexmark.html.renderer.NodeRendererFactory;
|
||||
import com.vladsch.flexmark.html.renderer.NodeRenderingHandler;
|
||||
import com.vladsch.flexmark.util.data.DataHolder;
|
||||
import ee.carlrobert.codegpt.util.ThemeUtils;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ public class ResponseNodeRenderer implements NodeRenderer {
|
|||
}
|
||||
|
||||
private void renderCode(Code node, NodeRendererContext context, HtmlWriter html) {
|
||||
html.attr("style", "color: " + ThemeUtils.getRGB(new JBColor(0x00627A, 0xCC7832)));
|
||||
html.attr("style", "color: " + ColorUtil.toHex(new JBColor(0x00627A, 0xCC7832)));
|
||||
context.delegateRender();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import ee.carlrobert.codegpt.toolwindow.chat.components.ChatMessageResponseBody;
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.components.ResponsePanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.TotalTokensPanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.UserPromptTextArea;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.llm.client.openai.completion.ErrorDetails;
|
||||
import ee.carlrobert.llm.client.you.completion.YouSerpResult;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -98,7 +98,7 @@ abstract class ToolWindowCompletionResponseEventListener implements
|
|||
|
||||
@Override
|
||||
public void handleTokensExceeded(Conversation conversation, Message message) {
|
||||
var answer = OverlayUtils.showTokenLimitExceededDialog();
|
||||
var answer = OverlayUtil.showTokenLimitExceededDialog();
|
||||
if (answer == OK) {
|
||||
TelemetryAction.IDE_ACTION.createActionMessage()
|
||||
.property("action", "DISCARD_TOKEN_LIMIT")
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
public interface YouModelChangeNotifier {
|
||||
|
||||
Topic<YouModelChangeNotifier> YOU_MODEL_CHANGE_NOTIFIER_TOPIC =
|
||||
Topic.create("youModelChangeTopic", YouModelChangeNotifier.class);
|
||||
|
||||
void modelChanged(boolean selected);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.components;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
import static java.lang.String.format;
|
||||
import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
|
||||
|
||||
|
|
@ -26,8 +26,8 @@ import ee.carlrobert.codegpt.toolwindow.chat.ResponseNodeRenderer;
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.StreamParser;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.StreamResponseType;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.editor.ResponseEditor;
|
||||
import ee.carlrobert.codegpt.util.MarkdownUtils;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.MarkdownUtil;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import ee.carlrobert.llm.client.you.completion.YouSerpResult;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
|
|
@ -93,7 +93,7 @@ public class ChatMessageResponseBody extends JPanel {
|
|||
}
|
||||
|
||||
public ChatMessageResponseBody withResponse(String response) {
|
||||
for (var message : MarkdownUtils.splitCodeBlocks(response)) {
|
||||
for (var message : MarkdownUtil.splitCodeBlocks(response)) {
|
||||
boolean isCodeResponse = message.startsWith("```");
|
||||
if (isCodeResponse) {
|
||||
currentlyProcessedEditor = null;
|
||||
|
|
@ -281,14 +281,14 @@ public class ChatMessageResponseBody extends JPanel {
|
|||
}
|
||||
|
||||
private JTextPane createTextPane(String text) {
|
||||
var textPane = SwingUtils.createTextPane(text, event -> {
|
||||
var textPane = UIUtil.createTextPane(text, event -> {
|
||||
if (FileUtil.exists(event.getDescription()) && ACTIVATED.equals(event.getEventType())) {
|
||||
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(event.getDescription());
|
||||
FileEditorManager.getInstance(project).openFile(Objects.requireNonNull(file), true);
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtils.handleHyperlinkClicked(event);
|
||||
UIUtil.handleHyperlinkClicked(event);
|
||||
});
|
||||
textPane.getCaret().setVisible(true);
|
||||
textPane.setCaretPosition(textPane.getDocument().getLength());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.components;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
|
||||
import com.intellij.icons.AllIcons.Actions;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@ import com.intellij.ui.DocumentAdapter;
|
|||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.components.JBTextArea;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.completions.CompletionRequestHandler;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
|
|
@ -29,7 +28,6 @@ import javax.swing.AbstractAction;
|
|||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
|
@ -40,10 +38,8 @@ public class UserPromptTextArea extends JPanel {
|
|||
|
||||
private static final Logger LOG = Logger.getInstance(UserPromptTextArea.class);
|
||||
|
||||
private static final String TEXT_SUBMIT = "text-submit";
|
||||
private static final String INSERT_BREAK = "insert-break";
|
||||
private static final JBColor BACKGROUND_COLOR = JBColor.namedColor(
|
||||
"Editor.SearchField.background", UIUtil.getTextFieldBackground());
|
||||
"Editor.SearchField.background", com.intellij.util.ui.UIUtil.getTextFieldBackground());
|
||||
|
||||
private final JBTextArea textArea;
|
||||
|
||||
|
|
@ -64,10 +60,7 @@ public class UserPromptTextArea extends JPanel {
|
|||
textArea.setWrapStyleWord(true);
|
||||
textArea.getEmptyText().setText(CodeGPTBundle.get("toolwindow.chat.textArea.emptyText"));
|
||||
textArea.setBorder(JBUI.Borders.empty(8, 4));
|
||||
var input = textArea.getInputMap();
|
||||
input.put(KeyStroke.getKeyStroke("ENTER"), TEXT_SUBMIT);
|
||||
input.put(KeyStroke.getKeyStroke("shift ENTER"), INSERT_BREAK);
|
||||
textArea.getActionMap().put(TEXT_SUBMIT, new AbstractAction() {
|
||||
UIUtil.addShiftEnterInputMap(textArea, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
|
|
@ -190,7 +183,7 @@ public class UserPromptTextArea extends JPanel {
|
|||
|
||||
// TODO: IconActionButton?
|
||||
private JButton createIconButton(Icon icon, @Nullable Runnable submitListener) {
|
||||
var button = SwingUtils.createIconButton(icon);
|
||||
var button = UIUtil.createIconButton(icon);
|
||||
if (submitListener != null) {
|
||||
button.addActionListener((e) -> handleSubmit());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.components;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
|
|
@ -12,16 +11,12 @@ import ee.carlrobert.codegpt.completions.you.YouSubscriptionNotifier;
|
|||
import ee.carlrobert.codegpt.completions.you.auth.SignedOutNotifier;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.ModelIconLabel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.YouModelChangeNotifier;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class UserPromptTextAreaHeader extends JPanel {
|
||||
|
||||
public UserPromptTextAreaHeader(
|
||||
Project project,
|
||||
SettingsState settings,
|
||||
TotalTokensPanel totalTokensPanel) {
|
||||
public UserPromptTextAreaHeader(SettingsState settings, TotalTokensPanel totalTokensPanel) {
|
||||
super(new BorderLayout());
|
||||
setBackground(getPanelBackgroundColor());
|
||||
setBorder(JBUI.Borders.emptyBottom(8));
|
||||
|
|
@ -31,8 +26,8 @@ public class UserPromptTextAreaHeader extends JPanel {
|
|||
add(totalTokensPanel, BorderLayout.LINE_START);
|
||||
break;
|
||||
case YOU:
|
||||
JBCheckBox gpt4CheckBox = new YouProCheckbox(project);
|
||||
subscribeToYouTopics(project, gpt4CheckBox);
|
||||
JBCheckBox gpt4CheckBox = new YouProCheckbox();
|
||||
subscribeToYouTopics(gpt4CheckBox);
|
||||
add(gpt4CheckBox, BorderLayout.LINE_START);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -45,21 +40,12 @@ public class UserPromptTextAreaHeader extends JPanel {
|
|||
.withBackground(getPanelBackgroundColor()), BorderLayout.LINE_END);
|
||||
}
|
||||
|
||||
private void subscribeToYouTopics(Project project, JBCheckBox gpt4CheckBox) {
|
||||
private void subscribeToYouTopics(JBCheckBox gpt4CheckBox) {
|
||||
var messageBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
|
||||
subscribeToYouModelChangeTopic(project, gpt4CheckBox);
|
||||
subscribeToYouSubscriptionTopic(messageBusConnection, gpt4CheckBox);
|
||||
subscribeToSignedOutTopic(messageBusConnection, gpt4CheckBox);
|
||||
}
|
||||
|
||||
private void subscribeToYouModelChangeTopic(Project project, JBCheckBox gpt4CheckBox) {
|
||||
project.getMessageBus()
|
||||
.connect()
|
||||
.subscribe(
|
||||
YouModelChangeNotifier.YOU_MODEL_CHANGE_NOTIFIER_TOPIC,
|
||||
(YouModelChangeNotifier) gpt4CheckBox::setSelected);
|
||||
}
|
||||
|
||||
private void subscribeToSignedOutTopic(
|
||||
MessageBusConnection messageBusConnection,
|
||||
JBCheckBox gpt4CheckBox) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.components;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.settings.state.YouSettingsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.YouModelChangeNotifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class YouProCheckbox extends JBCheckBox {
|
||||
|
||||
public YouProCheckbox(@NotNull Project project) {
|
||||
public YouProCheckbox() {
|
||||
super(CodeGPTBundle.get("toolwindow.chat.youProCheckBox.text"));
|
||||
var youSettings = YouSettingsState.getInstance();
|
||||
var youUserManager = YouUserManager.getInstance();
|
||||
|
|
@ -21,10 +18,6 @@ public class YouProCheckbox extends JBCheckBox {
|
|||
addChangeListener(e -> {
|
||||
var selected = ((JBCheckBox) e.getSource()).isSelected();
|
||||
setToolTipText(getTooltipText(youUserManager, selected));
|
||||
// TODO: Remove
|
||||
project.getMessageBus()
|
||||
.syncPublisher(YouModelChangeNotifier.YOU_MODEL_CHANGE_NOTIFIER_TOPIC)
|
||||
.modelChanged(selected);
|
||||
youSettings.setUseGPT4Model(selected);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.contextual;
|
||||
|
||||
import static com.intellij.openapi.ui.DialogWrapper.OK_EXIT_CODE;
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
|
|
@ -13,8 +13,8 @@ import ee.carlrobert.codegpt.indexes.CodebaseIndexingTask;
|
|||
import ee.carlrobert.codegpt.indexes.FolderStructureTreePanel;
|
||||
import ee.carlrobert.codegpt.settings.SettingsConfigurable;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.ResponsePanel;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import ee.carlrobert.vector.VectorStore;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
|
|
@ -77,7 +77,7 @@ class ContextualChatToolWindowLandingPanel extends ResponsePanel {
|
|||
}
|
||||
|
||||
private JTextPane createTextPane() {
|
||||
var textPane = SwingUtils.createTextPane("", this::handleHyperlinkClicked);
|
||||
var textPane = UIUtil.createTextPane("", this::handleHyperlinkClicked);
|
||||
textPane.setBackground(getPanelBackgroundColor());
|
||||
return textPane;
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ class ContextualChatToolWindowLandingPanel extends ResponsePanel {
|
|||
break;
|
||||
case "START_INDEXING":
|
||||
var folderStructureTreePanel = new FolderStructureTreePanel(project);
|
||||
var show = OverlayUtils.showFileStructureDialog(project, folderStructureTreePanel);
|
||||
var show = OverlayUtil.showFileStructureDialog(project, folderStructureTreePanel);
|
||||
if (show == OK_EXIT_CODE) {
|
||||
new CodebaseIndexingTask(project, folderStructureTreePanel.getCheckedFiles()).run();
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ class ContextualChatToolWindowLandingPanel extends ResponsePanel {
|
|||
LOG.error("Could not trigger action {}", event.getDescription());
|
||||
}
|
||||
} else {
|
||||
SwingUtils.handleHyperlinkClicked(event);
|
||||
UIUtil.handleHyperlinkClicked(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.editor;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtils.findLanguageExtensionMapping;
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtil.findLanguageExtensionMapping;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import com.intellij.icons.AllIcons.General;
|
||||
|
|
@ -28,7 +28,7 @@ import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.DiffAction;
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.EditAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.NewFileAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.ReplaceSelectionAction;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
|
|
@ -53,7 +53,7 @@ public class ResponseEditor extends JPanel implements Disposable {
|
|||
var extensionMapping = findLanguageExtensionMapping(markdownLanguage);
|
||||
language = extensionMapping.getKey();
|
||||
extension = extensionMapping.getValue();
|
||||
editor = EditorUtils.createEditor(project, extension, code);
|
||||
editor = EditorUtil.createEditor(project, extension, code);
|
||||
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new ReplaceCodeInMainEditorAction());
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.intellij.openapi.editor.Editor;
|
|||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.actions.ActionType;
|
||||
import ee.carlrobert.codegpt.actions.TrackableAction;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
|
@ -33,7 +33,7 @@ public class CopyAction extends TrackableAction {
|
|||
var locationOnScreen = ((MouseEvent) event.getInputEvent()).getLocationOnScreen();
|
||||
locationOnScreen.y = locationOnScreen.y - 16;
|
||||
|
||||
OverlayUtils.showInfoBalloon(
|
||||
OverlayUtil.showInfoBalloon(
|
||||
CodeGPTBundle.get("toolwindow.chat.editor.action.copy.success"),
|
||||
locationOnScreen);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ import com.intellij.openapi.util.Pair;
|
|||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.actions.ActionType;
|
||||
import ee.carlrobert.codegpt.actions.TrackableAction;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DiffAction extends TrackableAction {
|
||||
|
|
@ -37,16 +37,16 @@ public class DiffAction extends TrackableAction {
|
|||
public void handleAction(@NotNull AnActionEvent event) {
|
||||
var project = requireNonNull(event.getProject());
|
||||
var selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
|
||||
if (!EditorUtils.hasSelection(selectedTextEditor)) {
|
||||
OverlayUtils.showSelectedEditorSelectionWarning(event);
|
||||
if (!EditorUtil.hasSelection(selectedTextEditor)) {
|
||||
OverlayUtil.showSelectedEditorSelectionWarning(event);
|
||||
return;
|
||||
}
|
||||
|
||||
var resultEditorFile = FileUtils.getEditorFile(selectedTextEditor);
|
||||
var resultEditorFile = FileUtil.getEditorFile(selectedTextEditor);
|
||||
var diffContentFactory = DiffContentFactory.getInstance();
|
||||
var request = new SimpleDiffRequest(
|
||||
CodeGPTBundle.get("editor.diff.title"),
|
||||
diffContentFactory.create(project, FileUtils.getEditorFile(editor)),
|
||||
diffContentFactory.create(project, FileUtil.getEditorFile(editor)),
|
||||
diffContentFactory.create(project, resultEditorFile),
|
||||
CodeGPTBundle.get("editor.diff.local.content.title"),
|
||||
resultEditorFile.getName());
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import com.intellij.util.ui.FormBuilder;
|
|||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.actions.ActionType;
|
||||
import ee.carlrobert.codegpt.actions.TrackableAction;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ public class NewFileAction extends TrackableAction {
|
|||
fileNameTextField.setColumns(30);
|
||||
|
||||
if (showDialog(project, textFieldWithBrowseButton, fileNameTextField) == OK_EXIT_CODE) {
|
||||
var file = FileUtils.createFile(
|
||||
var file = FileUtil.createFile(
|
||||
textFieldWithBrowseButton.getText(),
|
||||
fileNameTextField.getText(),
|
||||
editor.getDocument().getText());
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import com.intellij.openapi.editor.Editor;
|
|||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.actions.ActionType;
|
||||
import ee.carlrobert.codegpt.actions.TrackableAction;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ReplaceSelectionAction extends TrackableAction {
|
||||
|
|
@ -26,10 +26,10 @@ public class ReplaceSelectionAction extends TrackableAction {
|
|||
@Override
|
||||
public void handleAction(@NotNull AnActionEvent event) {
|
||||
var project = requireNonNull(event.getProject());
|
||||
if (EditorUtils.isMainEditorTextSelected(project)) {
|
||||
EditorUtils.replaceMainEditorSelection(project, editor.getDocument().getText());
|
||||
if (EditorUtil.isMainEditorTextSelected(project)) {
|
||||
EditorUtil.replaceMainEditorSelection(project, editor.getDocument().getText());
|
||||
} else {
|
||||
OverlayUtils.showSelectedEditorSelectionWarning(event);
|
||||
OverlayUtil.showSelectedEditorSelectionWarning(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.standard;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
import static java.lang.String.format;
|
||||
import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import ee.carlrobert.codegpt.settings.state.SettingsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.ResponsePanel;
|
||||
import ee.carlrobert.codegpt.util.SwingUtils;
|
||||
import ee.carlrobert.codegpt.util.UIUtil;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
|
|
@ -24,7 +24,7 @@ class StandardChatToolWindowLandingPanel extends ResponsePanel {
|
|||
}
|
||||
|
||||
private JTextPane createContent() {
|
||||
var textPane = SwingUtils.createTextPane(
|
||||
var textPane = UIUtil.createTextPane(
|
||||
"<html>"
|
||||
+ format(
|
||||
"<p style=\"margin-top: 4px; margin-bottom: 4px;\">"
|
||||
|
|
@ -79,7 +79,7 @@ class StandardChatToolWindowLandingPanel extends ResponsePanel {
|
|||
LOG.error("Could not trigger action {}", event.getDescription());
|
||||
}
|
||||
} else {
|
||||
SwingUtils.handleHyperlinkClicked(event);
|
||||
UIUtil.handleHyperlinkClicked(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import ee.carlrobert.codegpt.toolwindow.chat.BaseChatToolWindowTabPanel;
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.components.ChatMessageResponseBody;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.ResponsePanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.UserMessagePanel;
|
||||
import ee.carlrobert.codegpt.util.EditorUtils;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.EditorUtil;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import javax.swing.JComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -34,16 +34,16 @@ public class StandardChatToolWindowTabPanel extends BaseChatToolWindowTabPanel {
|
|||
@Override
|
||||
protected JComponent getLandingView() {
|
||||
return new StandardChatToolWindowLandingPanel((action, locationOnScreen) -> {
|
||||
var editor = EditorUtils.getSelectedEditor(project);
|
||||
var editor = EditorUtil.getSelectedEditor(project);
|
||||
if (editor == null || !editor.getSelectionModel().hasSelection()) {
|
||||
OverlayUtils.showWarningBalloon(
|
||||
OverlayUtil.showWarningBalloon(
|
||||
editor == null ? "Unable to locate a selected editor"
|
||||
: "Please select a target code before proceeding",
|
||||
locationOnScreen);
|
||||
return;
|
||||
}
|
||||
|
||||
var fileExtension = FileUtils.getFileExtension(
|
||||
var fileExtension = FileUtil.getFileExtension(
|
||||
((EditorImpl) editor).getVirtualFile().getName());
|
||||
var message = new Message(action.getPrompt().replace(
|
||||
"{{selectedCode}}",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.conversations;
|
||||
|
||||
import static ee.carlrobert.codegpt.util.ThemeUtils.getPanelBackgroundColor;
|
||||
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.JBColor;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
|
|||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ApplicationUtils {
|
||||
public class ApplicationUtil {
|
||||
|
||||
public static boolean isUnitTestingMode() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
|
|
@ -2,9 +2,9 @@ package ee.carlrobert.codegpt.util;
|
|||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import ee.carlrobert.codegpt.util.file.FileUtils;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
|
||||
public class DownloadingUtils {
|
||||
public class DownloadingUtil {
|
||||
|
||||
private static final int BYTES_IN_MB = 1024 * 1024;
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ public class DownloadingUtils {
|
|||
|
||||
return format(
|
||||
"%s of %s (%.2f%%), Speed: %.2f MB/sec, Time left: %s",
|
||||
FileUtils.convertFileSize((long) downloadedMB * BYTES_IN_MB),
|
||||
FileUtils.convertFileSize((long) totalMB * BYTES_IN_MB),
|
||||
FileUtil.convertFileSize((long) downloadedMB * BYTES_IN_MB),
|
||||
FileUtil.convertFileSize((long) totalMB * BYTES_IN_MB),
|
||||
percent,
|
||||
speed,
|
||||
getTimeLeftFormattedString(speed, remainingMB));
|
||||
|
|
@ -20,7 +20,7 @@ import java.time.format.DateTimeFormatter;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class EditorUtils {
|
||||
public final class EditorUtil {
|
||||
|
||||
public static Editor createEditor(@NotNull Project project, String fileExtension, String code) {
|
||||
var timestamp = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
|
||||
|
|
@ -53,7 +53,7 @@ public final class EditorUtils {
|
|||
}
|
||||
|
||||
public static @Nullable String getSelectedEditorSelectedText(@NotNull Project project) {
|
||||
var selectedEditor = EditorUtils.getSelectedEditor(project);
|
||||
var selectedEditor = EditorUtil.getSelectedEditor(project);
|
||||
if (selectedEditor != null) {
|
||||
return selectedEditor.getSelectionModel().getSelectedText();
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MarkdownUtils {
|
||||
public class MarkdownUtil {
|
||||
|
||||
/**
|
||||
* Splits a given string into a list of strings where each element is either a code block
|
||||
|
|
@ -33,7 +33,7 @@ import java.awt.event.MouseEvent;
|
|||
import javax.swing.JComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class OverlayUtils {
|
||||
public class OverlayUtil {
|
||||
|
||||
public static void showNotification(String content, NotificationType type) {
|
||||
Notifications.Bus.notify(
|
||||
|
|
@ -134,7 +134,7 @@ public class OverlayUtils {
|
|||
locationOnScreen.y = locationOnScreen.y - 16;
|
||||
|
||||
showWarningBalloon(
|
||||
EditorUtils.getSelectedEditor(requireNonNull(event.getProject())) == null
|
||||
EditorUtil.getSelectedEditor(requireNonNull(event.getProject())) == null
|
||||
? "Unable to locate a selected editor"
|
||||
: "Please select a target code before proceeding",
|
||||
locationOnScreen);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package ee.carlrobert.codegpt.util;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import java.awt.Color;
|
||||
|
||||
public class ThemeUtils {
|
||||
|
||||
public static Color getPanelBackgroundColor() {
|
||||
var panelBg = UIUtil.getPanelBackground();
|
||||
return UIUtil.isUnderDarcula() ? toDarker(panelBg) : panelBg.brighter();
|
||||
}
|
||||
|
||||
private static Color toDarker(Color color) {
|
||||
var factor = 0.9;
|
||||
return new Color(
|
||||
Math.max((int) (color.getRed() * factor), 0),
|
||||
Math.max((int) (color.getGreen() * factor), 0),
|
||||
Math.max((int) (color.getBlue() * factor), 0),
|
||||
color.getAlpha());
|
||||
}
|
||||
|
||||
public static String getRGB(Color color) {
|
||||
return format("rgb(%d, %d, %d)", color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,17 @@
|
|||
package ee.carlrobert.codegpt.util;
|
||||
|
||||
import static com.intellij.util.ui.UIUtil.isUnderDarcula;
|
||||
import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
|
||||
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.util.ui.UI;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.components.SmartScroller;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.BorderFactory;
|
||||
|
|
@ -25,10 +28,10 @@ import javax.swing.ScrollPaneConstants;
|
|||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
|
||||
public class SwingUtils {
|
||||
public class UIUtil {
|
||||
|
||||
public static JTextPane createTextPane(String text) {
|
||||
return createTextPane(text, SwingUtils::handleHyperlinkClicked);
|
||||
return createTextPane(text, UIUtil::handleHyperlinkClicked);
|
||||
}
|
||||
|
||||
public static JTextPane createTextPane(String text, HyperlinkListener listener) {
|
||||
|
|
@ -72,25 +75,26 @@ public class SwingUtils {
|
|||
}
|
||||
|
||||
public static void handleHyperlinkClicked(HyperlinkEvent event) {
|
||||
if (ACTIVATED.equals(event.getEventType()) && event.getURL() != null) {
|
||||
var url = event.getURL();
|
||||
if (ACTIVATED.equals(event.getEventType()) && url != null) {
|
||||
try {
|
||||
BrowserUtil.browse(event.getURL().toURI());
|
||||
BrowserUtil.browse(url.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addShiftEnterInputMap(JTextArea textArea, Runnable onSubmit) {
|
||||
var enterStroke = KeyStroke.getKeyStroke("ENTER");
|
||||
var shiftEnterStroke = KeyStroke.getKeyStroke("shift ENTER");
|
||||
textArea.getInputMap().put(shiftEnterStroke, "insert-break");
|
||||
textArea.getInputMap().put(enterStroke, "text-submit");
|
||||
textArea.getActionMap().put("text-submit", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onSubmit.run();
|
||||
}
|
||||
});
|
||||
public static void addShiftEnterInputMap(JTextArea textArea, AbstractAction onSubmit) {
|
||||
textArea.getInputMap().put(KeyStroke.getKeyStroke("shift ENTER"), "insert-break");
|
||||
textArea.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "text-submit");
|
||||
textArea.getActionMap().put("text-submit", onSubmit);
|
||||
}
|
||||
|
||||
public static Color getPanelBackgroundColor() {
|
||||
return isUnderDarcula()
|
||||
? ColorUtil.darker(JBColor.PanelBackground, 1)
|
||||
: JBColor.PanelBackground.brighter();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7,7 +7,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
|||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import ee.carlrobert.codegpt.CodeGPTPlugin;
|
||||
import java.io.File;
|
||||
|
|
@ -31,9 +30,9 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FileUtils {
|
||||
public class FileUtil {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(FileUtils.class);
|
||||
private static final Logger LOG = Logger.getInstance(FileUtil.class);
|
||||
|
||||
public static File createFile(String directoryPath, String fileName, String fileContent) {
|
||||
try {
|
||||
|
|
@ -53,7 +52,7 @@ public class FileUtils {
|
|||
long[] bytesRead,
|
||||
long fileSize,
|
||||
ProgressIndicator indicator) throws IOException {
|
||||
FileUtils.tryCreateDirectory(CodeGPTPlugin.getLlamaModelsPath());
|
||||
FileUtil.tryCreateDirectory(CodeGPTPlugin.getLlamaModelsPath());
|
||||
|
||||
try (
|
||||
var readableByteChannel = Channels.newChannel(url.openStream());
|
||||
|
|
@ -80,8 +79,9 @@ public class FileUtils {
|
|||
|
||||
public static void tryCreateDirectory(String directoryPath) {
|
||||
try {
|
||||
if (!FileUtil.exists(directoryPath)) {
|
||||
if (!FileUtil.createDirectory(Path.of(directoryPath).toFile())) {
|
||||
if (!com.intellij.openapi.util.io.FileUtil.exists(directoryPath)) {
|
||||
if (!com.intellij.openapi.util.io.FileUtil.createDirectory(
|
||||
Path.of(directoryPath).toFile())) {
|
||||
throw new IOException("Failed to create directory: " + directoryPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ public class FileUtils {
|
|||
}
|
||||
|
||||
public static String getResourceContent(String name) {
|
||||
try (var stream = Objects.requireNonNull(FileUtils.class.getResourceAsStream(name))) {
|
||||
try (var stream = Objects.requireNonNull(FileUtil.class.getResourceAsStream(name))) {
|
||||
return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read resource", e);
|
||||
Loading…
Add table
Add a link
Reference in a new issue