-
Notifications
You must be signed in to change notification settings - Fork 334
Execute yjs from insight script #11965
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
That's working:
What's in progress:
|
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.
Thanks Dmitry for finding a way to convert insight
offsets to ASTs!
const result = ctx.returnValue(frame) | ||
if (result && spanMap) { | ||
const key = Ast.nodeKey(ctx.charIndex, ctx.charEndIndex - ctx.charIndex) | ||
const asts = spanMap.nodes.get(key) |
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 see. Whenever we get an insight.on('return', ...)
event, we look appropriate asts
and update them. I am not sure how fast this is, but it certainly seems good enough for demonstration purposes.
} | ||
}, { | ||
expressions: true, | ||
statements: false, |
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 believe n = 42
would be a statement
- e.g. if you want to observe when "IDE nodes" are being assigned to, you may want to observe statements.
engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala
Outdated
Show resolved
Hide resolved
engine/common/src/main/java/org/enso/common/ContextFactory.java
Outdated
Show resolved
Hide resolved
engine/common/src/main/java/org/enso/common/ContextFactory.java
Outdated
Show resolved
Hide resolved
|
|
||
const d = new Y.Doc() | ||
const project = new DistributedProject(d) | ||
//const provider = attachProvider('ws://[::1]:5976/project', 'index', d) |
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.
Uncomment attachProvider
method to reproduce the issue
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.
If I comment out the line with 814eb91 I get following errors:
Initializing Insight: {"id":"insight","version":"1.2"}
attachProvider ws://[::1]:5976/project index
[WARN] [2025-03-14T09:43:00.619] [org.enso.languageserver.protocol.json.JsonConnectionController] Failed to initialize resources
java.util.concurrent.CompletionException: org.graalvm.polyglot.PolyglotException: java.net.ConnectException: Connection refused
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
at org.enso.akka.wrapper/akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:49)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1423)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: org.graalvm.polyglot.PolyglotException: java.net.ConnectException: Connection refused
at <js>.WebSocket(websocket.js:132)
at <js>.setupWS(insight.js:26888)
at <js>.connect(insight.js:27164)
at <js>.WebsocketProvider(insight.js:27073)
at <js>.attachProvider(insight.js:27179)
at <js>.poly_enso_eval(insight.js:27213)
I hope that means the WebSocket
infrastructure is working fine, it is just misconfigured. What do you think, @4e6?
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 one would be resolved by providing
?ls=...
argument to the URL - or by adopting Automatically select the only available session #13168
@JaroslavTulach there is an issue with WebSocket connections from inside the insight script. You can reproduce it by trying to establish any connection, i.e. let ws = new WebSocket('wss://echo.websocket.org') |
The Chrome Dev Tools debugging shows an exception when creating new socket:
Concatenate the last three lines to a single |
This is the testing var counter = 0;
function app() {
let ws = new WebSocket('wss://echo.websocket.org');
function sayHi() {
ws.send(`Hi there! #${counter++}`);
}
ws.onopen = function(ev) {
print("Open: " + ev);
};
ws.onmessage = function(ev) {
print("Msg : " + Object.getOwnPropertyNames(ev));
print(" data: " + ev.data);
setTimeout(sayHi, 3000);
};
ws.onclose = function(ev) {
print("Close: " + Object.getOwnPropertyNames(ev));
};
ws.onerror = function(ev) {
print("Err: " + Object.getOwnPropertyNames(ev));
};
}
if (typeof insight === "undefined") {
globalThis.print = console.log;
if (typeof WebSocket === "undefined") {
let r = require("ws");
globalThis.WebSocket = r.WebSocket;
}
app();
} else {
app();
} the testing script can by used from node ( I can confirm, the connection gets randomly broken in the GUI. The cause is multithreadedness. GraalVM JavaScript isn't ready to be used from multiple threads. References:
We need to use better Update on Apr 11, 2025:
|
|
e8558ca
to
f383682
Compare
✨ GUI Checks ResultsSummary
See individual check results for more details. ℹ️ Chromatic Tests SkippedChromatic visual regression tests were skipped for this PR. To run the tests and deploy Storybook, add the Note: We skip tests by default to optimize CI costs. Only run them when your UI changes are ready for review. 👮 Lint GUI ResultsCheck Results
ESLint3 Warning(s):
|
#length; | ||
|
||
constructor(buffer) { | ||
constructor(buffer, offset, length) { |
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 one is here to support Buffer.from(arrayBuffer[, byteOffset[, length]]). Originally I tried to just extract offset
and length
from buffer
, create a copy of such buffer and pass it into the old constructor. But that doesn't seem to work.
The Buffer.from(arrayBuffer[, byteOffset[, length]]) factory method is supposed to provide live view of the buffer. E.g. further changes are still propagated to the buffer.
As such we are extracting the slice
lazily in buffer()
getter. With that approach we pass thru the new tests in 8e21525
* | ||
* The {@code enso-engine-*?/enso-*?/component/} represents path to the @{code component} directory | ||
* which needs to be adjusted to proper path on each operating system. All lines may need to be | ||
* concatenated into a single line. |
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 WebSocketClient
should be a useful utility for testing compatibility of the emulation with real node.js implementation.
System.out.printf("Script %s evaluated to %s\n", code, res); | ||
var console = System.console(); | ||
for (int i = 0; i < 10; i++) { | ||
var line = console.readLine("js> "); |
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 console.readLine seems to work surprisingly well. It supports arrow movements and even provides history of previous entries. Isn't it time to replace JLine
with it? Isn't the console actually backed by JLine (repackaged)?
…orking directory in --env specification
var keyAndValue = args.get(atEnv + 1).split("=", 2) | ||
if (jvmOptName == keyAndValue(0)) { | ||
prevValue = prevValue + " " + keyAndValue(1) | ||
val (key, value) = { |
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.
With these changes, it is possible to:
$ sbt
sbt:enso> runProjectManagerDistribution
--env ENSO_JVM_OPTS=-Denso.dev.insight=$PWD/app/ydoc-server-polyglot/dist/insight.js
--env ENSO_JVM_OPTS=-Dpolyglot.inspect
e.g. to influence the environment variable ENSO_JVM_OPTS
from sbt
shell itself (please concatenate the above example to single sbt
command line). No need to restart sbt
to change the arguments anymore.
…Sending message to GUI and stacktrace to the console and log file.
...e/runtime-instrument-common/src/main/java/org/enso/interpreter/service/ExecutionService.java
Show resolved
Hide resolved
if (asts) { | ||
const resultValue = resultToString(result) | ||
for (const ast of asts) { | ||
const editAst = syncModule.getVersion(ast) |
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.
- with Demo: Support displaying ExpressionUpdates found in AST metadata #13179
- we should modify this part to
;(ast as any).fields.get('metadata').set('expressionUpdate', update)
- e.g. to update the Y.doc server to a value the IDE expects and renders
Pull Request Description
Allow populating Yjs metadata with values provided by the insight script.
Compile the Insight Script
Run pnpm install
Build
app/ydoc-server/polyglot/insight.js
bundle withRunning
Start the project manager specifying the insight script location with
ENSO_JVM_OPTS
env variableENSO_JVM_OPTS="-Denso.dev.insight=$PWD/app/ydoc-server-polyglot/dist/insight.js"
Every time the
insight.js
is rebuilt, the engine reloads it automatically.Debugging (in Chrome Dev Tools)
Add
-Dpolyglot.inspect
argument:ENSO_JVM_OPTS="-Denso.dev.insight=$PWD/app/ydoc-server-polyglot/dist/insight.js -Dpolyglot.inspect"
The Engine stops and waits for Chrome Dev Tools to connect to it just like it waits for node.js processes.
Don't Suspend
By default the Chrome Dev Tools integration stops on first executed JavaScript statement. That may not be appropriate in all situations. Add
-Dpolyglot.inspect.Suspend=false
to theENSO_JVM_OPTS
to disable such behavior. The engine still connects to Chrome Dev Tools, but stops only on breakpoints or when pause is explicitly requested in the debugger.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.