mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-23 23:54:48 +01:00
chore: general cleanup of now useless RuntimeException wrapping
This commit is contained in:
parent
7ceb7eb998
commit
e64939d156
13 changed files with 98 additions and 120 deletions
|
@ -1,9 +1,5 @@
|
||||||
package com.codemp.intellij;
|
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.editor.Editor;
|
||||||
import com.intellij.openapi.util.SystemInfo;
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
import cz.adamh.utils.NativeUtils;
|
import cz.adamh.utils.NativeUtils;
|
||||||
|
@ -33,7 +29,6 @@ public class CodeMP {
|
||||||
LOGGER.info("Loaded CodeMP library!");
|
LOGGER.info("Loaded CodeMP library!");
|
||||||
loadedLibrary = false;
|
loadedLibrary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ConnectAction extends AnAction {
|
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
|
CodeMP.loadLibrary(); //will only load it the first time
|
||||||
CodeMPHandler.connect(url);
|
CodeMPHandler.connect(url);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.codemp.intellij.actions;
|
package com.codemp.intellij.actions;
|
||||||
|
|
||||||
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.actions.buffer.BufferAttachAction;
|
import com.codemp.intellij.actions.buffer.BufferAttachAction;
|
||||||
import com.codemp.intellij.actions.workspace.WorkspaceJoinAction;
|
import com.codemp.intellij.actions.workspace.WorkspaceJoinAction;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
|
@ -12,12 +13,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
public class FastForwardAction extends AnAction {
|
public class FastForwardAction extends AnAction {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
try {
|
ConnectAction.connect(e, "http://alemi.dev:50052", true);
|
||||||
ConnectAction.connect(e, "http://alemi.dev:50052", true);
|
WorkspaceJoinAction.join(e, "default", true);
|
||||||
WorkspaceJoinAction.join(e, "default", true);
|
BufferAttachAction.attach(e, "fucl", true);
|
||||||
BufferAttachAction.attach(e, "test", true);
|
CodeMP.LOGGER.debug("Completed quick startup for testing!");
|
||||||
} catch(Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferAttachAction extends AnAction {
|
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);
|
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
||||||
if(!silent) ActionUtil.notify(e, "Success",
|
if(!silent) ActionUtil.notify(e, "Success",
|
||||||
String.format("Successfully attached to buffer to buffer to %s!", buffer)
|
String.format("Successfully attached to buffer to buffer to %s!", buffer)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferCreateAction extends AnAction {
|
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);
|
CodeMPHandler.create(buffer);
|
||||||
if(!silent) ActionUtil.notify(e, "Success",
|
if(!silent) ActionUtil.notify(e, "Success",
|
||||||
String.format("Created buffer %s!", buffer)
|
String.format("Created buffer %s!", buffer)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferCreateWithContentAction extends AnAction {
|
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();
|
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
||||||
CodeMPHandler.createWithContent(buffer, content);
|
CodeMPHandler.createWithContent(buffer, content);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferDetachAction extends AnAction {
|
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);
|
boolean res = CodeMPHandler.detach(buffer);
|
||||||
if(!res) throw new BufferDetachException(buffer);
|
if(!res) throw new BufferDetachException(buffer);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class WorkspaceJoinAction extends AnAction {
|
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);
|
CursorHandler cursorHandler = CodeMPHandler.join(workspace);
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(e,
|
if(!silent) ActionUtil.notify(e,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class WorkspaceLeaveAction extends AnAction {
|
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();
|
CodeMPHandler.leaveWorkspace();
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(e, "Success", "Left workspace");
|
if(!silent) ActionUtil.notify(e, "Success", "Left workspace");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.codemp.intellij.listeners;
|
package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
|
import com.codemp.intellij.exceptions.CodeMPException;
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
import com.codemp.intellij.jni.BufferHandler;
|
||||||
import com.intellij.openapi.command.CommandProcessor;
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||||
|
@ -16,7 +17,7 @@ public class BufferEventListener implements DocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void documentChanged(@NotNull DocumentEvent event) {
|
public void documentChanged(@NotNull DocumentEvent event) throws CodeMPException {
|
||||||
CodeMP.LOGGER.debug("Changed {} to {} at offset {}",
|
CodeMP.LOGGER.debug("Changed {} to {} at offset {}",
|
||||||
event.getOldFragment(), event.getNewFragment(), event.getOffset());
|
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"))
|
if(group instanceof String groupString && groupString.startsWith("codemp-buffer-receive"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try { //TODO move actions break
|
//TODO move actions break
|
||||||
int changeOffset = event.getOffset();
|
int changeOffset = event.getOffset();
|
||||||
CharSequence newFragment = event.getNewFragment();
|
CharSequence newFragment = event.getNewFragment();
|
||||||
this.bufferHandler.send(changeOffset,
|
this.bufferHandler.send(changeOffset,
|
||||||
changeOffset + event.getOldFragment().length(),
|
changeOffset + event.getOldFragment().length(),
|
||||||
newFragment.toString());
|
newFragment.toString());
|
||||||
} catch(Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,18 +22,14 @@ public class CursorEventListener implements CaretListener {
|
||||||
if(caret == null)
|
if(caret == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
VisualPosition startPos = caret.getSelectionStartPosition();
|
||||||
VisualPosition startPos = caret.getSelectionStartPosition();
|
VisualPosition endPos = caret.getSelectionEndPosition();
|
||||||
VisualPosition endPos = caret.getSelectionEndPosition();
|
CodeMP.LOGGER.debug("Caret moved from {}x {}y to {}x {}y",
|
||||||
CodeMP.LOGGER.debug("Caret moved from {}x {}y to {}x {}y",
|
startPos.line, startPos.column, endPos.line, endPos.column);
|
||||||
startPos.line, startPos.column, endPos.line, endPos.column);
|
this.cursorHandler.send(
|
||||||
this.cursorHandler.send(
|
CodeMP.ACTIVE_BUFFERS_REVERSE.get(event.getEditor()),
|
||||||
CodeMP.ACTIVE_BUFFERS_REVERSE.get(event.getEditor()),
|
startPos.line, startPos.column,
|
||||||
startPos.line, startPos.column,
|
endPos.line, endPos.column
|
||||||
endPos.line, endPos.column
|
);
|
||||||
);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,44 +59,40 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
String buffer = CodeMPHandler.selectBuffer();
|
||||||
String buffer = CodeMPHandler.selectBuffer();
|
BufferHandler handler = CodeMPHandler.getBuffer(buffer);
|
||||||
BufferHandler handler = CodeMPHandler.getBuffer(buffer);
|
|
||||||
|
|
||||||
List<TextChangeWrapper> changeList = new ArrayList<>();
|
List<TextChangeWrapper> changeList = new ArrayList<>();
|
||||||
while(true) {
|
while(true) {
|
||||||
Optional<TextChangeWrapper> changeOptional;
|
Optional<TextChangeWrapper> changeOptional;
|
||||||
try {
|
try {
|
||||||
changeOptional = handler.tryRecv();
|
changeOptional = handler.tryRecv();
|
||||||
} catch(DeadlockedException e) {
|
} catch(DeadlockedException e) {
|
||||||
CodeMP.LOGGER.error(e.getMessage());
|
CodeMP.LOGGER.error(e.getMessage());
|
||||||
continue;
|
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);
|
|
||||||
}
|
}
|
||||||
|
if(changeOptional.isEmpty())
|
||||||
Editor bufferEditor = CodeMP.ACTIVE_BUFFERS.get(buffer);
|
break;
|
||||||
|
TextChangeWrapper change = changeOptional.get();
|
||||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
||||||
ApplicationManager.getApplication().runWriteAction(() ->
|
change.getContent(), change.getStart(), change.getEnd());
|
||||||
CommandProcessor.getInstance().executeCommand(
|
changeList.add(change);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch(Exception ex) {
|
||||||
TaskManager.nullBufferTask();
|
TaskManager.nullBufferTask();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.codemp.intellij.task;
|
package com.codemp.intellij.task;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
|
import com.codemp.intellij.exceptions.CodeMPException;
|
||||||
import com.codemp.intellij.jni.CursorEventWrapper;
|
import com.codemp.intellij.jni.CursorEventWrapper;
|
||||||
import com.codemp.intellij.jni.CursorHandler;
|
import com.codemp.intellij.jni.CursorHandler;
|
||||||
import com.codemp.intellij.util.ColorUtil;
|
import com.codemp.intellij.util.ColorUtil;
|
||||||
|
@ -41,54 +42,48 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
||||||
assert myProject != null; //will never fail
|
assert myProject != null; //will never fail
|
||||||
try {
|
try {
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
CursorEventWrapper event = handler.recv();
|
||||||
CursorEventWrapper event = handler.recv();
|
|
||||||
|
|
||||||
Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer());
|
Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer());
|
||||||
if(editor == null)
|
if(editor == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CodeMP.LOGGER.debug(
|
CodeMP.LOGGER.debug(
|
||||||
"Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!",
|
"Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!",
|
||||||
event.getUser(),
|
event.getUser(),
|
||||||
event.getStartCol(), event.getStartCol(),
|
event.getStartCol(), event.getStartCol(),
|
||||||
event.getEndRow(), event.getEndCol(),
|
event.getEndRow(), event.getEndCol(),
|
||||||
event.getBuffer());
|
event.getBuffer());
|
||||||
|
|
||||||
int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
||||||
int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
||||||
|
|
||||||
ApplicationManager.getApplication().invokeLater(() -> {
|
ApplicationManager.getApplication().invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
RangeHighlighter highlighter = this.highlighterMap.get(event.getUser());
|
RangeHighlighter highlighter = this.highlighterMap.get(event.getUser());
|
||||||
if(highlighter != null)
|
if(highlighter != null)
|
||||||
highlighter.dispose();
|
highlighter.dispose();
|
||||||
|
|
||||||
this.highlighterMap.put(event.getUser(), editor
|
this.highlighterMap.put(event.getUser(), editor
|
||||||
.getMarkupModel()
|
.getMarkupModel()
|
||||||
.addRangeHighlighter(
|
.addRangeHighlighter(
|
||||||
startOffset,
|
startOffset,
|
||||||
endOffset,
|
endOffset,
|
||||||
HighlighterLayer.SELECTION,
|
HighlighterLayer.SELECTION,
|
||||||
new TextAttributes(
|
new TextAttributes(
|
||||||
null,
|
null,
|
||||||
ColorUtil.colorFromUsername(event.getUser()),
|
ColorUtil.colorFromUsername(event.getUser()),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Font.PLAIN
|
Font.PLAIN
|
||||||
), HighlighterTargetArea.EXACT_RANGE
|
), HighlighterTargetArea.EXACT_RANGE
|
||||||
));
|
));
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(IllegalArgumentException ex) {
|
||||||
//suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF
|
//suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF
|
||||||
if(endOffset - editor.getDocument().getTextLength() != 1)
|
if(endOffset - editor.getDocument().getTextLength() != 1)
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch(Exception ex) {
|
}
|
||||||
throw new RuntimeException(ex);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch(Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(Exception ex) { //exited
|
} catch(Exception ex) { //exited
|
||||||
this.highlighterMap.forEach((s, r) -> r.dispose());
|
this.highlighterMap.forEach((s, r) -> r.dispose());
|
||||||
|
|
Loading…
Reference in a new issue