mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-22 07:04:49 +01:00
feat: working BufferAttach, various fixes, upgrade to woot
This commit is contained in:
parent
9e16c21454
commit
dfae6d6b9d
7 changed files with 52 additions and 34 deletions
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.4.5", features = ["global", "sync"] }
|
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", branch = "woot", features = ["global", "sync"] }
|
||||||
jni = { version = "0.21.1", features = ["invocation"] }
|
jni = { version = "0.21.1", features = ["invocation"] }
|
||||||
jni-sys = "0.3.0"
|
jni-sys = "0.3.0"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class FastForwardAction extends AnAction {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
try {
|
try {
|
||||||
ConnectAction.connect("http://alemi.dev:50051", true);
|
ConnectAction.connect("http://alemi.dev:50052", true);
|
||||||
JoinAction.join(e, "default", true);
|
JoinAction.join(e, "default", true);
|
||||||
BufferAttachAction.attach(e, "test", true);
|
BufferAttachAction.attach(e, "test", true);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
|
|
|
@ -94,6 +94,9 @@ public class JoinAction extends AnAction {
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
CursorEventWrapper event = handler.recv();
|
CursorEventWrapper event = handler.recv();
|
||||||
|
int startOffset = this.editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
||||||
|
int endOffset = this.editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
||||||
|
|
||||||
ApplicationManager.getApplication().invokeLater(() -> {
|
ApplicationManager.getApplication().invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
RangeHighlighter highlighter = highlighterMap.get(event.getUser());
|
RangeHighlighter highlighter = highlighterMap.get(event.getUser());
|
||||||
|
@ -110,8 +113,8 @@ public class JoinAction extends AnAction {
|
||||||
highlighterMap.put(event.getUser(), this.editor
|
highlighterMap.put(event.getUser(), this.editor
|
||||||
.getMarkupModel()
|
.getMarkupModel()
|
||||||
.addRangeHighlighter(
|
.addRangeHighlighter(
|
||||||
this.editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol(),
|
startOffset,
|
||||||
this.editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol(),
|
endOffset,
|
||||||
HighlighterLayer.SELECTION,
|
HighlighterLayer.SELECTION,
|
||||||
new TextAttributes(
|
new TextAttributes(
|
||||||
null,
|
null,
|
||||||
|
@ -121,8 +124,12 @@ public class JoinAction extends AnAction {
|
||||||
Font.PLAIN
|
Font.PLAIN
|
||||||
), HighlighterTargetArea.EXACT_RANGE
|
), 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 - this.editor.getDocument().getTextLength() != 1)
|
||||||
|
throw ex;
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
|
|
|
@ -9,10 +9,12 @@ import com.codemp.intellij.util.ActionUtil;
|
||||||
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.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.editor.Document;
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.progress.ProgressIndicator;
|
import com.intellij.openapi.progress.ProgressIndicator;
|
||||||
import com.intellij.openapi.progress.ProgressManager;
|
import com.intellij.openapi.progress.ProgressManager;
|
||||||
import com.intellij.openapi.progress.Task;
|
import com.intellij.openapi.progress.Task;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -27,6 +29,8 @@ public class BufferAttachAction extends AnAction {
|
||||||
//register buffer change listener
|
//register buffer change listener
|
||||||
//TODO "get" the Document corresponding to buffer, for now use the current one
|
//TODO "get" the Document corresponding to buffer, for now use the current one
|
||||||
BufferEventListener listener = new BufferEventListener(buffer);
|
BufferEventListener listener = new BufferEventListener(buffer);
|
||||||
|
|
||||||
|
Project project = ActionUtil.getCurrentProject(e);
|
||||||
Document document = ActionUtil.getCurrentEditor(e).getDocument();
|
Document document = ActionUtil.getCurrentEditor(e).getDocument();
|
||||||
document.addDocumentListener(listener);
|
document.addDocumentListener(listener);
|
||||||
|
|
||||||
|
@ -37,17 +41,21 @@ public class BufferAttachAction extends AnAction {
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
TextChangeWrapper event = bufferHandler.recv();
|
TextChangeWrapper event = bufferHandler.recv();
|
||||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
|
||||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
||||||
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!\n",
|
|
||||||
event.getContent(), event.getStart(), event.getEnd());
|
event.getContent(), event.getStart(), event.getEnd());
|
||||||
CodeMP.LOGGER.info("is writable: {}", document.isWritable());
|
|
||||||
document.replaceString( //TODO this doesn't work
|
ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> {
|
||||||
(int) event.getStart(),
|
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||||
(int) event.getEnd(),
|
CommandProcessor.getInstance().executeCommand(
|
||||||
event.getContent()
|
project,
|
||||||
);
|
() -> document.replaceString(
|
||||||
}));
|
(int) event.getStart(), (int) event.getEnd(), event.getContent()),
|
||||||
|
"CodeMPBufferReceive",
|
||||||
|
"codemp-buffer-receive", //TODO: mark this with the name
|
||||||
|
document);
|
||||||
|
});
|
||||||
|
});
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
import com.codemp.intellij.jni.BufferHandler;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
import com.codemp.intellij.jni.CodeMPHandler;
|
||||||
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||||
import com.intellij.openapi.editor.event.DocumentListener;
|
import com.intellij.openapi.editor.event.DocumentListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -16,11 +17,16 @@ public class BufferEventListener implements DocumentListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void documentChanged(@NotNull DocumentEvent event) {
|
public void documentChanged(@NotNull DocumentEvent event) {
|
||||||
try {
|
Object group = CommandProcessor.getInstance().getCurrentCommandGroupId();
|
||||||
|
if(group instanceof String groupString && groupString.startsWith("codemp-buffer-receive"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
try { //TODO move actions break
|
||||||
int changeOffset = event.getOffset();
|
int changeOffset = event.getOffset();
|
||||||
CharSequence newFragment = event.getNewFragment();
|
CharSequence newFragment = event.getNewFragment();
|
||||||
BufferHandler bufferHandler = CodeMPHandler.getBuffer(this.bufferName);
|
BufferHandler bufferHandler = CodeMPHandler.getBuffer(this.bufferName);
|
||||||
bufferHandler.send(changeOffset, changeOffset + event.getOldFragment().length(),
|
bufferHandler.send(changeOffset,
|
||||||
|
changeOffset + event.getOldFragment().length(),
|
||||||
newFragment.toString());
|
newFragment.toString());
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -8,11 +8,8 @@ public class ColorUtil {
|
||||||
public static JBColor colorFromUsername(String username) {
|
public static JBColor colorFromUsername(String username) {
|
||||||
int hash = username.hashCode();
|
int hash = username.hashCode();
|
||||||
|
|
||||||
Color hashColor = Color.decode( //Integer.toHexString(((hash >> 24) & 0xFF)) +
|
@SuppressWarnings("all")
|
||||||
Integer.toHexString(((hash >> 16) & 0xFF)) +
|
Color hashColor = new Color(hash | (0xFF << 24));
|
||||||
Integer.toHexString(((hash >> 8) & 0xFF)) +
|
|
||||||
Integer.toHexString((hash & 0xFF))
|
|
||||||
);
|
|
||||||
|
|
||||||
return new JBColor(hashColor, hashColor.darker());
|
return new JBColor(hashColor, hashColor.darker());
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,8 +184,8 @@ impl TextChangeWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
fn get_content(&self) -> &str {
|
fn get_content(&self) -> String {
|
||||||
&self.content
|
self.content.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,20 +205,20 @@ impl BufferHandler {
|
||||||
fn recv(&self) -> Result<TextChangeWrapper, String> {
|
fn recv(&self) -> Result<TextChangeWrapper, String> {
|
||||||
match self.buffer.blocking_recv(CODEMP_INSTANCE.rt()) {
|
match self.buffer.blocking_recv(CODEMP_INSTANCE.rt()) {
|
||||||
Err(err) => Err(ErrorWrapper::from(err).get_error_message()),
|
Err(err) => Err(ErrorWrapper::from(err).get_error_message()),
|
||||||
Ok(change) => Ok(TextChangeWrapper {
|
Ok(change) => {
|
||||||
|
println!("test {:?}", change);
|
||||||
|
Ok(TextChangeWrapper {
|
||||||
start: change.span.start,
|
start: change.span.start,
|
||||||
end: change.span.end,
|
end: change.span.end,
|
||||||
content: change.content.clone()
|
content: change.content.clone()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
fn send(&self, start_offset: usize, end_offset: usize, content: String) -> Result<(), String> {
|
fn send(&self, start_offset: usize, end_offset: usize, content: String) -> Result<(), String> {
|
||||||
match self.buffer.delta(start_offset, &content, end_offset) {
|
self.buffer.send(CodempTextChange { span: start_offset..end_offset, content, after: "".to_string() })
|
||||||
None => Err("Cannot send a no-op".to_string()),
|
|
||||||
Some(op_seq) => self.buffer.send(op_seq)
|
|
||||||
.map_err(|err| ErrorWrapper::from(err).get_error_message())
|
.map_err(|err| ErrorWrapper::from(err).get_error_message())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue