mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-21 22:54:48 +01:00
feat: updated actions
This commit is contained in:
parent
7c5c851f6f
commit
5a42577a1f
17 changed files with 106 additions and 328 deletions
|
@ -10,7 +10,6 @@ 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) {
|
public static void connect(AnActionEvent e, String url, boolean silent) {
|
||||||
CodeMP.connect(url);
|
CodeMP.connect(url);
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(e,
|
if(!silent) ActionUtil.notify(e,
|
||||||
"Success", String.format("Connected to %s!", url));
|
"Success", String.format("Connected to %s!", url));
|
||||||
CodeMP.LOGGER.debug("Connected to {}!", url);
|
CodeMP.LOGGER.debug("Connected to {}!", url);
|
||||||
|
|
|
@ -9,9 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
public class DisconnectAction extends AnAction {
|
public class DisconnectAction extends AnAction {
|
||||||
public static void disconnect(AnActionEvent e, boolean silent) {
|
public static void disconnect(AnActionEvent e, boolean silent) {
|
||||||
String url = CodeMP.getClient("disconnect").getUrl();
|
String url = CodeMP.getClient("disconnect").getUrl();
|
||||||
|
|
||||||
CodeMP.disconnect();
|
CodeMP.disconnect();
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(e,
|
if(!silent) ActionUtil.notify(e,
|
||||||
"Success", String.format("Disconnected from %s!", url));
|
"Success", String.format("Disconnected from %s!", url));
|
||||||
CodeMP.LOGGER.debug("Connected to {}!", url);
|
CodeMP.LOGGER.debug("Connected to {}!", url);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.codemp.intellij.actions;
|
package com.codemp.intellij.actions;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
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;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
@ -15,7 +14,6 @@ public class FastForwardAction extends AnAction {
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
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);
|
|
||||||
CodeMP.LOGGER.debug("Completed quick startup for testing!");
|
CodeMP.LOGGER.debug("Completed quick startup for testing!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package com.codemp.intellij.actions.buffer;
|
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
|
||||||
import com.codemp.intellij.util.ActionUtil;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
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) {
|
|
||||||
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
|
||||||
if(!silent) ActionUtil.notify(e, "Success",
|
|
||||||
String.format("Successfully attached to buffer to buffer to %s!", buffer));
|
|
||||||
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
|
|
||||||
|
|
||||||
//TODO "get" the Editor corresponding to buffer, for now use the current one
|
|
||||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
|
||||||
|
|
||||||
WorkspaceManager
|
|
||||||
.getOrCreateBufferTask(ActionUtil.getCurrentProject(e))
|
|
||||||
.registerListener(bufferHandler, editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
||||||
String buffer = Messages.showInputDialog(
|
|
||||||
"Buffer name:",
|
|
||||||
"Attach to CodeMP Buffer",
|
|
||||||
Messages.getQuestionIcon());
|
|
||||||
try {
|
|
||||||
attach(e, buffer, false);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ActionUtil.notifyError(e, String.format(
|
|
||||||
"Failed to attach to buffer %s!",
|
|
||||||
buffer), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package com.codemp.intellij.actions.buffer;
|
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
|
||||||
import com.codemp.intellij.util.ActionUtil;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
||||||
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) {
|
|
||||||
CodeMPHandler.create(buffer);
|
|
||||||
if(!silent) ActionUtil.notify(e, "Success",
|
|
||||||
String.format("Created buffer %s!", buffer)
|
|
||||||
);
|
|
||||||
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
||||||
String buffer = Messages.showInputDialog(
|
|
||||||
"Buffer name:",
|
|
||||||
"Create CodeMP Buffer",
|
|
||||||
Messages.getQuestionIcon());
|
|
||||||
|
|
||||||
try {
|
|
||||||
create(e, buffer, false);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ActionUtil.notifyError(e, String.format(
|
|
||||||
"Failed to create buffer with name %s!",
|
|
||||||
buffer), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.codemp.intellij.actions.buffer;
|
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
|
||||||
import com.codemp.intellij.util.ActionUtil;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
||||||
import com.intellij.openapi.ui.Messages;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class BufferCreateWithContentAction extends AnAction {
|
|
||||||
|
|
||||||
public static void createWithContent(AnActionEvent event, String buffer, boolean silent) {
|
|
||||||
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
|
||||||
CodeMPHandler.createWithContent(buffer, content);
|
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(event, "Success", String.format(
|
|
||||||
"Created buffer %s with content %s!", buffer, content));
|
|
||||||
CodeMP.LOGGER.debug("Created buffer {} with content {}!", buffer, content);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
||||||
String buffer = Messages.showInputDialog(
|
|
||||||
"Buffer name:",
|
|
||||||
"Create CodeMP Buffer with Content",
|
|
||||||
Messages.getQuestionIcon());
|
|
||||||
|
|
||||||
try {
|
|
||||||
createWithContent(e, buffer, false);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ActionUtil.notifyError(e, String.format(
|
|
||||||
"Failed to create buffer with name %s!",
|
|
||||||
buffer), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package com.codemp.intellij.actions.buffer;
|
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
|
||||||
import com.codemp.intellij.exceptions.ide.BufferDetachException;
|
|
||||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
|
||||||
import com.codemp.intellij.util.ActionUtil;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
||||||
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) {
|
|
||||||
boolean res = CodeMPHandler.detach(buffer);
|
|
||||||
if(!res) throw new BufferDetachException(buffer);
|
|
||||||
|
|
||||||
CodeMP.ACTIVE_BUFFERS.remove(buffer);
|
|
||||||
if(task != null) {
|
|
||||||
task.unregisterListener(buffer);
|
|
||||||
if(!silent) ActionUtil.notify(e, "Success",
|
|
||||||
String.format("Detached from buffer %s!", buffer)
|
|
||||||
);
|
|
||||||
CodeMP.LOGGER.debug("Detached from buffer {}!", buffer);
|
|
||||||
} else {
|
|
||||||
if(!silent) ActionUtil.notifyError(e, String.format("Failed to detach from %s", buffer),
|
|
||||||
"Buffer event task was dead!");
|
|
||||||
CodeMP.LOGGER.debug("Failed to detach from {}: buffer event task was dead!", buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
||||||
String buffer = Messages.showInputDialog(
|
|
||||||
"Buffer name:",
|
|
||||||
"Detach from CodeMP Buffer",
|
|
||||||
Messages.getQuestionIcon());
|
|
||||||
|
|
||||||
try {
|
|
||||||
detach(e, buffer, false);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ActionUtil.notifyError(e, String.format(
|
|
||||||
"Failed to detach from buffer with name %s!",
|
|
||||||
buffer), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package com.codemp.intellij.actions.buffer;
|
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
|
||||||
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.command.CommandProcessor;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class BufferSyncAction extends AnAction {
|
|
||||||
public static void sync(AnActionEvent e, String bufferName, boolean silent) {
|
|
||||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
|
||||||
ApplicationManager.getApplication().runWriteAction(() ->
|
|
||||||
CommandProcessor.getInstance().executeCommand(
|
|
||||||
editor.getProject(),
|
|
||||||
() -> editor.getDocument().setText(CodeMPHandler.getBuffer(bufferName).getContent()),
|
|
||||||
"CodeMPBufferSync",
|
|
||||||
"codemp-buffer-sync",
|
|
||||||
editor.getDocument()
|
|
||||||
));
|
|
||||||
|
|
||||||
if(!silent) ActionUtil.notify(e,
|
|
||||||
String.format("Synced buffer %s", bufferName),
|
|
||||||
"The buffer was synced successfully.");
|
|
||||||
CodeMP.LOGGER.debug("The buffer {} was synced successfully.", bufferName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
||||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
|
||||||
String bufferName = CodeMP.ACTIVE_BUFFERS_REVERSE.get(editor);
|
|
||||||
try {
|
|
||||||
sync(e, bufferName, false);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ActionUtil.notifyError(e, String.format(
|
|
||||||
"Failed to attach to buffer %s!",
|
|
||||||
bufferName), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ public class WorkspaceJoinAction extends AnAction {
|
||||||
if(!silent) ActionUtil.notify(e,
|
if(!silent) ActionUtil.notify(e,
|
||||||
"Success", String.format("Joined workspace %s!", workspaceId));
|
"Success", String.format("Joined workspace %s!", workspaceId));
|
||||||
CodeMP.LOGGER.debug("Joined workspace {}!", workspaceId);
|
CodeMP.LOGGER.debug("Joined workspace {}!", workspaceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.codemp.intellij.actions.workspace;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.util.ActionUtil;
|
import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.codemp.intellij.workspace.Workspace;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
|
|
|
@ -2,15 +2,12 @@ package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.CursorHandler;
|
import com.codemp.intellij.jni.CursorHandler;
|
||||||
import com.codemp.intellij.task.CursorEventAwaiterTask;
|
|
||||||
import com.codemp.intellij.util.FileUtil;
|
import com.codemp.intellij.util.FileUtil;
|
||||||
import com.codemp.intellij.workspace.Workspace;
|
|
||||||
import com.intellij.openapi.editor.Caret;
|
import com.intellij.openapi.editor.Caret;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.editor.VisualPosition;
|
import com.intellij.openapi.editor.VisualPosition;
|
||||||
import com.intellij.openapi.editor.event.CaretEvent;
|
import com.intellij.openapi.editor.event.CaretEvent;
|
||||||
import com.intellij.openapi.editor.event.CaretListener;
|
import com.intellij.openapi.editor.event.CaretListener;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class CursorEventListener implements CaretListener {
|
public class CursorEventListener implements CaretListener {
|
||||||
|
|
|
@ -3,14 +3,9 @@ package com.codemp.intellij.listeners;
|
||||||
import com.codemp.intellij.jni.WorkspaceHandler;
|
import com.codemp.intellij.jni.WorkspaceHandler;
|
||||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||||
import com.codemp.intellij.util.FileUtil;
|
import com.codemp.intellij.util.FileUtil;
|
||||||
import com.codemp.intellij.workspace.Workspace;
|
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.editor.Document;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||||
import com.intellij.openapi.fileEditor.TextEditor;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.codemp.intellij.listeners;
|
package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
|
import com.codemp.intellij.exceptions.lib.TransportException;
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
import com.codemp.intellij.jni.BufferHandler;
|
||||||
import com.codemp.intellij.jni.WorkspaceHandler;
|
import com.codemp.intellij.jni.WorkspaceHandler;
|
||||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||||
|
@ -39,7 +40,7 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
||||||
String path = FileUtil.getRelativePath(editor.getProject(), file);
|
String path = FileUtil.getRelativePath(editor.getProject(), file);
|
||||||
if(path == null) return;
|
if(path == null) return;
|
||||||
|
|
||||||
BufferHandler bufferHandler = this.handler.attachToBuffer(path);
|
BufferHandler bufferHandler = this.getBufferForPath(path);
|
||||||
Disposable disp = Disposer.newDisposable(String.format("codemp-buffer-%s", path));
|
Disposable disp = Disposer.newDisposable(String.format("codemp-buffer-%s", path));
|
||||||
editor.getDocument().addDocumentListener(new BufferEventListener(bufferHandler), disp);
|
editor.getDocument().addDocumentListener(new BufferEventListener(bufferHandler), disp);
|
||||||
|
|
||||||
|
@ -47,4 +48,17 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
||||||
this.task.activeBuffers.put(path, disp);
|
this.task.activeBuffers.put(path, disp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach to a buffer or, if it does not exist, implicitly create it.
|
||||||
|
* @param path the buffer's name (which is the path relative to project root)
|
||||||
|
* @return the {@link BufferHandler} for it
|
||||||
|
*/
|
||||||
|
private BufferHandler getBufferForPath(String path) {
|
||||||
|
try {
|
||||||
|
return this.handler.attachToBuffer(path);
|
||||||
|
} catch (TransportException ignored) {
|
||||||
|
return this.handler.createBuffer(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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.lib.ChannelException;
|
|
||||||
import com.codemp.intellij.exceptions.lib.DeadlockedException;
|
import com.codemp.intellij.exceptions.lib.DeadlockedException;
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
import com.codemp.intellij.jni.BufferHandler;
|
||||||
import com.codemp.intellij.jni.StringVec;
|
import com.codemp.intellij.jni.StringVec;
|
||||||
|
@ -15,10 +14,12 @@ import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.progress.ProgressIndicator;
|
import com.intellij.openapi.progress.ProgressIndicator;
|
||||||
import com.intellij.openapi.progress.Task;
|
import com.intellij.openapi.progress.Task;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Disposer;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class BufferEventAwaiterTask extends Task.Backgroundable implements Disposable {
|
public class BufferEventAwaiterTask extends Task.Backgroundable implements Disposable {
|
||||||
|
@ -33,51 +34,47 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("InfiniteLoopStatement")
|
@SuppressWarnings("InfiniteLoopStatement")
|
||||||
public void run(@NotNull ProgressIndicator indicator) {
|
public void run(@NotNull ProgressIndicator indicator) {
|
||||||
try {
|
while(true) {
|
||||||
|
StringVec buffers = new StringVec(); //jni moment
|
||||||
|
this.activeBuffers.keySet().forEach(buffers::push);
|
||||||
|
|
||||||
|
Optional<BufferHandler> bufferOptional = this.handler.selectBuffer(buffers, 100L);
|
||||||
|
if(bufferOptional.isEmpty())
|
||||||
|
continue;
|
||||||
|
BufferHandler buffer = bufferOptional.get();
|
||||||
|
|
||||||
|
List<TextChangeWrapper> changeList = new ArrayList<>();
|
||||||
while(true) {
|
while(true) {
|
||||||
StringVec buffers = new StringVec(); //jni moment
|
Optional<TextChangeWrapper> changeOptional;
|
||||||
this.activeBuffers.keySet().forEach(buffers::push);
|
try {
|
||||||
|
changeOptional = buffer.tryRecv();
|
||||||
Optional<BufferHandler> bufferOptional = this.handler.selectBuffer(buffers, 100L);
|
} catch(DeadlockedException e) {
|
||||||
if(bufferOptional.isEmpty())
|
CodeMP.LOGGER.error(e.getMessage());
|
||||||
continue;
|
continue;
|
||||||
BufferHandler buffer = bufferOptional.get();
|
|
||||||
|
|
||||||
List<TextChangeWrapper> changeList = new ArrayList<>();
|
|
||||||
while(true) {
|
|
||||||
Optional<TextChangeWrapper> changeOptional;
|
|
||||||
try {
|
|
||||||
changeOptional = buffer.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor bufferEditor = FileUtil.getActiveEditorByPath(this.myProject, buffer.getName());
|
if(changeOptional.isEmpty())
|
||||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
break;
|
||||||
ApplicationManager.getApplication().runWriteAction(() ->
|
TextChangeWrapper change = changeOptional.get();
|
||||||
CommandProcessor.getInstance().executeCommand(
|
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
||||||
this.myProject,
|
change.getContent(), change.getStart(), change.getEnd());
|
||||||
() -> changeList.forEach((change) ->
|
changeList.add(change);
|
||||||
bufferEditor.getDocument().replaceString(
|
}
|
||||||
(int) change.getStart(), (int) change.getEnd(), change.getContent())
|
|
||||||
),
|
Editor bufferEditor = FileUtil.getActiveEditorByPath(this.myProject, buffer.getName());
|
||||||
"CodeMPBufferReceive",
|
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
||||||
"codemp-buffer-receive", //TODO: mark this with the name
|
ApplicationManager.getApplication().runWriteAction(() ->
|
||||||
bufferEditor.getDocument()
|
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(ChannelException ex) { //exited
|
|
||||||
//TODO handle stop
|
|
||||||
Disposer.dispose(this); //stopped
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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.lib.ChannelException;
|
|
||||||
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;
|
||||||
|
@ -9,6 +8,7 @@ import com.codemp.intellij.util.FileUtil;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
|
import com.intellij.openapi.editor.RangeMarker;
|
||||||
import com.intellij.openapi.editor.markup.HighlighterLayer;
|
import com.intellij.openapi.editor.markup.HighlighterLayer;
|
||||||
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
|
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
|
||||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||||
|
@ -36,62 +36,58 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("InfiniteLoopStatement")
|
@SuppressWarnings("InfiniteLoopStatement")
|
||||||
public void run(@NotNull ProgressIndicator indicator) {
|
public void run(@NotNull ProgressIndicator indicator) {
|
||||||
try {
|
while(true) {
|
||||||
while(true) {
|
CursorEventWrapper event = this.handler.recv();
|
||||||
CursorEventWrapper event = this.handler.recv();
|
Editor editor = FileUtil.getActiveEditorByPath(this.myProject, event.getBuffer());
|
||||||
Editor editor = FileUtil.getActiveEditorByPath(this.myProject, 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());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int startOffset = editor.getDocument()
|
int startOffset = editor.getDocument()
|
||||||
.getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
.getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
||||||
int endOffset = editor.getDocument()
|
int endOffset = editor.getDocument()
|
||||||
.getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
.getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
||||||
|
|
||||||
ApplicationManager.getApplication().invokeLater(() -> {
|
ApplicationManager.getApplication().invokeLater(() -> {
|
||||||
int documentLength = editor.getDocument().getTextLength();
|
int documentLength = editor.getDocument().getTextLength();
|
||||||
if(startOffset > documentLength || endOffset > documentLength) {
|
if(startOffset > documentLength || endOffset > documentLength) {
|
||||||
CodeMP.LOGGER.debug(
|
CodeMP.LOGGER.debug(
|
||||||
"Out of bounds cursor: start was {}, end was {}, document length was {}!",
|
"Out of bounds cursor: start was {}, end was {}, document length was {}!",
|
||||||
startOffset, endOffset, documentLength);
|
startOffset, endOffset, documentLength);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeHighlighter previous = this.highlighterMap.put(event.getUser(), editor
|
RangeHighlighter previous = 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.hashColor(event.getUser()),
|
ColorUtil.hashColor(event.getUser()),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Font.PLAIN
|
Font.PLAIN
|
||||||
), HighlighterTargetArea.EXACT_RANGE
|
), HighlighterTargetArea.EXACT_RANGE
|
||||||
));
|
));
|
||||||
|
|
||||||
if(previous != null)
|
if(previous != null)
|
||||||
previous.dispose();
|
previous.dispose();
|
||||||
});
|
});
|
||||||
} catch(IndexOutOfBoundsException ignored) {}
|
} catch(IndexOutOfBoundsException ignored) {}
|
||||||
}
|
|
||||||
} catch(ChannelException ex) { //exited
|
|
||||||
this.run(indicator);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
this.highlighterMap.forEach((s, r) -> r.dispose());
|
this.highlighterMap.values().forEach(RangeMarker::dispose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,26 +13,10 @@
|
||||||
<action id="codemp.fast-forward" class="com.codemp.intellij.actions.FastForwardAction" text="Just 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.connect" class="com.codemp.intellij.actions.ConnectAction" text="Connect..."/>
|
||||||
<action id="codemp.connect" class="com.codemp.intellij.actions.DisconnectAction" text="Disconnect"/>
|
<action id="codemp.connect" class="com.codemp.intellij.actions.DisconnectAction" text="Disconnect"/>
|
||||||
|
<action id="codemp.workspace.join" class="com.codemp.intellij.actions.workspace.WorkspaceJoinAction"
|
||||||
<group id="codemp.workspace" text="Workspace" popup="true">
|
text="Join Workspace"/>
|
||||||
<action id="codemp.workspace.join" class="com.codemp.intellij.actions.workspace.WorkspaceJoinAction"
|
<action id="codemp.workspace.leave" class="com.codemp.intellij.actions.workspace.WorkspaceLeaveAction"
|
||||||
text="Join Workspace"/>
|
text="Leave Workspace"/>
|
||||||
<action id="codemp.workspace.leave" class="com.codemp.intellij.actions.workspace.WorkspaceLeaveAction"
|
|
||||||
text="Leave Workspace"/>
|
|
||||||
</group>
|
|
||||||
<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"/>
|
|
||||||
<action id="codemp.buffer.sync" class="com.codemp.intellij.actions.buffer.BufferSyncAction"
|
|
||||||
text="Force Sync Buffer"/>
|
|
||||||
<action id="codemp.buffer.detach" class="com.codemp.intellij.actions.buffer.BufferDetachAction"
|
|
||||||
text="Detach from Buffer"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
</group>
|
||||||
</actions>
|
</actions>
|
||||||
|
|
||||||
|
|
|
@ -76,9 +76,9 @@ impl WorkspaceHandler {
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
/// create a new buffer in current workspace
|
/// create a new buffer in current workspace
|
||||||
fn create_buffer(&mut self, path: &str) -> CodempResult<Option<BufferHandler>> {
|
fn create_buffer(&mut self, path: &str) -> CodempResult<BufferHandler> {
|
||||||
RT.block_on(RT.block_on(self.workspace.write()).create(path))?;
|
RT.block_on(RT.block_on(self.workspace.write()).create(path))?;
|
||||||
Ok(self.get_buffer(path))
|
Ok(self.get_buffer(path).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
|
@ -144,7 +144,7 @@ impl WorkspaceHandler {
|
||||||
/// get a [crate::BufferHandler] for one of the workspace's buffers
|
/// get a [crate::BufferHandler] for one of the workspace's buffers
|
||||||
fn get_buffer(&self, path: &str) -> Option<BufferHandler> {
|
fn get_buffer(&self, path: &str) -> Option<BufferHandler> {
|
||||||
RT.block_on(self.workspace.read()).buffer_by_name(path)
|
RT.block_on(self.workspace.read()).buffer_by_name(path)
|
||||||
.map(|b| BufferHandler { buffer: b })
|
.map(|buffer| BufferHandler { buffer })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
|
|
Loading…
Reference in a new issue