diff --git a/src/main/java/com/codemp/intellij/actions/ConnectAction.java b/src/main/java/com/codemp/intellij/actions/ConnectAction.java index 3ad68d8..297b6a7 100644 --- a/src/main/java/com/codemp/intellij/actions/ConnectAction.java +++ b/src/main/java/com/codemp/intellij/actions/ConnectAction.java @@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull; public class ConnectAction extends AnAction { public static void connect(AnActionEvent e, String url, boolean silent) { CodeMP.connect(url); - if(!silent) ActionUtil.notify(e, "Success", String.format("Connected to %s!", url)); CodeMP.LOGGER.debug("Connected to {}!", url); diff --git a/src/main/java/com/codemp/intellij/actions/DisconnectAction.java b/src/main/java/com/codemp/intellij/actions/DisconnectAction.java index 2a6e7dc..396f887 100644 --- a/src/main/java/com/codemp/intellij/actions/DisconnectAction.java +++ b/src/main/java/com/codemp/intellij/actions/DisconnectAction.java @@ -9,9 +9,7 @@ import org.jetbrains.annotations.NotNull; public class DisconnectAction extends AnAction { public static void disconnect(AnActionEvent e, boolean silent) { String url = CodeMP.getClient("disconnect").getUrl(); - CodeMP.disconnect(); - if(!silent) ActionUtil.notify(e, "Success", String.format("Disconnected from %s!", url)); CodeMP.LOGGER.debug("Connected to {}!", url); diff --git a/src/main/java/com/codemp/intellij/actions/FastForwardAction.java b/src/main/java/com/codemp/intellij/actions/FastForwardAction.java index ea351d9..09eaf76 100644 --- a/src/main/java/com/codemp/intellij/actions/FastForwardAction.java +++ b/src/main/java/com/codemp/intellij/actions/FastForwardAction.java @@ -1,7 +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; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -15,7 +14,6 @@ public class FastForwardAction extends AnAction { public void actionPerformed(@NotNull AnActionEvent e) { 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 deleted file mode 100644 index 198fab0..0000000 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferAttachAction.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java deleted file mode 100644 index ebb1849..0000000 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateAction.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java deleted file mode 100644 index d839ff0..0000000 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferCreateWithContentAction.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java deleted file mode 100644 index 62ee4fe..0000000 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferDetachAction.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/com/codemp/intellij/actions/buffer/BufferSyncAction.java b/src/main/java/com/codemp/intellij/actions/buffer/BufferSyncAction.java deleted file mode 100644 index 26229b1..0000000 --- a/src/main/java/com/codemp/intellij/actions/buffer/BufferSyncAction.java +++ /dev/null @@ -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); - } - } -} 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 001dfbb..022fb9a 100644 --- a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java +++ b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceJoinAction.java @@ -18,7 +18,6 @@ public class WorkspaceJoinAction extends AnAction { if(!silent) ActionUtil.notify(e, "Success", String.format("Joined workspace %s!", workspaceId)); CodeMP.LOGGER.debug("Joined workspace {}!", workspaceId); - } @Override 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 5cc12e5..21246bd 100644 --- a/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java +++ b/src/main/java/com/codemp/intellij/actions/workspace/WorkspaceLeaveAction.java @@ -2,7 +2,6 @@ package com.codemp.intellij.actions.workspace; import com.codemp.intellij.CodeMP; import com.codemp.intellij.util.ActionUtil; -import com.codemp.intellij.workspace.Workspace; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.ui.Messages; diff --git a/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java b/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java index f112a07..486e2c5 100644 --- a/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java +++ b/src/main/java/com/codemp/intellij/listeners/CursorEventListener.java @@ -2,15 +2,12 @@ package com.codemp.intellij.listeners; import com.codemp.intellij.CodeMP; import com.codemp.intellij.jni.CursorHandler; -import com.codemp.intellij.task.CursorEventAwaiterTask; import com.codemp.intellij.util.FileUtil; -import com.codemp.intellij.workspace.Workspace; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.VisualPosition; import com.intellij.openapi.editor.event.CaretEvent; import com.intellij.openapi.editor.event.CaretListener; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; public class CursorEventListener implements CaretListener { diff --git a/src/main/java/com/codemp/intellij/listeners/WorkspaceFileClosedListener.java b/src/main/java/com/codemp/intellij/listeners/WorkspaceFileClosedListener.java index 9e4c829..a2ddb34 100644 --- a/src/main/java/com/codemp/intellij/listeners/WorkspaceFileClosedListener.java +++ b/src/main/java/com/codemp/intellij/listeners/WorkspaceFileClosedListener.java @@ -3,14 +3,9 @@ package com.codemp.intellij.listeners; import com.codemp.intellij.jni.WorkspaceHandler; import com.codemp.intellij.task.BufferEventAwaiterTask; import com.codemp.intellij.util.FileUtil; -import com.codemp.intellij.workspace.Workspace; 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.FileEditorManagerListener; -import com.intellij.openapi.fileEditor.TextEditor; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/codemp/intellij/listeners/WorkspaceFileOpenedListener.java b/src/main/java/com/codemp/intellij/listeners/WorkspaceFileOpenedListener.java index feacea6..d7b9661 100644 --- a/src/main/java/com/codemp/intellij/listeners/WorkspaceFileOpenedListener.java +++ b/src/main/java/com/codemp/intellij/listeners/WorkspaceFileOpenedListener.java @@ -1,5 +1,6 @@ package com.codemp.intellij.listeners; +import com.codemp.intellij.exceptions.lib.TransportException; import com.codemp.intellij.jni.BufferHandler; import com.codemp.intellij.jni.WorkspaceHandler; import com.codemp.intellij.task.BufferEventAwaiterTask; @@ -39,7 +40,7 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener { String path = FileUtil.getRelativePath(editor.getProject(), file); 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)); editor.getDocument().addDocumentListener(new BufferEventListener(bufferHandler), disp); @@ -47,4 +48,17 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener { 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); + } + } } diff --git a/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java b/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java index 7f088e0..b4422f4 100644 --- a/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java +++ b/src/main/java/com/codemp/intellij/task/BufferEventAwaiterTask.java @@ -1,7 +1,6 @@ package com.codemp.intellij.task; import com.codemp.intellij.CodeMP; -import com.codemp.intellij.exceptions.lib.ChannelException; import com.codemp.intellij.exceptions.lib.DeadlockedException; import com.codemp.intellij.jni.BufferHandler; 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.Task; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; 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; public class BufferEventAwaiterTask extends Task.Backgroundable implements Disposable { @@ -33,51 +34,47 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo @Override @SuppressWarnings("InfiniteLoopStatement") public void run(@NotNull ProgressIndicator indicator) { - try { + while(true) { + StringVec buffers = new StringVec(); //jni moment + this.activeBuffers.keySet().forEach(buffers::push); + + Optional bufferOptional = this.handler.selectBuffer(buffers, 100L); + if(bufferOptional.isEmpty()) + continue; + BufferHandler buffer = bufferOptional.get(); + + List changeList = new ArrayList<>(); while(true) { - StringVec buffers = new StringVec(); //jni moment - this.activeBuffers.keySet().forEach(buffers::push); - - Optional bufferOptional = this.handler.selectBuffer(buffers, 100L); - if(bufferOptional.isEmpty()) + Optional changeOptional; + try { + changeOptional = buffer.tryRecv(); + } catch(DeadlockedException e) { + CodeMP.LOGGER.error(e.getMessage()); continue; - BufferHandler buffer = bufferOptional.get(); - - List changeList = new ArrayList<>(); - while(true) { - Optional 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()); - 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() - ))); + 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()); + 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(ChannelException ex) { //exited - //TODO handle stop - Disposer.dispose(this); //stopped - } } @Override diff --git a/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java b/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java index 9fe5814..454a7f9 100644 --- a/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java +++ b/src/main/java/com/codemp/intellij/task/CursorEventAwaiterTask.java @@ -1,7 +1,6 @@ package com.codemp.intellij.task; import com.codemp.intellij.CodeMP; -import com.codemp.intellij.exceptions.lib.ChannelException; import com.codemp.intellij.jni.CursorEventWrapper; import com.codemp.intellij.jni.CursorHandler; 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.application.ApplicationManager; 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.HighlighterTargetArea; import com.intellij.openapi.editor.markup.RangeHighlighter; @@ -36,62 +36,58 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo @Override @SuppressWarnings("InfiniteLoopStatement") public void run(@NotNull ProgressIndicator indicator) { - try { - while(true) { - CursorEventWrapper event = this.handler.recv(); - Editor editor = FileUtil.getActiveEditorByPath(this.myProject, event.getBuffer()); - if(editor == null) - continue; + while(true) { + CursorEventWrapper event = this.handler.recv(); + Editor editor = FileUtil.getActiveEditorByPath(this.myProject, 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()); - try { - int startOffset = editor.getDocument() - .getLineStartOffset(event.getStartRow()) + event.getStartCol(); - int endOffset = editor.getDocument() - .getLineStartOffset(event.getEndRow()) + event.getEndCol(); + try { + int startOffset = editor.getDocument() + .getLineStartOffset(event.getStartRow()) + event.getStartCol(); + int endOffset = editor.getDocument() + .getLineStartOffset(event.getEndRow()) + event.getEndCol(); - ApplicationManager.getApplication().invokeLater(() -> { - int documentLength = editor.getDocument().getTextLength(); - if(startOffset > documentLength || endOffset > documentLength) { - CodeMP.LOGGER.debug( - "Out of bounds cursor: start was {}, end was {}, document length was {}!", - startOffset, endOffset, documentLength); - return; - } + ApplicationManager.getApplication().invokeLater(() -> { + int documentLength = editor.getDocument().getTextLength(); + if(startOffset > documentLength || endOffset > documentLength) { + CodeMP.LOGGER.debug( + "Out of bounds cursor: start was {}, end was {}, document length was {}!", + startOffset, endOffset, documentLength); + return; + } - RangeHighlighter previous = this.highlighterMap.put(event.getUser(), editor - .getMarkupModel() - .addRangeHighlighter( - startOffset, - endOffset, - HighlighterLayer.SELECTION, - new TextAttributes( - null, - ColorUtil.hashColor(event.getUser()), - null, - null, - Font.PLAIN - ), HighlighterTargetArea.EXACT_RANGE - )); + RangeHighlighter previous = this.highlighterMap.put(event.getUser(), editor + .getMarkupModel() + .addRangeHighlighter( + startOffset, + endOffset, + HighlighterLayer.SELECTION, + new TextAttributes( + null, + ColorUtil.hashColor(event.getUser()), + null, + null, + Font.PLAIN + ), HighlighterTargetArea.EXACT_RANGE + )); - if(previous != null) - previous.dispose(); - }); - } catch(IndexOutOfBoundsException ignored) {} - } - } catch(ChannelException ex) { //exited - this.run(indicator); + if(previous != null) + previous.dispose(); + }); + } catch(IndexOutOfBoundsException ignored) {} } } @Override public void dispose() { - this.highlighterMap.forEach((s, r) -> r.dispose()); + this.highlighterMap.values().forEach(RangeMarker::dispose); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 2b2d9c8..934acf2 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -13,26 +13,10 @@ - - - - - - - - - - - - + + diff --git a/src/main/rust/lib.rs b/src/main/rust/lib.rs index d24403d..ef9d2d2 100644 --- a/src/main/rust/lib.rs +++ b/src/main/rust/lib.rs @@ -76,9 +76,9 @@ impl WorkspaceHandler { #[generate_interface] /// create a new buffer in current workspace - fn create_buffer(&mut self, path: &str) -> CodempResult> { + fn create_buffer(&mut self, path: &str) -> CodempResult { RT.block_on(RT.block_on(self.workspace.write()).create(path))?; - Ok(self.get_buffer(path)) + Ok(self.get_buffer(path).unwrap()) } #[generate_interface] @@ -144,7 +144,7 @@ impl WorkspaceHandler { /// get a [crate::BufferHandler] for one of the workspace's buffers fn get_buffer(&self, path: &str) -> Option { RT.block_on(self.workspace.read()).buffer_by_name(path) - .map(|b| BufferHandler { buffer: b }) + .map(|buffer| BufferHandler { buffer }) } #[generate_interface]