-
Notifications
You must be signed in to change notification settings - Fork 336
Replace language server WebSocket connection with Ydoc #14438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
7356274 to
4371781
Compare
| @@ -0,0 +1,3 @@ | |||
| module org.enso.ydoc.api { | |||
| exports org.enso.ydoc.api; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There is no need for a new API module.
- there already is YdocServerApi
- please put the new interfaces there as inner classes of
YdocServerApi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Possibly you can move
YdocServerApito the neworg.enso.ydoc.apimodule. - but the whole API needs to be co-located
| package org.enso.ydoc.api; | ||
|
|
||
| public class NoOpMessageCallbacks implements MessageCallbacks { | ||
| public static final NoOpMessageCallbacks INSTANCE = new NoOpMessageCallbacks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please don't put
NoOpMessagesCallbacksimplementation class into the API - remove it
- if you have to have it, then encapsulate it
- put
public static final MessageCallbacks NO_OPintoMessageCallbacksand make the implementation class package private
JaroslavTulach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ideally
HostAccessis configured internally - and both tests and production code just work with the default configuration
- possible trick to achieve that is to crate a proxy around interfaces passed to JavaScript
| return this; | ||
| } | ||
|
|
||
| public Builder hostAccessBuilder(HostAccess.Builder hostAccessBuilder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why is this a builder?
- Isn't just
HostAccessinstance good enough?
| public Builder hostAccessBuilder(HostAccess.Builder hostAccessBuilder) { | |
| public Builder hostAccess(HostAccess hostAccessBuilder) { |
- without
WebEnvironment.defaultHostAccessbeing public, one might need a builder - but having both builder and
WebEnvironment.defaultHostAccessseems unnecessary
| WebEnvironment.defaultHostAccess | ||
| // allowImplementations is required to call methods on JS objects from Java, i.e. to | ||
| // call methods on `YjsChannel` object returned from JS | ||
| .allowImplementations(YjsChannel.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- allowing implementation of a well known interface is OK
- but opening up
allowAccessto a randomcallbacks.getClass()class is a security flaw - please create a proxy around
callbacksand expose its methods- preferrably via
@HostAccess.Explicit - or via
allowAccess(ProxyMessageCallbacks.getDeclararedMethod(""))but while hardcodingProxyMessageCallbacksclass
- preferrably via
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current state with:
.allowImplementations(YjsChannel.class)
.allowPublicAccess(true);
is certainly better than the original one. Thanks.
Still, it be good to remove .allowPublicAccess(true) and use @HostAccess.Explicit annotation instead.
| @@ -0,0 +1,3 @@ | |||
| module org.enso.ydoc.api { | |||
| exports org.enso.ydoc.api; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Possibly you can move
YdocServerApito the neworg.enso.ydoc.apimodule. - but the whole API needs to be co-located
71e9b86 to
8713e6f
Compare
lib/scala/json-rpc-server/src/main/scala/org/enso/jsonrpc/YdocJsonRpcServer.scala
Show resolved
Hide resolved
app/ydoc-channel/src/YjsChannel.ts
Outdated
| for (const item of items) { | ||
| // Only notify handlers if the message is from another sender | ||
| if (item.senderId !== this.senderId) { | ||
| this.notifyHandlers(item.payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- As of 8713e6f we are probably dealing with ever growing
Y.Array - somehow we need to find out that the "message has been delivered" to all handlers
- that's kind of hard in a distributed framework
- where handlers can appear and diappear
- one solution would be to add
receiverIdtoitem- deliver the message only when
senderIdmatchesreceiverId - e.g.
if (item.receiverId === this.senderId)` - if there was only one receiver of a message
- then it'd be the receiver's responsibility to remove the
itemfromarray
- deliver the message only when
f122b95 to
9625b1f
Compare
JaroslavTulach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all looks quite decent. Few comments inline.
| /** | ||
| * A bidirectional communication channel backed by Y.Array. | ||
| * | ||
| * This class allows multiple parties to send and receive messages through a shared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- really "multiple parties"?
- shouldn't the
YjsChannelbe just bidirectional?
| import java.util.ServiceLoader; | ||
| import org.enso.ydoc.api.MessageCallbacks; | ||
|
|
||
| public abstract class YdocServerApi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we put YdocServerApi into org.enso.ydoc.api module as well? As this comment suggests?
lib/java/ydoc-polyfill/src/test/java/org/enso/ydoc/api/CallbacksTest.java
Show resolved
Hide resolved
lib/java/ydoc-polyfill/src/test/java/org/enso/ydoc/api/CallbacksTest.java
Show resolved
Hide resolved
|
|
||
| @Test | ||
| public void onConnectSend() throws Exception { | ||
| var res = new AtomicReference<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'd slightly prefer you to create
CountingTestclass and register its instance instead - annotate its
setmethod with@HostAccess.Explicit
| @@ -25,21 +28,22 @@ public static void main(String[] args) throws Exception { | |||
| var then = System.currentTimeMillis(); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is this
public static void mainstill useful for anything? - Shouldn't it be removed?
| WebEnvironment.defaultHostAccess | ||
| // allowImplementations is required to call methods on JS objects from Java, i.e. to | ||
| // call methods on `YjsChannel` object returned from JS | ||
| .allowImplementations(YjsChannel.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current state with:
.allowImplementations(YjsChannel.class)
.allowPublicAccess(true);
is certainly better than the original one. Thanks.
Still, it be good to remove .allowPublicAccess(true) and use @HostAccess.Explicit annotation instead.
| var bindings = ctx.getBindings("js"); | ||
| bindings.putMember("YDOC_HOST", hostname); | ||
| bindings.putMember("YDOC_PORT", port); | ||
| bindings.putMember("YDOC_MESSAGE_CALLBACKS", callbacks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- registering non-primitive type as global symbol seems strange
- with
YDOC_HOSTone could post it as environment variable, but - one cannot register
callbacksvia environment variable - why don't create a initializeYdocServer function
- and call it here directly with proper arguments?
app/ydoc-server-polyglot/src/main.ts
Outdated
|
|
||
| configureAllDebugLogs(debug) | ||
|
|
||
| if (YDOC_MESSAGE_CALLBACKS == undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this check makes
main.tsunusable from command line- at least I believe usage from CLI was the motivation for these
YDOC_(environment) variables
- at least I believe usage from CLI was the motivation for these
- why don't we define:
function initializeYdocServer(YDOC_HOST, YDOC_PORT, YDOC_LS_DEBUG, YDOC_MESSAGE_CALLBACKS) {- and then just call this method with proper arguments from Java?
27df1af to
b5f7639
Compare
149e994 to
9a35c00
Compare
| } | ||
| } | ||
| public static void main(String[] args) { | ||
| // main method declaration is required to build the native library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- GraalVM
native-imagedoesn't needmainmethod - probably the invocation logic in NativeImage.scala is wrong
enso/project/NativeImage.scala
Line 260 in a282b3a
args ++= Seq("-jar", pathToJAR.toString) - when there is no
mainClassthen we shouldn't pass in any option - especially when
shared=true
| assert impl != null; | ||
| var arr = ProxyArray.fromArray(hostname, "" + port); | ||
| impl.invokeMember("main", arr); | ||
| impl.invokeMember("launch", hostname, port + "", jsonChannelCallbacks, binaryChannelCallbacks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the
launchmethod is starting newThreadto form a JavaScript event loop executor - due to restrictions spelled out at Allow multiple threads to access a
Channelsimultaneously #14264- "only master can initialize connection on a new thread"
- "then slave can reply on such a thread or any other thread which was initiated previously by the master"
- thus we must start the executor here and pass it to the other JVM
- btw. previously it wasn't a problem as there were no callbacks from JavaScript to Java
89fd5f5 to
5a30daa
Compare
…nfig. No need for YjsCallbacksSynchronized constructor to be public.
dead671 to
75734a9
Compare
Pull Request Description
ydoc-servertalking directly to the engine+ls #14142Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.