mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-21 22:54:48 +01:00
chore: gradle cleanup
This commit is contained in:
parent
73dfda2d1c
commit
13c3601e90
6 changed files with 144 additions and 52 deletions
19
build.gradle
19
build.gradle
|
@ -1,11 +1,12 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.jetbrains.intellij.platform' version '2.0.1'
|
alias libs.plugins.intellij.plugin
|
||||||
id 'com.palantir.git-version' version '3.1.0'
|
alias libs.plugins.git.version
|
||||||
|
alias libs.plugins.osdetector
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'mp.code'
|
group = 'mp.code'
|
||||||
version = versionDetails().lastTag
|
//version = versionDetails().lastTag
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
@ -13,18 +14,18 @@ java {
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url 'https://jitpack.io' }
|
|
||||||
intellijPlatform {
|
intellijPlatform {
|
||||||
defaultRepositories()
|
defaultRepositories()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.slf4j:slf4j-api:2.0.9'
|
implementation variantOf(libs.codemp) {
|
||||||
implementation 'ch.qos.logback:logback-classic:1.4.12'
|
classifier osdetector.classifier
|
||||||
implementation 'mp.code:codemp:0.7.0:linux-x86_64'
|
}
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.34'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
compileOnly libs.lombok
|
||||||
|
annotationProcessor libs.lombok
|
||||||
|
|
||||||
intellijPlatform { // TODO: not all of these may be needed, but whatever
|
intellijPlatform { // TODO: not all of these may be needed, but whatever
|
||||||
intellijIdeaCommunity('2023.3')
|
intellijIdeaCommunity('2023.3')
|
||||||
|
|
15
gradle/libs.versions.toml
Normal file
15
gradle/libs.versions.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[versions]
|
||||||
|
codemp = '0.7.0'
|
||||||
|
lombok = '1.18.34'
|
||||||
|
intellij-plugin = '2.0.1'
|
||||||
|
git-version = '3.1.0'
|
||||||
|
osdetector = '1.7.3'
|
||||||
|
|
||||||
|
[plugins]
|
||||||
|
intellij-plugin = { id = 'org.jetbrains.intellij.platform', version.ref = 'intellij-plugin' }
|
||||||
|
git-version = { id = 'com.palantir.git-version', version.ref = 'git-version' }
|
||||||
|
osdetector = { id = 'com.google.osdetector', version.ref = 'osdetector' }
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
codemp = { group = 'mp.code', name = 'codemp', version.ref = 'codemp' }
|
||||||
|
lombok = { group = 'org.projectlombok', name = 'lombok', version.ref = 'lombok' }
|
|
@ -1,18 +1,16 @@
|
||||||
package mp.code.intellij.ui;
|
package mp.code.intellij.ui;
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.command.CommandProcessor;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
import com.intellij.openapi.project.DumbAware;
|
import com.intellij.openapi.project.DumbAware;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.wm.ToolWindow;
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||||
import com.intellij.ui.content.Content;
|
import com.intellij.ui.content.Content;
|
||||||
import com.intellij.ui.content.ContentFactory;
|
import com.intellij.ui.content.ContentFactory;
|
||||||
import com.intellij.ui.treeStructure.Tree;
|
import com.intellij.ui.treeStructure.Tree;
|
||||||
import mp.code.data.TextChange;
|
|
||||||
import mp.code.exceptions.ControllerException;
|
|
||||||
import mp.code.intellij.CodeMP;
|
import mp.code.intellij.CodeMP;
|
||||||
|
import mp.code.intellij.util.cb.BufferCallback;
|
||||||
import mp.code.intellij.util.FileUtil;
|
import mp.code.intellij.util.FileUtil;
|
||||||
import mp.code.intellij.util.InteractionUtil;
|
import mp.code.intellij.util.InteractionUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -23,8 +21,6 @@ import javax.swing.tree.TreePath;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class CodeMPToolWindowFactory implements ToolWindowFactory, DumbAware {
|
public class CodeMPToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||||
|
@ -102,6 +98,20 @@ public class CodeMPToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||||
this.add(tree);
|
this.add(tree);
|
||||||
}
|
}
|
||||||
case JOINED -> {
|
case JOINED -> {
|
||||||
|
JButton createButton = new JButton(new AbstractAction("Create buffer") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String bufferPath = Messages.showInputDialog(
|
||||||
|
"Name of buffer:",
|
||||||
|
"CodeMP Buffer Create",
|
||||||
|
Messages.getQuestionIcon()
|
||||||
|
);
|
||||||
|
|
||||||
|
InteractionUtil.bufferCreate(project, bufferPath);
|
||||||
|
CodeMPToolWindow.this.redraw(project);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
JTree tree = drawTree(CodeMP.getActiveWorkspace().getFileTree(Optional.empty(), false));
|
JTree tree = drawTree(CodeMP.getActiveWorkspace().getFileTree(Optional.empty(), false));
|
||||||
tree.addMouseListener(new SimpleMouseListener() {
|
tree.addMouseListener(new SimpleMouseListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -124,46 +134,11 @@ public class CodeMPToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
controller.callback(bufferController -> {
|
controller.callback(buf -> new BufferCallback(project).accept(buf));
|
||||||
ApplicationManager.getApplication().runReadAction(() -> {
|
|
||||||
Editor editor = FileUtil.getActiveEditorByPath(project, bufferController.getName());
|
|
||||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> {
|
|
||||||
List<TextChange> changeList = new ArrayList<>();
|
|
||||||
while(true) {
|
|
||||||
Optional<TextChange> changeOptional;
|
|
||||||
try {
|
|
||||||
changeOptional = bufferController.tryRecv();
|
|
||||||
} catch(ControllerException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(changeOptional.isEmpty())
|
|
||||||
break;
|
|
||||||
TextChange change = changeOptional.get();
|
|
||||||
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
|
||||||
change.content, change.start, change.end);
|
|
||||||
changeList.add(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationManager.getApplication().runWriteAction(() ->
|
|
||||||
CommandProcessor.getInstance().executeCommand(
|
|
||||||
project,
|
|
||||||
() -> changeList.forEach((change) ->
|
|
||||||
editor.getDocument().replaceString(
|
|
||||||
(int) change.start, (int) change.end, change.content)
|
|
||||||
),
|
|
||||||
"CodeMPBufferReceive",
|
|
||||||
"codemp-buffer-receive",
|
|
||||||
editor.getDocument()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.add(createButton);
|
||||||
this.add(tree);
|
this.add(tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
85
src/main/java/mp/code/intellij/util/MemoryManager.java
Normal file
85
src/main/java/mp/code/intellij/util/MemoryManager.java
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
package mp.code.intellij.util;
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable;
|
||||||
|
import com.intellij.openapi.util.Disposer;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.ref.Cleaner;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows association of IntelliJ {@link Disposable Disposables} with CodeMP-related
|
||||||
|
* lifetimes (which are managed by a {@link Cleaner}).
|
||||||
|
*/
|
||||||
|
public class CodeMPMemoryManager {
|
||||||
|
private static ClientDisposable clientDisposable = null;
|
||||||
|
|
||||||
|
public static boolean startClientLifetime() {
|
||||||
|
if(clientDisposable != null) return false;
|
||||||
|
clientDisposable = new ClientDisposable();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable Disposable getClientLifetime() {
|
||||||
|
return clientDisposable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean endClientLifetime() {
|
||||||
|
if(clientDisposable == null) return false;
|
||||||
|
ClientDisposable tmp = clientDisposable;
|
||||||
|
clientDisposable = null;
|
||||||
|
Disposer.dispose(tmp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean startWorkspaceLifetime(String workspace) {
|
||||||
|
if(clientDisposable.workspaces.containsKey(workspace)) return false;
|
||||||
|
clientDisposable.workspaces.put(workspace, new DisposableWorkspace());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable Disposable getWorkspaceLifetime(String workspace) {
|
||||||
|
return clientDisposable.workspaces.get(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean endWorkspaceLifetime(String workspace, String buffer) {
|
||||||
|
if(clientDisposable == null) return false;
|
||||||
|
ClientDisposable tmp = clientDisposable;
|
||||||
|
clientDisposable = null;
|
||||||
|
Disposer.dispose(tmp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean startBufferLifetime(String workspace, String buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable Disposable getBufferLifetime(String workspace, String buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean endBufferLifetime(String workspace, String buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ClientDisposable implements Disposable {
|
||||||
|
private final Map<String, DisposableWorkspace> workspaces = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
this.workspaces.values().forEach(Disposer::dispose);
|
||||||
|
this.workspaces.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DisposableWorkspace implements Disposable {
|
||||||
|
private final Map<String, Disposable> buffers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
this.buffers.values().forEach(Disposer::dispose);
|
||||||
|
this.buffers.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/mp/code/intellij/util/cb/BufferCallback.java
Normal file
12
src/main/java/mp/code/intellij/util/cb/BufferCallback.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package mp.code.intellij.util;
|
||||||
|
|
||||||
|
import mp.code.BufferController;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class BufferCallback implements Consumer<BufferController> {
|
||||||
|
@Override
|
||||||
|
public void accept(BufferController bufferController) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package mp.code.intellij.util.cb;
|
||||||
|
|
||||||
|
public class CursorCallback {
|
||||||
|
}
|
Loading…
Reference in a new issue