feat: effectively restored to before glue migration

This commit is contained in:
zaaarf 2024-08-16 02:42:15 +02:00
parent ddf0e4eb71
commit c1fd57421d
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
13 changed files with 207 additions and 84 deletions

View file

@ -21,6 +21,8 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'ch.qos.logback:logback-classic:1.4.12'
implementation files('../../lib/dist/java/build/libs/codemp-0.6.2.jar')
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
}
intellij {

View file

@ -1,7 +1,5 @@
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency=false
# TODO temporary workaround for Kotlin 1.8.20+ (https://jb.gg/intellij-platform-kotlin-oom)
kotlin.incremental.useClasspathSnapshot=false
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache=true
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html

View file

@ -1,35 +1,40 @@
package mp.code.intellij.actions;
import com.intellij.credentialStore.Credentials;
import mp.code.intellij.CodeMP;
import mp.code.intellij.settings.CodeMPSettings;
import mp.code.intellij.util.ActionUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import mp.code.exceptions.CodeMPException;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class ConnectAction extends AnAction {
public static void connect(AnActionEvent e, String url, String username, String password, boolean silent) throws CodeMPException {
System.out.printf("%s %s %s", url, username, password);
CodeMP.connect(url, username, password);
public static void connect(AnActionEvent e, boolean silent) throws NullPointerException, CodeMPException {
CodeMPSettings.State state = Objects.requireNonNull(CodeMPSettings.getInstance().getState());
Credentials creds = Objects.requireNonNull(state.getCredentials());
CodeMP.connect(
Objects.requireNonNull(state.getServerUrl()),
Objects.requireNonNull(creds.getUserName()),
Objects.requireNonNull(creds.getPasswordAsString())
);
if(!silent) ActionUtil.notify(e,
"Success", String.format("Connected to %s!", url));
CodeMP.LOGGER.debug("Connected to {}!", url);
"Success", String.format("Connected to %s!", state.getServerUrl()));
CodeMP.LOGGER.debug("Connected to {}!", state.getServerUrl());
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
/*
LoginDialog dialog = new LoginDialog(e.getProject(), "Please input your login credentials!", "Connect to CodeMP server");
if(dialog.showAndGet()) {
try {
connect(e, dialog.urlField.getText(), dialog.usernameField.getText(), dialog.passwordField.getText(), false);
connect(e, false);
} catch(NullPointerException ex) {
ActionUtil.notifyError(e, "Invalid credentials!", "Please configure your credentials before connecting.");
} catch(Exception exception) {
ActionUtil.notifyError(
e,
String.format("Failed to connect to %s!", dialog.urlField.getText()),
exception
);
}
}*/
ActionUtil.notifyError(e, "Failed to connect to server!", exception);
}
}
}

View file

@ -1,24 +0,0 @@
package mp.code.intellij.actions;
import mp.code.intellij.CodeMP;
import mp.code.intellij.actions.workspace.WorkspaceJoinAction;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import mp.code.exceptions.CodeMPException;
import org.jetbrains.annotations.NotNull;
/**
* Used exclusively to streamline debugging.
*/
public class FastForwardAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
try {
ConnectAction.connect(e, "http://alemi.dev:50053", "", "", true);
WorkspaceJoinAction.join(e, "glue", true);
CodeMP.LOGGER.debug("Completed quick startup for testing!");
} catch(CodeMPException ex) {
throw new RuntimeException(ex);
}
}
}

View file

@ -10,8 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class WorkspaceLeaveAction extends AnAction {
public static void leave(AnActionEvent e, String workspaceId, boolean silent) {
//CodeMP.getClient("leave workspace").leaveWorkspace(workspaceId);
// TODO
CodeMP.getClient("leave workspace").leaveWorkspace(workspaceId);
Disposer.dispose(CodeMP.ACTIVE_WORKSPACES.remove(workspaceId));
if(!silent) ActionUtil.notify(e, "Success", String.format("Left workspace %s!", workspaceId));

View file

@ -1,5 +1,6 @@
package mp.code.intellij.listeners;
import lombok.SneakyThrows;
import mp.code.intellij.CodeMP;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.event.DocumentEvent;
@ -10,6 +11,7 @@ import mp.code.exceptions.CodeMPException;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.OptionalLong;
public class BufferEventListener implements DocumentListener {
@ -20,6 +22,7 @@ public class BufferEventListener implements DocumentListener {
}
@Override
@SneakyThrows
public void documentChanged(@NotNull DocumentEvent event) {
CodeMP.LOGGER.debug("Changed {} to {} at offset {}",
event.getOldFragment(), event.getNewFragment(), event.getOffset());
@ -32,15 +35,11 @@ public class BufferEventListener implements DocumentListener {
//TODO move actions break
int changeOffset = event.getOffset();
CharSequence newFragment = event.getNewFragment();
try {
this.controller.send(new TextChange(
changeOffset,
changeOffset + event.getOldFragment().length(),
newFragment.toString(),
0L
OptionalLong.empty()
));
} catch(CodeMPException ignored) {
// TODO actually give a shit
}
}
}

View file

@ -1,5 +1,6 @@
package mp.code.intellij.listeners;
import lombok.SneakyThrows;
import mp.code.intellij.CodeMP;
import mp.code.intellij.util.FileUtil;
import com.intellij.openapi.editor.Caret;
@ -9,7 +10,6 @@ import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener;
import mp.code.CursorController;
import mp.code.data.Cursor;
import mp.code.exceptions.CodeMPException;
import org.jetbrains.annotations.NotNull;
public class CursorEventListener implements CaretListener {
@ -21,6 +21,7 @@ public class CursorEventListener implements CaretListener {
}
@Override
@SneakyThrows
public void caretPositionChanged(@NotNull CaretEvent event) {
Caret caret = event.getCaret();
if(caret == null)
@ -33,7 +34,6 @@ public class CursorEventListener implements CaretListener {
);
Editor editor = event.getEditor();
try {
this.controller.send(new Cursor(
startPos.line,
startPos.column,
@ -42,8 +42,5 @@ public class CursorEventListener implements CaretListener {
FileUtil.getRelativePath(editor.getProject(), editor.getVirtualFile()),
null
));
} catch(CodeMPException e) {
// TODO zzzzz
}
}
}

View file

@ -27,7 +27,7 @@ public class WorkspaceFileClosedListener implements FileEditorManagerListener.Be
Disposable disp = this.task.activeBuffers.remove(path);
if(disp == null) return;
// TODO : this.handler.detachFromBuffer(path);
this.handler.detachFromBuffer(path);
Disposer.dispose(disp);
}
}

View file

@ -0,0 +1,48 @@
package mp.code.intellij.settings;
import com.intellij.credentialStore.CredentialAttributes;
import com.intellij.credentialStore.CredentialAttributesKt;
import com.intellij.credentialStore.Credentials;
import com.intellij.ide.passwordSafe.PasswordSafe;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@State(
name = "mp.code.intellij.settings.CodeMPSettings",
storages = @Storage("codemp.xml")
)
public class CodeMPSettings implements PersistentStateComponent<CodeMPSettings.State> {
private State currentState = new State();
public static CodeMPSettings getInstance() {
return ApplicationManager.getApplication()
.getService(CodeMPSettings.class);
}
@Override
public State getState() {
return this.currentState;
}
@Override
public void loadState(@NotNull State state) {
this.currentState = state;
}
private static final String KEY = "cred";
static CredentialAttributes createCredentialAttributes() {
return new CredentialAttributes(CredentialAttributesKt.generateServiceName("CodeMP", KEY));
}
public static class State {
@Getter String serverUrl;
public @Nullable Credentials getCredentials() {
CredentialAttributes attr = createCredentialAttributes();
return PasswordSafe.getInstance().get(attr);
}
}
}

View file

@ -0,0 +1,96 @@
package mp.code.intellij.settings;
import com.intellij.credentialStore.CredentialAttributes;
import com.intellij.credentialStore.Credentials;
import com.intellij.credentialStore.OneTimeString;
import com.intellij.ide.passwordSafe.PasswordSafe;
import com.intellij.openapi.options.Configurable;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPasswordField;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Objects;
final class CodeMPSettingsConfigurable implements Configurable {
private Component component;
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "CodeMP";
}
@Override
public JComponent getPreferredFocusedComponent() {
return this.component.serverUrlField;
}
@Nullable
@Override
public JComponent createComponent() {
this.component = new Component();
return component.mainPanel;
}
@Override
public boolean isModified() {
CodeMPSettings.State state = Objects.requireNonNull(CodeMPSettings.getInstance().getState());
Credentials creds = state.getCredentials();
return !this.component.serverUrlField.getText().equals(state.serverUrl)
|| (creds == null && (this.component.userNameField.getText() != null || this.component.passwordField.getPassword() != null))
|| creds != null && (
!Objects.equals(creds.getUserName(), this.component.userNameField.getText())
|| !Objects.equals(creds.getPassword(), new OneTimeString(this.component.passwordField.getPassword()))
);
}
@Override
public void apply() {
CodeMPSettings.State state = Objects.requireNonNull(CodeMPSettings.getInstance().getState());
state.serverUrl = this.component.serverUrlField.getText();
CredentialAttributes attributes = CodeMPSettings.createCredentialAttributes();
PasswordSafe.getInstance().set(attributes, new Credentials(
this.component.userNameField.getText(),
this.component.passwordField.getPassword()
));
}
@Override
public void reset() {
CodeMPSettings.State state = Objects.requireNonNull(CodeMPSettings.getInstance().getState());
this.component.serverUrlField.setText(state.serverUrl);
Credentials cred = state.getCredentials();
if(cred != null) {
this.component.userNameField.setText(cred.getUserName());
this.component.passwordField.setText(cred.getPasswordAsString());
}
}
@Override
public void disposeUIResources() {
this.component = null;
}
private static class Component {
final JPanel mainPanel;
final JBTextField serverUrlField = new JBTextField();
final JBTextField userNameField = new JBTextField();
final JBPasswordField passwordField = new JBPasswordField();
Component() {
this.mainPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(new JBLabel("Server address:"), this.serverUrlField, 1, false)
.addLabeledComponent(new JBLabel("Username:"), this.userNameField, 1, false)
.addLabeledComponent(new JBLabel("Password:"), this.passwordField, 1, false)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
}
}
}

View file

@ -1,5 +1,6 @@
package mp.code.intellij.task;
import lombok.SneakyThrows;
import mp.code.intellij.CodeMP;
import mp.code.intellij.util.FileUtil;
import com.intellij.openapi.Disposable;
@ -32,15 +33,13 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
}
@Override
@SneakyThrows
@SuppressWarnings("InfiniteLoopStatement")
public void run(@NotNull ProgressIndicator indicator) {
while(true) {
Optional<BufferController> bufferOptional;
try {
bufferOptional = this.handler.selectBuffer(100L);
} catch(CodeMPException e) {
bufferOptional = Optional.empty(); // TODO error handling
}
if(bufferOptional.isEmpty())
continue;
BufferController buffer = bufferOptional.get();

View file

@ -1,5 +1,7 @@
package mp.code.intellij.task;
import lombok.SneakyThrows;
import mp.code.exceptions.DeadlockedException;
import mp.code.intellij.CodeMP;
import mp.code.intellij.util.ColorUtil;
import mp.code.intellij.util.FileUtil;
@ -23,7 +25,7 @@ import java.awt.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
//TODO this is janky as it shows a progress bar it doesn't use tbh
//TODO this is janky as it shows a progress bar it doesn't use
//implements disposable so i can use it as lifetime ig
public class CursorEventAwaiterTask extends Task.Backgroundable implements Disposable {
private final CursorController handler;
@ -35,15 +37,12 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
}
@Override
@SneakyThrows
@SuppressWarnings("InfiniteLoopStatement")
public void run(@NotNull ProgressIndicator indicator) {
while(true) {
Cursor event;
try {
event = this.handler.recv();
} catch(CodeMPException ex) {
continue; // TODO proper handling
}
Editor editor = FileUtil.getActiveEditorByPath(this.myProject, event.buffer);
if(editor == null)
continue;

View file

@ -10,8 +10,7 @@
<actions>
<group id="codemp" text="CodeMP" popup="true">
<add-to-group group-id="ToolsMenu" anchor="first"/>
<action id="codemp.fast-forward" class="mp.code.intellij.actions.FastForwardAction" text="Just Hurry"/>
<action id="codemp.connect" class="mp.code.intellij.actions.ConnectAction" text="Connect..."/>
<action id="codemp.connect" class="mp.code.intellij.actions.ConnectAction" text="Connect"/>
<action id="codemp.disconnect" class="mp.code.intellij.actions.DisconnectAction" text="Disconnect"/>
<action id="codemp.workspace.join" class="mp.code.intellij.actions.workspace.WorkspaceJoinAction"
text="Join Workspace"/>
@ -22,5 +21,11 @@
<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="CodeMP" displayType="BALLOON"/>
<applicationService serviceImplementation="mp.code.intellij.settings.CodeMPSettings"/>
<applicationConfigurable
parentId="tools"
instance="mp.code.intellij.settings.CodeMPSettingsConfigurable"
id="mp.code.intellij.settings.CodeMPSettingsConfigurable"
displayName="CodeMP"/>
</extensions>
</idea-plugin>