mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-21 22:54:48 +01:00
chore: a bit of cleanup
This commit is contained in:
parent
5b7d3c95dd
commit
cebcad7327
14 changed files with 102 additions and 52 deletions
|
@ -1,3 +1,8 @@
|
|||
package com.codemp.intellij;
|
||||
|
||||
public class CodeMP {}
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CodeMP {
|
||||
public static Logger LOGGER = LoggerFactory.getLogger(CodeMP.class);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.codemp.intellij.actions;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
@ -11,7 +12,6 @@ import java.io.IOException;
|
|||
|
||||
public class ConnectAction extends AnAction {
|
||||
public ConnectAction() {
|
||||
super();
|
||||
/*try {
|
||||
NativeUtils.loadLibraryFromJar("/resources/libHelloJNI.so");
|
||||
} catch(IOException e) {
|
||||
|
@ -21,19 +21,18 @@ public class ConnectAction extends AnAction {
|
|||
System.load("O:/dev/IRL/Rust/codemp/client/intellij/target/debug/codemp_intellij.dll");
|
||||
}
|
||||
|
||||
public void connect(String url) throws Exception {
|
||||
public static void connect(String url, boolean silent) throws Exception {
|
||||
CodeMPHandler.connect(url);
|
||||
//Messages.showInfoMessage(String.format("Connected to %s!", url), "CodeMP");
|
||||
System.out.printf("Connected to %s!\n", url);
|
||||
if(!silent) Messages.showInfoMessage(String.format("Connected to %s!", url), "CodeMP");
|
||||
CodeMP.LOGGER.debug("Connected to {}!", url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String url = Messages.showInputDialog("URL to CodeMP instance:", "CodeMP Connect",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
this.connect(url);
|
||||
connect(url, false);
|
||||
} catch(Exception ex) {
|
||||
Messages.showErrorDialog(String.format("Failed to connect to %s: %s!", url, ex.getMessage()), "CodeMP");
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ import com.intellij.openapi.actionSystem.AnAction;
|
|||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Used exclusively to streamline debugging.
|
||||
*/
|
||||
public class FastForwardAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
ConnectAction connectAction = new ConnectAction();
|
||||
JoinAction joinAction = new JoinAction();
|
||||
BufferAttachAction attachAction = new BufferAttachAction();
|
||||
try {
|
||||
connectAction.connect("http://alemi.dev:50051");
|
||||
joinAction.join(e, "default");
|
||||
attachAction.attach(e, "test");
|
||||
ConnectAction.connect("http://alemi.dev:50051", true);
|
||||
JoinAction.join(e, "default", true);
|
||||
BufferAttachAction.attach(e, "test", true);
|
||||
} catch(Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.codemp.intellij.actions;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.codemp.intellij.jni.CursorEventWrapper;
|
||||
import com.codemp.intellij.jni.CursorHandler;
|
||||
import com.codemp.intellij.listeners.CursorEventListener;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
|
@ -15,7 +17,6 @@ import com.intellij.openapi.editor.markup.HighlighterLayer;
|
|||
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
|
@ -26,26 +27,25 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JoinAction extends AnAction {
|
||||
|
||||
private final Map<String, RangeHighlighter> highlighterMap = new HashMap<>();
|
||||
private static final Map<String, RangeHighlighter> highlighterMap = new HashMap<>();
|
||||
|
||||
private static final TextAttributes HIGHLIGHTED = new TextAttributes(
|
||||
null, JBColor.BLUE, null, null, Font.PLAIN
|
||||
);
|
||||
|
||||
public void join(AnActionEvent e, String session) throws Exception {
|
||||
public static void join(AnActionEvent e, String session, boolean silent) throws Exception {
|
||||
CursorHandler cursorHandler = CodeMPHandler.join(session);
|
||||
EditorFactory.getInstance()
|
||||
.getEventMulticaster()
|
||||
.addCaretListener(new CursorEventListener());
|
||||
//Messages.showInfoMessage(String.format("Joined %s!", session), "CodeMP");
|
||||
System.out.printf(String.format("Joined %s!\n", session));
|
||||
Editor editor = FileEditorManager.getInstance(Objects.requireNonNull(e.getProject()))
|
||||
.getSelectedTextEditor();
|
||||
assert editor != null;
|
||||
|
||||
if(!silent) Messages.showInfoMessage(String.format("Joined session %s!", session), "CodeMP");
|
||||
else CodeMP.LOGGER.debug("Joined session {}!", session);
|
||||
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
Document document = editor.getDocument();
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(e.getProject(), "Awaiting CodeMP cursor events") {
|
||||
@Override
|
||||
|
@ -59,8 +59,8 @@ public class JoinAction extends AnAction {
|
|||
if(h != null)
|
||||
h.dispose();
|
||||
|
||||
System.out.printf(
|
||||
"Cursor moved by user %s! Start pos: x%d y%d; end pos: x%d y%d with buffer %s!\n",
|
||||
CodeMP.LOGGER.debug(
|
||||
"Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y with buffer {}!",
|
||||
event.getUser(),
|
||||
event.getStartCol(), event.getStartCol(),
|
||||
event.getEndRow(), event.getEndCol(),
|
||||
|
@ -94,7 +94,7 @@ public class JoinAction extends AnAction {
|
|||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
this.join(e, session);
|
||||
join(e, session, false);
|
||||
} catch(Exception ex) {
|
||||
Messages.showErrorDialog(String.format(
|
||||
"Failed to join session %s: %s!",
|
||||
|
|
|
@ -1,37 +1,33 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.BufferHandler;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.codemp.intellij.jni.TextChangeWrapper;
|
||||
import com.codemp.intellij.listeners.BufferEventListener;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.print.Doc;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BufferAttachAction extends AnAction {
|
||||
|
||||
public void attach(AnActionEvent e, String buffer) throws Exception {
|
||||
public static void attach(AnActionEvent e, String buffer, boolean silent) throws Exception {
|
||||
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
||||
//Messages.showInfoMessage(String.format("Connected to %s!", url), "CodeMP");
|
||||
if(!silent) Messages.showInfoMessage(String.format("Attached to buffer to %s!", buffer),
|
||||
"CodeMP Buffer Attach");
|
||||
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
|
||||
|
||||
//register buffer change listener
|
||||
//TODO "get" the Document corresponding to buffer, for now use the current one
|
||||
BufferEventListener listener = new BufferEventListener(buffer);
|
||||
assert e.getProject() != null;
|
||||
Editor editor = FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor();
|
||||
assert editor != null;
|
||||
Document document = editor.getDocument();
|
||||
Document document = ActionUtil.getCurrentEditor(e).getDocument();
|
||||
document.addDocumentListener(listener);
|
||||
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(e.getProject(), "Awaiting CodeMP buffer events") {
|
||||
|
@ -42,7 +38,7 @@ public class BufferAttachAction extends AnAction {
|
|||
TextChangeWrapper event = bufferHandler.recv();
|
||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
System.out.printf("Received text change %s from offset %d to %d!\n",
|
||||
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!\n",
|
||||
event.getContent(), event.getStart(), event.getEnd());
|
||||
document.replaceString( //TODO this doesn't work
|
||||
(int) event.getStart(),
|
||||
|
@ -56,7 +52,6 @@ public class BufferAttachAction extends AnAction {
|
|||
}
|
||||
}
|
||||
});
|
||||
System.out.printf("Created buffer %s!\n", buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,9 +60,8 @@ public class BufferAttachAction extends AnAction {
|
|||
"Buffer name:",
|
||||
"Attach to CodeMP Buffer",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
this.attach(e, buffer);
|
||||
attach(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
Messages.showErrorDialog(String.format(
|
||||
"Failed to attach to buffer %s: %s!",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
@ -7,6 +8,12 @@ import com.intellij.openapi.ui.Messages;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferCreateAction extends AnAction {
|
||||
public static void create(String buffer, boolean silent) throws Exception {
|
||||
CodeMPHandler.create(buffer);
|
||||
if(!silent) Messages.showInfoMessage(String.format("Created buffer %s!", buffer),
|
||||
"Create CodeMP Buffer" );
|
||||
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
|
@ -16,9 +23,7 @@ public class BufferCreateAction extends AnAction {
|
|||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
CodeMPHandler.create(buffer);
|
||||
//Messages.showInfoMessage(String.format("Created buffer %s!", url), "Create CodeMP Buffer" );
|
||||
System.out.printf("Created buffer %s!\n", buffer);
|
||||
create(buffer, false);
|
||||
} catch(Exception ex) {
|
||||
Messages.showErrorDialog(String.format(
|
||||
"Failed to create buffer with name %s: %s!",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.codemp.intellij.exceptions;
|
||||
|
||||
public class CodeMPException extends Exception {
|
||||
public class CodeMPException extends RuntimeException {
|
||||
public CodeMPException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.codemp.intellij.exceptions.ide;
|
||||
|
||||
import com.codemp.intellij.exceptions.CodeMPException;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
/**
|
||||
* Fired when trying to use {@link com.intellij.openapi.actionSystem.AnActionEvent}'s context
|
||||
* from a state where that use is not supported.
|
||||
*/
|
||||
public class BadActionEventStateException extends CodeMPException {
|
||||
public BadActionEventStateException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
package com.codemp.intellij.exceptions;
|
||||
package com.codemp.intellij.exceptions.rust;
|
||||
|
||||
import com.codemp.intellij.exceptions.CodeMPException;
|
||||
|
||||
public class ChannelException extends CodeMPException {
|
||||
public ChannelException(String input) {
|
|
@ -1,4 +1,6 @@
|
|||
package com.codemp.intellij.exceptions;
|
||||
package com.codemp.intellij.exceptions.rust;
|
||||
|
||||
import com.codemp.intellij.exceptions.CodeMPException;
|
||||
|
||||
public class InvalidStateException extends CodeMPException {
|
||||
public InvalidStateException(String message) {
|
|
@ -1,4 +1,6 @@
|
|||
package com.codemp.intellij.exceptions;
|
||||
package com.codemp.intellij.exceptions.rust;
|
||||
|
||||
import com.codemp.intellij.exceptions.CodeMPException;
|
||||
|
||||
public class TransportException extends CodeMPException {
|
||||
public TransportException(String message) {
|
|
@ -1,5 +1,6 @@
|
|||
package com.codemp.intellij.listeners;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
|
@ -10,16 +11,14 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class CursorEventListener implements CaretListener {
|
||||
@Override
|
||||
public void caretPositionChanged(@NotNull CaretEvent event) {
|
||||
System.out.println("called!");
|
||||
Caret caret = event.getCaret();
|
||||
if(caret == null)
|
||||
return;
|
||||
System.out.println("valid caret!");
|
||||
|
||||
try {
|
||||
VisualPosition startPos = caret.getSelectionStartPosition();
|
||||
VisualPosition endPos = caret.getSelectionEndPosition();
|
||||
System.out.printf("start %dx %dy end %dx %dy",
|
||||
CodeMP.LOGGER.debug("Caret moved from {}x {}y to {}x {}y",
|
||||
startPos.line, startPos.column, endPos.line, endPos.column);
|
||||
CodeMPHandler.getCursor().send(
|
||||
"", startPos.line, startPos.column, endPos.line, endPos.column
|
||||
|
|
24
src/main/java/com/codemp/intellij/util/ActionUtil.java
Normal file
24
src/main/java/com/codemp/intellij/util/ActionUtil.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.codemp.intellij.util;
|
||||
|
||||
import com.codemp.intellij.exceptions.ide.BadActionEventStateException;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
public class ActionUtil {
|
||||
public static Project getCurrentProject(AnActionEvent event) {
|
||||
Project project = event.getProject();
|
||||
if(project == null)
|
||||
throw new BadActionEventStateException("Project was null!");
|
||||
return project;
|
||||
}
|
||||
|
||||
public static Editor getCurrentEditor(AnActionEvent event) {
|
||||
Editor editor = FileEditorManager.getInstance(getCurrentProject(event))
|
||||
.getSelectedTextEditor();
|
||||
if(editor == null)
|
||||
throw new BadActionEventStateException("Editor was null!");
|
||||
return editor;
|
||||
}
|
||||
}
|
|
@ -25,12 +25,15 @@
|
|||
<actions>
|
||||
<group id="codemp" text="CodeMP" popup="true">
|
||||
<add-to-group group-id="ToolsMenu" anchor="first"/>
|
||||
<action id="codemp.fast-forward" class="com.codemp.intellij.actions.FastForwardAction" text="Pls hurry"/>
|
||||
<action id="codemp.fast-forward" class="com.codemp.intellij.actions.FastForwardAction" text="Just Hurry"/>
|
||||
<action id="codemp.connect" class="com.codemp.intellij.actions.ConnectAction" text="Connect..."/>
|
||||
<action id="codemp.join" class="com.codemp.intellij.actions.JoinAction" text="Join..."/>
|
||||
<group id="codemp.buffer" text="Buffer" popup="true">
|
||||
<action id="codemp.buffer.create" class="com.codemp.intellij.actions.buffer.BufferCreateAction"
|
||||
text="Create Buffer"/>
|
||||
<action id="codemp.buffer.create-with-content"
|
||||
class="com.codemp.intellij.actions.buffer.BufferCreateWithContentAction"
|
||||
text="Create Buffer with Content"/>
|
||||
<action id="codemp.buffer.attach" class="com.codemp.intellij.actions.buffer.BufferAttachAction"
|
||||
text="Attach to Buffer"/>
|
||||
</group>
|
||||
|
@ -38,8 +41,9 @@
|
|||
</actions>
|
||||
|
||||
<!-- Extension points defined by the plugin.
|
||||
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
|
||||
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
->
|
Loading…
Reference in a new issue