-
Notifications
You must be signed in to change notification settings - Fork 334
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
486cb1d to
c1ee0ea
Compare
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?
|
|
||
| // Polyfill DOM event types for Node.js environment | ||
| if (typeof globalThis.CloseEvent === 'undefined') { | ||
| ;(globalThis as any).CloseEvent = class CloseEvent extends Event { |
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.
Line prefixed by ;?
| ;(globalThis as any).CloseEvent = class CloseEvent extends Event { | |
| (globalThis as any).CloseEvent = class CloseEvent extends Event { |
| 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?
| @Override | ||
| public void onConnect(YjsChannel channel) { |
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.
| @Override | |
| public void onConnect(YjsChannel channel) { | |
| @Override | |
| @HostAccess.Export | |
| public void onConnect(YjsChannel channel) { |
| // public access is required to recognize Java lambdas passed to | ||
| // `YjsChannel::subscribe` method as JS functions. | ||
| .allowPublicAccess(true) | ||
| .allowAccess(TestCallbacks.class.getDeclaredMethod("onConnect", 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.
| .allowAccess(TestCallbacks.class.getDeclaredMethod("onConnect", YjsChannel.class)) | |
| // no need for TestCallbacks registration |
rather use @HostAccess.Explicit
|
|
||
| @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
| "javax.management.**;java.lang.**;java.rmi.**;javax.security.auth.Subject;!*"); | ||
|
|
||
| if (args.length == 2) { | ||
| 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
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.