Skip to content

Commit ae2e02d

Browse files
committed
chore(java): aligned signatures to rust side
1 parent a10dcf2 commit ae2e02d

8 files changed

Lines changed: 75 additions & 66 deletions

File tree

dist/java/src/mp/code/CursorController.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package mp.code;
22

3-
import mp.code.proto.Cursor;
4-
import mp.code.proto.Selection;
3+
import mp.code.proto.CursorUpdate;
4+
import mp.code.proto.CursorEvent;
5+
import mp.code.proto.CursorPosition;
56
import mp.code.proto.WorkspaceIdentifier;
67
import mp.code.exceptions.ControllerException;
78

@@ -31,43 +32,43 @@ public WorkspaceIdentifier workspaceId() {
3132
return workspace_id(this.ptr);
3233
}
3334

34-
private static native Cursor try_recv(long self) throws ControllerException;
35+
private static native CursorEvent try_recv(long self) throws ControllerException;
3536

3637
/**
37-
* Tries to get a {@link Cursor} update from the queue if any were present, null otherwise.
38-
* @return the first cursor update in queue, if any are present
38+
* Tries to get a {@link CursorEvent} from the queue if any were present, null otherwise.
39+
* @return the first cursor event in queue, if any are present
3940
* @throws ControllerException if the controller was stopped
4041
*/
41-
public Cursor tryRecv() throws ControllerException {
42+
public CursorEvent tryRecv() throws ControllerException {
4243
return try_recv(this.ptr);
4344
}
4445

45-
private static native Cursor recv(long self) throws ControllerException;
46+
private static native CursorUpdate recv(long self) throws ControllerException;
4647

4748
/**
48-
* Blocks until a {@link Cursor} update is available and returns it.
49-
* @return the cursor update that occurred
49+
* Blocks until a {@link CursorEvent} is available and returns it.
50+
* @return the cursor event that occurred
5051
* @throws ControllerException if the controller was stopped
5152
*/
52-
public Cursor recv() throws ControllerException {
53+
public CursorUpdate recv() throws ControllerException {
5354
return recv(this.ptr);
5455
}
5556

56-
private static native void send(long self, Selection selection) throws ControllerException;
57+
private static native void send(long self, CursorUpdate selection) throws ControllerException;
5758

5859
/**
59-
* Tries to send a {@link Selection} update.
60-
* @param selection the update to send
60+
* Tries to send a {@link CursorPosition} update.
61+
* @param update the update to send
6162
* @throws ControllerException if the controller was stopped
6263
*/
63-
public void send(Selection selection) throws ControllerException {
64-
send(this.ptr, selection);
64+
public void send(CursorUpdate update) throws ControllerException {
65+
send(this.ptr, update);
6566
}
6667

6768
private static native void callback(long self, Consumer<CursorController> cb);
6869

6970
/**
70-
* Registers a callback to be invoked whenever a {@link Cursor} update occurs.
71+
* Registers a callback to be invoked whenever a {@link CursorUpdate} update occurs.
7172
* This will not work unless a Java thread has been dedicated to the event loop.
7273
* @param cb a {@link Consumer} that receives the controller when the change occurs;
7374
* you should probably spawn a new thread in here, to avoid deadlocking
@@ -90,7 +91,7 @@ public void clearCallback() {
9091
private static native void poll(long self) throws ControllerException;
9192

9293
/**
93-
* Blocks until a {@link Cursor} update is available.
94+
* Blocks until a {@link CursorUpdate} update is available.
9495
* @throws ControllerException if the controller was stopped
9596
*/
9697
public void poll() throws ControllerException {

dist/java/src/mp/code/Workspace.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package mp.code;
22

3-
import java.util.Optional;
43
import java.util.function.Consumer;
54

65
import mp.code.proto.UserInfo;
76
import mp.code.exceptions.ConnectionException;
87
import mp.code.exceptions.ConnectionRemoteException;
98
import mp.code.exceptions.ControllerException;
109
import mp.code.proto.WorkspaceEvent;
10+
import mp.code.proto.WorkspaceIdentifier;
1111

1212
/**
1313
* Represents a CodeMP workspace, which broadly speaking is a collection
@@ -25,13 +25,13 @@ public final class Workspace {
2525
Extensions.CLEANER.register(this, () -> free(ptr));
2626
}
2727

28-
private static native String id(long self);
28+
private static native WorkspaceIdentifier id(long self);
2929

3030
/**
3131
* Gets the unique identifier of the current workspace.
32-
* @return the identifier
32+
* @return the {@link WorkspaceIdentifier} for this workspace
3333
*/
34-
public String id() {
34+
public WorkspaceIdentifier id() {
3535
return id(this.ptr);
3636
}
3737

@@ -51,10 +51,10 @@ public CursorController cursor() {
5151
* Looks for a {@link BufferController} with the given path within the
5252
* current workspace and returns it if it exists.
5353
* @param path the current path
54-
* @return the {@link BufferController} with the given path, if it exists
54+
* @return the {@link BufferController} with the given path, if it exists, null otherwise
5555
*/
56-
public Optional<BufferController> getBuffer(String path) {
57-
return Optional.ofNullable(get_buffer(this.ptr, path));
56+
public BufferController getBuffer(String path) {
57+
return get_buffer(this.ptr, path);
5858
}
5959

6060
private static native String[] search_buffers(long self, String filter);

dist/java/src/mp/code/proto/Config.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package mp.code.proto;
22

3-
import lombok.AccessLevel;
43
import lombok.EqualsAndHashCode;
54
import lombok.RequiredArgsConstructor;
65
import lombok.ToString;
@@ -10,7 +9,7 @@
109
*/
1110
@ToString
1211
@EqualsAndHashCode
13-
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
12+
@RequiredArgsConstructor
1413
public class Config {
1514
/** The username to connect with. */
1615
public final String username;

dist/java/src/mp/code/proto/CursorEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public class CursorEvent {
1919
/**
2020
* The cursor position data.
2121
*/
22-
public final Cursor cursor;
22+
public final CursorUpdate position;
2323
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package mp.code.proto;
2+
3+
import lombok.EqualsAndHashCode;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.ToString;
6+
7+
/**
8+
* A data class holding information about a cursor selection.
9+
*/
10+
@ToString
11+
@EqualsAndHashCode
12+
@RequiredArgsConstructor
13+
public class CursorPosition {
14+
/**
15+
* The start of the cursor's position.
16+
*/
17+
public final RowCol start;
18+
19+
/**
20+
* The end of the cursor's position.
21+
*/
22+
public final RowCol end;
23+
}

dist/java/src/mp/code/proto/Cursor.java renamed to dist/java/src/mp/code/proto/CursorUpdate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@ToString
1111
@EqualsAndHashCode
1212
@RequiredArgsConstructor
13-
public class Cursor {
13+
public class CursorUpdate {
1414
/**
1515
* The buffer the cursor is on.
1616
*/
@@ -19,5 +19,5 @@ public class Cursor {
1919
/**
2020
* The associated selection updates.
2121
*/
22-
public final Selection[] selection;
22+
public final CursorPosition[] cursors;
2323
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package mp.code.proto;
2+
3+
import lombok.EqualsAndHashCode;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.ToString;
6+
7+
/**
8+
* A data class representing a position in a buffer.
9+
*/
10+
@ToString
11+
@EqualsAndHashCode
12+
@RequiredArgsConstructor
13+
public class RowCol {
14+
/**
15+
* The row. If negative, it is clamped to 0.
16+
*/
17+
public final int row;
18+
19+
/**
20+
* The column. If negative, it is clamped to 0.
21+
*/
22+
public final int col;
23+
}

dist/java/src/mp/code/proto/Selection.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)