diff --git a/src/main/java/com/codemp/intellij/CodeMP.java b/src/main/java/com/codemp/intellij/CodeMP.java index 3082c63..1a2b0a6 100644 --- a/src/main/java/com/codemp/intellij/CodeMP.java +++ b/src/main/java/com/codemp/intellij/CodeMP.java @@ -1,9 +1,5 @@ package com.codemp.intellij; -import com.codemp.intellij.exceptions.lib.ChannelException; -import com.codemp.intellij.exceptions.lib.DeadlockedException; -import com.codemp.intellij.exceptions.lib.InvalidStateException; -import com.codemp.intellij.exceptions.lib.TransportException; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.SystemInfo; import cz.adamh.utils.NativeUtils; @@ -33,7 +29,6 @@ public class CodeMP { LOGGER.info("Loaded CodeMP library!"); loadedLibrary = false; } - } } } diff --git a/src/main/java/com/codemp/intellij/actions/ConnectAction.java b/src/main/java/com/codemp/intellij/actions/ConnectAction.java index fdd21f7..8f1154a 100644 --- a/src/main/java/com/codemp/intellij/actions/ConnectAction.java +++ b/src/main/java/com/codemp/intellij/actions/ConnectAction.java @@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class ConnectAction extends AnAction { - public static void connect(AnActionEvent e, String url, boolean silent) throws Exception { + public static void connect(AnActionEvent e, String url, boolean silent) { CodeMP.loadLibrary(); //will only load it the first time CodeMPHandler.connect(url); diff --git a/src/main/java/com/codemp/intellij/actions/FastForwardAction.java b/src/main/java/com/codemp/intellij/actions/FastForwardAction.java index 066e9f9..ea351d9 100644 --- a/src/main/java/com/codemp/intellij/actions/FastForwardAction.java +++ b/src/main/java/com/codemp/intellij/actions/FastForwardAction.java @@ -1,5 +1,6 @@ package com.codemp.intellij.actions; +import com.codemp.intellij.CodeMP; import com.codemp.intellij.actions.buffer.BufferAttachAction; import com.codemp.intellij.actions.workspace.WorkspaceJoinAction; import com.intellij.openapi.actionSystem.AnAction; @@ -12,12 +13,9 @@ import org.jetbrains.annotations.NotNull; public class FastForwardAction extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { - try { - ConnectAction.connect(e, "http://alemi.dev:50052", true); - WorkspaceJoinAction.join(e, "default", true); - BufferAttachAction.attach(e, "test", true); - } catch(Exception ex) { - throw new RuntimeException(ex); - } + ConnectAction.connect(e, "http://alemi.dev:50052", true); + WorkspaceJoinAction.join(e, "default", true); + BufferAttachAction.attach(e, "fucl", true); + CodeMP.LOGGER.debug("Completed quick startup for testing!"); } } diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferAttachAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferAttachAction.java index 4295c3f..3912a0e 100644 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferAttachAction.java +++ b/src/main/java/com/codemp/intellij/actions/buffer/BufferAttachAction.java @@ -12,7 +12,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class BufferAttachAction extends AnAction { - public static void attach(AnActionEvent e, String buffer, boolean silent) throws Exception { + public static void attach(AnActionEvent e, String buffer, boolean silent) { BufferHandler bufferHandler = CodeMPHandler.attach(buffer); if(!silent) ActionUtil.notify(e, "Success", String.format("Successfully attached to buffer to buffer to %s!", buffer) diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java index c425bd2..0db6055 100644 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java +++ b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java @@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class BufferCreateAction extends AnAction { - public static void create(AnActionEvent e, String buffer, boolean silent) throws Exception { + public static void create(AnActionEvent e, String buffer, boolean silent) { CodeMPHandler.create(buffer); if(!silent) ActionUtil.notify(e, "Success", String.format("Created buffer %s!", buffer) diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java index b593957..80df1d5 100644 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java +++ b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; public class BufferCreateWithContentAction extends AnAction { - public static void createWithContent(AnActionEvent event, String buffer, boolean silent) throws Exception { + public static void createWithContent(AnActionEvent event, String buffer, boolean silent) { String content = ActionUtil.getCurrentEditor(event).getDocument().getText(); CodeMPHandler.createWithContent(buffer, content); diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java index 428d902..a96bb86 100644 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java +++ b/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java @@ -12,7 +12,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class BufferDetachAction extends AnAction { - public static void detach(AnActionEvent e, String buffer, boolean silent) throws Exception { + public static void detach(AnActionEvent e, String buffer, boolean silent) { boolean res = CodeMPHandler.detach(buffer); if(!res) throw new BufferDetachException(buffer); diff --git a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java index 8139c2a..9375c41 100644 --- a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java +++ b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java @@ -14,7 +14,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class WorkspaceJoinAction extends AnAction { - public static void join(AnActionEvent e, String workspace, boolean silent) throws Exception { + public static void join(AnActionEvent e, String workspace, boolean silent) { CursorHandler cursorHandler = CodeMPHandler.join(workspace); if(!silent) ActionUtil.notify(e, diff --git a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java index 971b8e0..19122d9 100644 --- a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java +++ b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java @@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; public class WorkspaceLeaveAction extends AnAction { - public static void leave(AnActionEvent e, boolean silent) throws Exception { + public static void leave(AnActionEvent e, boolean silent) { CodeMPHandler.leaveWorkspace(); if(!silent) ActionUtil.notify(e, "Success", "Left workspace"); diff --git a/src/main/java/com/codemp/intellij/listeners/BufferEventListener.java b/src/main/java/com/codemp/intellij/listeners/BufferEventListener.java index 707ff87..1f35d94 100644 --- a/src/main/java/com/codemp/intellij/listeners/BufferEventListener.java +++ b/src/main/java/com/codemp/intellij/listeners/BufferEventListener.java @@ -1,6 +1,7 @@ package com.codemp.intellij.listeners; import com.codemp.intellij.CodeMP; +import com.codemp.intellij.exceptions.CodeMPException; import com.codemp.intellij.jni.BufferHandler; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.event.DocumentEvent; @@ -16,7 +17,7 @@ public class BufferEventListener implements DocumentListener { } @Override - public void documentChanged(@NotNull DocumentEvent event) { + public void documentChanged(@NotNull DocumentEvent event) throws CodeMPException { CodeMP.LOGGER.debug("Changed {} to {} at offset {}", event.getOldFragment(), event.getNewFragment(), event.getOffset()); @@ -24,14 +25,11 @@ public class BufferEventListener implements DocumentListener { if(group instanceof String groupString && groupString.startsWith("codemp-buffer-receive")) return; - try { //TODO move actions break - int changeOffset = event.getOffset(); - CharSequence newFragment = event.getNewFragment(); - this.bufferHandler.send(changeOffset, - changeOffset + event.getOldFragment().length(), - newFragment.toString()); - } catch(Exception e) { - throw new RuntimeException(e); - } + //TODO move actions break + int changeOffset = event.getOffset(); + CharSequence newFragment = event.getNewFragment(); + this.bufferHandler.send(changeOffset, + changeOffset + event.getOldFragment().length(), + newFragment.toString()); } } diff --git a/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java b/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java index b482904..b400ccf 100644 --- a/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java +++ b/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java @@ -22,18 +22,14 @@ public class CursorEventListener implements CaretListener { if(caret == null) return; - try { - VisualPosition startPos = caret.getSelectionStartPosition(); - VisualPosition endPos = caret.getSelectionEndPosition(); - CodeMP.LOGGER.debug("Caret moved from {}x {}y to {}x {}y", - startPos.line, startPos.column, endPos.line, endPos.column); - this.cursorHandler.send( - CodeMP.ACTIVE_BUFFERS_REVERSE.get(event.getEditor()), - startPos.line, startPos.column, - endPos.line, endPos.column - ); - } catch(Exception ex) { - throw new RuntimeException(ex); - } + VisualPosition startPos = caret.getSelectionStartPosition(); + VisualPosition endPos = caret.getSelectionEndPosition(); + CodeMP.LOGGER.debug("Caret moved from {}x {}y to {}x {}y", + startPos.line, startPos.column, endPos.line, endPos.column); + this.cursorHandler.send( + CodeMP.ACTIVE_BUFFERS_REVERSE.get(event.getEditor()), + startPos.line, startPos.column, + endPos.line, endPos.column + ); } } diff --git a/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java b/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java index c1820d1..caacf51 100644 --- a/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java +++ b/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java @@ -59,44 +59,40 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo try { while(true) { - try { - String buffer = CodeMPHandler.selectBuffer(); - BufferHandler handler = CodeMPHandler.getBuffer(buffer); + String buffer = CodeMPHandler.selectBuffer(); + BufferHandler handler = CodeMPHandler.getBuffer(buffer); - List changeList = new ArrayList<>(); - while(true) { - Optional changeOptional; - try { - changeOptional = handler.tryRecv(); - } catch(DeadlockedException e) { - CodeMP.LOGGER.error(e.getMessage()); - continue; - } - if(changeOptional.isEmpty()) - break; - TextChangeWrapper change = changeOptional.get(); - CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!", - change.getContent(), change.getStart(), change.getEnd()); - changeList.add(change); + List changeList = new ArrayList<>(); + while(true) { + Optional changeOptional; + try { + changeOptional = handler.tryRecv(); + } catch(DeadlockedException e) { + CodeMP.LOGGER.error(e.getMessage()); + continue; } - - Editor bufferEditor = CodeMP.ACTIVE_BUFFERS.get(buffer); - - ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> - ApplicationManager.getApplication().runWriteAction(() -> - CommandProcessor.getInstance().executeCommand( - this.myProject, - () -> changeList.forEach((change) -> - bufferEditor.getDocument().replaceString( - (int) change.getStart(), (int) change.getEnd(), change.getContent()) - ), - "CodeMPBufferReceive", - "codemp-buffer-receive", //TODO: mark this with the name - bufferEditor.getDocument() - ))); - } catch(Exception ex) { - throw new RuntimeException(ex); + if(changeOptional.isEmpty()) + break; + TextChangeWrapper change = changeOptional.get(); + CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!", + change.getContent(), change.getStart(), change.getEnd()); + changeList.add(change); } + + Editor bufferEditor = CodeMP.ACTIVE_BUFFERS.get(buffer); + + ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> + ApplicationManager.getApplication().runWriteAction(() -> + CommandProcessor.getInstance().executeCommand( + this.myProject, + () -> changeList.forEach((change) -> + bufferEditor.getDocument().replaceString( + (int) change.getStart(), (int) change.getEnd(), change.getContent()) + ), + "CodeMPBufferReceive", + "codemp-buffer-receive", //TODO: mark this with the name + bufferEditor.getDocument() + ))); } } catch(Exception ex) { TaskManager.nullBufferTask(); diff --git a/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java b/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java index 0541352..9a28c20 100644 --- a/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java +++ b/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java @@ -1,6 +1,7 @@ package com.codemp.intellij.task; import com.codemp.intellij.CodeMP; +import com.codemp.intellij.exceptions.CodeMPException; import com.codemp.intellij.jni.CursorEventWrapper; import com.codemp.intellij.jni.CursorHandler; import com.codemp.intellij.util.ColorUtil; @@ -41,54 +42,48 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo assert myProject != null; //will never fail try { while(true) { - try { - CursorEventWrapper event = handler.recv(); + CursorEventWrapper event = handler.recv(); - Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer()); - if(editor == null) - continue; + Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer()); + if(editor == null) + continue; - CodeMP.LOGGER.debug( - "Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!", - event.getUser(), - event.getStartCol(), event.getStartCol(), - event.getEndRow(), event.getEndCol(), - event.getBuffer()); + CodeMP.LOGGER.debug( + "Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!", + event.getUser(), + event.getStartCol(), event.getStartCol(), + event.getEndRow(), event.getEndCol(), + event.getBuffer()); - int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol(); - int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol(); + int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol(); + int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol(); - ApplicationManager.getApplication().invokeLater(() -> { - try { - RangeHighlighter highlighter = this.highlighterMap.get(event.getUser()); - if(highlighter != null) - highlighter.dispose(); + ApplicationManager.getApplication().invokeLater(() -> { + try { + RangeHighlighter highlighter = this.highlighterMap.get(event.getUser()); + if(highlighter != null) + highlighter.dispose(); - this.highlighterMap.put(event.getUser(), editor - .getMarkupModel() - .addRangeHighlighter( - startOffset, - endOffset, - HighlighterLayer.SELECTION, - new TextAttributes( - null, - ColorUtil.colorFromUsername(event.getUser()), - null, - null, - Font.PLAIN - ), HighlighterTargetArea.EXACT_RANGE - )); - } catch(IllegalArgumentException ex) { - //suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF - if(endOffset - editor.getDocument().getTextLength() != 1) - throw ex; - } catch(Exception ex) { - throw new RuntimeException(ex); - } - }); - } catch(Exception ex) { - throw new RuntimeException(ex); - } + this.highlighterMap.put(event.getUser(), editor + .getMarkupModel() + .addRangeHighlighter( + startOffset, + endOffset, + HighlighterLayer.SELECTION, + new TextAttributes( + null, + ColorUtil.colorFromUsername(event.getUser()), + null, + null, + Font.PLAIN + ), HighlighterTargetArea.EXACT_RANGE + )); + } catch(IllegalArgumentException ex) { + //suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF + if(endOffset - editor.getDocument().getTextLength() != 1) + throw ex; + } + }); } } catch(Exception ex) { //exited this.highlighterMap.forEach((s, r) -> r.dispose());