fix: couple of intellij platform warnings

This commit is contained in:
Carl-Robert Linnupuu 2024-03-13 16:27:26 +02:00
parent 31f96f8642
commit a7610acfa1
17 changed files with 42 additions and 30 deletions

View file

@ -1,6 +1,7 @@
package ee.carlrobert.codegpt;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
@ -25,7 +26,8 @@ public class PluginStartupActivity implements StartupActivity {
EditorActionsUtil.refreshActions();
var authenticationResponse = YouUserManager.getInstance().getAuthenticationResponse();
if (authenticationResponse == null) {
handleYouServiceAuthentication();
ApplicationManager.getApplication()
.executeOnPooledThread(this::handleYouServiceAuthentication);
}
}

View file

@ -12,7 +12,7 @@ public class AskAction extends AnAction {
public AskAction() {
super("New Chat", "Chat with CodeGPT", Icons.Sparkle);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -1,5 +1,6 @@
package ee.carlrobert.codegpt.actions.editor;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
@ -17,7 +18,7 @@ abstract class BaseEditorAction extends AnAction {
@Nullable @NlsActions.ActionDescription String description,
@Nullable Icon icon) {
super(text, description, icon);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
BaseEditorAction(
@ -45,4 +46,9 @@ abstract class BaseEditorAction extends AnAction {
}
event.getPresentation().setEnabled(menuAllowed);
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
}
}

View file

@ -27,7 +27,7 @@ public class CustomPromptAction extends BaseEditorAction {
CustomPromptAction() {
super("Custom Prompt", "Custom prompt description", AllIcons.Actions.Run_anything);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -38,15 +38,14 @@ public class EditorActionsUtil {
return actionsMap.entrySet()
.stream()
.map((entry) -> new String[]{entry.getKey(), entry.getValue()})
.collect(toList())
.toList()
.toArray(new String[0][0]);
}
public static void refreshActions() {
AnAction actionGroup =
ActionManager.getInstance().getAction("action.editor.group.EditorActionGroup");
if (actionGroup instanceof DefaultActionGroup) {
DefaultActionGroup group = (DefaultActionGroup) actionGroup;
if (actionGroup instanceof DefaultActionGroup group) {
group.removeAll();
group.add(new AskAction());
group.add(new CustomPromptAction());
@ -82,12 +81,10 @@ public class EditorActionsUtil {
}
}
public static void registerOrReplaceAction(AnAction action) {
public static void registerAction(AnAction action) {
ActionManager actionManager = ActionManager.getInstance();
var actionId = convertToId(action.getTemplateText());
if (actionManager.getAction(actionId) != null) {
actionManager.replaceAction(actionId, action);
} else {
if (actionManager.getAction(actionId) == null) {
actionManager.registerAction(actionId, action, PluginId.getId("ee.carlrobert.chatgpt"));
}
}

View file

@ -17,7 +17,7 @@ public class ClearChatWindowAction extends AnAction {
public ClearChatWindowAction(Runnable onActionPerformed) {
super("Clear Window", "Clears a chat window", AllIcons.General.Reset);
this.onActionPerformed = onActionPerformed;
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -15,7 +15,7 @@ public class CreateNewConversationAction extends AnAction {
public CreateNewConversationAction(Runnable onCreate) {
super("Create New Chat", "Create new chat", AllIcons.General.Add);
this.onCreate = onCreate;
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -21,7 +21,7 @@ public class DeleteAllConversationsAction extends AnAction {
public DeleteAllConversationsAction(Runnable onRefresh) {
super("Delete All", "Delete all conversations", AllIcons.Actions.GC);
this.onRefresh = onRefresh;
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -19,7 +19,7 @@ public class DeleteConversationAction extends AnAction {
public DeleteConversationAction(Runnable onDelete) {
super("Delete Conversation", "Delete single conversation", AllIcons.Actions.GC);
this.onDelete = onDelete;
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -12,7 +12,7 @@ public class MoveDownAction extends MoveAction {
public MoveDownAction(Runnable onRefresh) {
super("Move Down", "Move Down", AllIcons.Actions.MoveDown, onRefresh);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -12,11 +12,11 @@ public class MoveUpAction extends MoveAction {
public MoveUpAction(Runnable onRefresh) {
super("Move Up", "Move up", AllIcons.Actions.MoveUp, onRefresh);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override
protected Optional<Conversation> getConversation(@NotNull Project project) {
return ConversationService.getInstance().getPreviousConversation();
return ConversationService.getInstance().getNextConversation();
}
}

View file

@ -23,7 +23,7 @@ public class OpenInEditorAction extends AnAction {
public OpenInEditorAction() {
super("Open In Editor", "Open conversation in editor", AllIcons.Actions.SplitVertically);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -15,7 +15,7 @@ public class ReplaceCodeInMainEditorAction extends AnAction {
public ReplaceCodeInMainEditorAction() {
super("Replace in Main Editor", "Replace code in main editor", AllIcons.Actions.Replace);
EditorActionsUtil.registerOrReplaceAction(this);
EditorActionsUtil.registerAction(this);
}
@Override

View file

@ -10,9 +10,7 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
abstract class AbstractCredentialsManager {
private static final PasswordSafe passwordSafe = PasswordSafe.getInstance();
private final Map<String, CredentialAttributes> credentialMapping;
private final Map<String, String> credentialCache = new ConcurrentHashMap<>();
@ -38,7 +36,7 @@ abstract class AbstractCredentialsManager {
return cachedCredential;
}
String credential = passwordSafe.getPassword(credentialMapping.get(key));
String credential = PasswordSafe.getInstance().getPassword(credentialMapping.get(key));
if (credential != null) {
credentialCache.put(key, credential);
}
@ -52,6 +50,6 @@ abstract class AbstractCredentialsManager {
credentialCache.put(key, credential);
}
passwordSafe.setPassword(credentialMapping.get(key), credential);
PasswordSafe.getInstance().setPassword(credentialMapping.get(key), credential);
}
}

View file

@ -6,6 +6,7 @@ import static ee.carlrobert.codegpt.completions.CompletionRequestProvider.COMPLE
import com.intellij.icons.AllIcons;
import com.intellij.icons.AllIcons.Nodes;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.keymap.impl.ui.EditKeymapsDialog;
import com.intellij.openapi.ui.ComponentValidator;
@ -309,6 +310,11 @@ public class ConfigurationComponent {
Arrays.stream(DEFAULT_ACTIONS_ARRAY).forEach(model::addRow);
EditorActionsUtil.refreshActions();
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
}
}
class KeymapActionButton extends AnActionButton {
@ -334,5 +340,10 @@ public class ConfigurationComponent {
}
new EditKeymapsDialog(e.getProject(), actionId, false).show();
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
}
}
}

View file

@ -1,6 +1,5 @@
package ee.carlrobert.codegpt.settings.service.custom;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import com.intellij.ui.ToolbarDecorator;
@ -75,11 +74,10 @@ class CustomServiceFormTabbedPane extends JBTabbedPane {
}
private static Object parseValue(Object value) {
if (!(value instanceof String)) {
if (!(value instanceof String stringValue)) {
return value;
}
var stringValue = (String) value;
try {
return Integer.parseInt(stringValue);
} catch (NumberFormatException e) {
@ -100,7 +98,7 @@ class CustomServiceFormTabbedPane extends JBTabbedPane {
return actionsMap.entrySet()
.stream()
.map((entry) -> new Object[]{entry.getKey(), entry.getValue()})
.collect(toList())
.toList()
.toArray(new Object[0][0]);
}