From 2512bb973b0f2b432b928ae3ffbb1cf4a7abf84b Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Mon, 23 Dec 2024 08:38:50 +0000 Subject: [PATCH 1/7] feat: build insight script --- app/ydoc-server-polyglot/build.mjs | 4 ++-- app/ydoc-server-polyglot/package.json | 2 +- app/ydoc-server-polyglot/src/insight.ts | 16 ++++++++++++++++ project/Ydoc.scala | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 app/ydoc-server-polyglot/src/insight.ts diff --git a/app/ydoc-server-polyglot/build.mjs b/app/ydoc-server-polyglot/build.mjs index 80f90fd7d334..ef8c98e391a3 100644 --- a/app/ydoc-server-polyglot/build.mjs +++ b/app/ydoc-server-polyglot/build.mjs @@ -13,9 +13,9 @@ const globals = { } const ctx = await esbuild.context({ - outfile: 'dist/main.cjs', + outdir: 'dist', sourcemap: 'linked', - entryPoints: ['src/main.ts'], + entryPoints: ['src/main.ts', 'src/insight.ts'], bundle: true, platform: 'browser', define: { diff --git a/app/ydoc-server-polyglot/package.json b/app/ydoc-server-polyglot/package.json index b12f1f578d7d..9fb271c20993 100644 --- a/app/ydoc-server-polyglot/package.json +++ b/app/ydoc-server-polyglot/package.json @@ -10,7 +10,7 @@ "main": "./dist/main.js", "scripts": { "compile": "node ./build.mjs build", - "start": "node ./dist/main.cjs", + "start": "node ./dist/main.js", "dev:watch": "node ./build.mjs watch", "lint": "eslint . --cache --max-warnings=0" }, diff --git a/app/ydoc-server-polyglot/src/insight.ts b/app/ydoc-server-polyglot/src/insight.ts new file mode 100644 index 000000000000..7b8e15c1f069 --- /dev/null +++ b/app/ydoc-server-polyglot/src/insight.ts @@ -0,0 +1,16 @@ +print("Initializing Insight: " + JSON.stringify(insight)); + +insight.on("source", function(ctx, frame) { + print(`[source] ctx.uri=${ctx.uri}`) +}); + +insight.on("return", function(ctx, frame) { + print(`[return] ctx='${JSON.stringify(ctx)}'`) + print(`[return] frame='${JSON.stringify(frame)}'`) + print(`[return] ctx.returnValue='${JSON.stringify(ctx.returnValue(frame))}'`) +}, { + expressions: true, + statements: true, + roots: true, + rootNameFilter: ".*main" +}); diff --git a/project/Ydoc.scala b/project/Ydoc.scala index dbb6e5b0b9f5..cfdb21e567f8 100644 --- a/project/Ydoc.scala +++ b/project/Ydoc.scala @@ -62,7 +62,7 @@ object Ydoc { } val generatedYdocServerJs = - base / "app" / "ydoc-server-polyglot" / "dist" / "main.cjs" + base / "app" / "ydoc-server-polyglot" / "dist" / "main.js" IO.copyFile(generatedYdocServerJs, resourceYdocServerJs) } From 4477b4a3ce80a3c3bb34d11cb35914480cc1a7f8 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 25 Dec 2024 13:49:38 +0000 Subject: [PATCH 2/7] feat: initialize polyfill parser --- .../org/enso/interpreter/epb/EpbContext.java | 3 +++ .../org/enso/ydoc/polyfill/ParserPolyfill.java | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/EpbContext.java b/engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/EpbContext.java index c688e1264595..a837123c48a3 100644 --- a/engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/EpbContext.java +++ b/engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/EpbContext.java @@ -11,6 +11,7 @@ import java.util.concurrent.Executors; import java.util.function.Function; import java.util.logging.Level; +import org.enso.ydoc.polyfill.ParserPolyfill; import org.enso.ydoc.polyfill.web.WebEnvironment; import org.graalvm.polyglot.Value; @@ -86,6 +87,7 @@ public void log(Level level, String msg, Object... args) { final void initializePolyfill(Node node, TruffleContext ctx) { if (!polyfillInitialized) { + var parserPolyfill = new ParserPolyfill(); polyfillInitialized = true; var exec = Executors.newSingleThreadScheduledExecutor(); Function eval = @@ -99,6 +101,7 @@ final void initializePolyfill(Node node, TruffleContext ctx) { } }; WebEnvironment.initialize(eval, exec); + parserPolyfill.initialize(eval); } } } diff --git a/lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/ParserPolyfill.java b/lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/ParserPolyfill.java index 5713c4b28e52..8589c8e5ff44 100644 --- a/lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/ParserPolyfill.java +++ b/lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/ParserPolyfill.java @@ -8,6 +8,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.URL; +import java.util.function.Function; + public final class ParserPolyfill implements ProxyExecutable { private static final Logger log = LoggerFactory.getLogger(ParserPolyfill.class); @@ -22,10 +25,17 @@ public final class ParserPolyfill implements ProxyExecutable { public ParserPolyfill() {} public void initialize(Context ctx) { - Source parserJs = - Source.newBuilder("js", ParserPolyfill.class.getResource(PARSER_JS)).buildLiteral(); + Function eval = + (url) -> { + var src = Source.newBuilder("js", url).buildLiteral(); + return ctx.eval(src); + }; + initialize(eval); + } - ctx.eval(parserJs).execute(this); + public void initialize(Function eval) { + final Value fn = eval.apply(getClass().getResource(PARSER_JS)); + fn.execute(this); } @Override From 31c97b94928be03cbc8bb2f3eb985ceb03ef20fa Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 25 Dec 2024 15:30:08 +0000 Subject: [PATCH 3/7] DRAFT: insight parse tree --- app/ydoc-server-polyglot/package.json | 3 ++- app/ydoc-server-polyglot/src/insight.ts | 32 +++++++++++++++++++--- app/ydoc-server-polyglot/tsconfig.json | 5 +++- pnpm-lock.yaml | 35 ++++++++++++++++++------- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/app/ydoc-server-polyglot/package.json b/app/ydoc-server-polyglot/package.json index 9fb271c20993..bd3640b70936 100644 --- a/app/ydoc-server-polyglot/package.json +++ b/app/ydoc-server-polyglot/package.json @@ -16,7 +16,8 @@ }, "dependencies": { "ydoc-server": "workspace:*", - "ydoc-shared": "workspace:*" + "ydoc-shared": "workspace:*", + "yjs": "^13.6.7" }, "devDependencies": { "@fal-works/esbuild-plugin-global-externals": "^2.1.2", diff --git a/app/ydoc-server-polyglot/src/insight.ts b/app/ydoc-server-polyglot/src/insight.ts index 7b8e15c1f069..5917f23b90ca 100644 --- a/app/ydoc-server-polyglot/src/insight.ts +++ b/app/ydoc-server-polyglot/src/insight.ts @@ -1,16 +1,40 @@ +import { deserializeIdMap } from 'ydoc-server' +import * as Ast from 'ydoc-shared/ast' +import { splitFileContents } from 'ydoc-shared/ensoFile' +import { ModuleDoc } from 'ydoc-shared/yjsModel' +import * as Y from 'yjs' + print("Initializing Insight: " + JSON.stringify(insight)); +const PROJECT_NAME = 'NewProject1' +const doc = new ModuleDoc(new Y.Doc()); +const syncModule = new Ast.MutableModule(doc.ydoc) + +function parseContents(contents: string, syncModule: Ast.MutableModule) { + const { code, idMapJson, metadataJson } = splitFileContents(contents) + const parsedIdMap = deserializeIdMap(idMapJson) + + const { root, spans } = Ast.parseModuleWithSpans(code, syncModule) + syncModule.setRoot(root) + + Ast.setExternalIds(syncModule, spans, parsedIdMap) + print(`[parseContents] idMap.entries=${parsedIdMap.entries()}`) +} + insight.on("source", function(ctx, frame) { - print(`[source] ctx.uri=${ctx.uri}`) + print(`[source] ctx.uri=${ctx.name}`) + if (ctx.name.includes(PROJECT_NAME)) { + print(`[source] MATCHED ctx=${JSON.stringify(ctx)}`) + parseContents(ctx.characters, syncModule) + } }); insight.on("return", function(ctx, frame) { print(`[return] ctx='${JSON.stringify(ctx)}'`) print(`[return] frame='${JSON.stringify(frame)}'`) - print(`[return] ctx.returnValue='${JSON.stringify(ctx.returnValue(frame))}'`) }, { - expressions: true, + expressions: false, statements: true, - roots: true, + roots: false, rootNameFilter: ".*main" }); diff --git a/app/ydoc-server-polyglot/tsconfig.json b/app/ydoc-server-polyglot/tsconfig.json index cbc0472e8725..7d3204c27204 100644 --- a/app/ydoc-server-polyglot/tsconfig.json +++ b/app/ydoc-server-polyglot/tsconfig.json @@ -1,7 +1,10 @@ { "extends": "../../tsconfig.json", "include": ["src/**/*.ts"], - "references": [{ "path": "../ydoc-server" }], + "references": [ + { "path": "../ydoc-server" }, + { "path": "../ydoc-shared" }, + ], "compilerOptions": { "composite": true, "noEmit": false, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc166e7b3fac..24cf168e8201 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -677,7 +677,7 @@ importers: version: 31.2.0 electron-builder: specifier: ^24.13.3 - version: 24.13.3(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)) + version: 24.13.3(electron-builder-squirrel-windows@24.13.3) enso-common: specifier: workspace:* version: link:../../common @@ -802,6 +802,9 @@ importers: ydoc-shared: specifier: workspace:* version: link:../ydoc-shared + yjs: + specifier: ^13.6.7 + version: 13.6.18 devDependencies: '@fal-works/esbuild-plugin-global-externals': specifier: ^2.1.2 @@ -4638,6 +4641,7 @@ packages: encoding-down@6.3.0: resolution: {integrity: sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==} engines: {node: '>=6'} + deprecated: Superseded by abstract-level (https://github.com/Level/community#faq) end-of-stream@1.4.4: resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==} @@ -5796,14 +5800,17 @@ packages: level-codec@9.0.2: resolution: {integrity: sha512-UyIwNb1lJBChJnGfjmO0OR+ezh2iVu1Kas3nvBS/BzGnx79dv6g7unpKIDNPMhfdTEGoc7mC8uAu51XEtX+FHQ==} engines: {node: '>=6'} + deprecated: Superseded by level-transcoder (https://github.com/Level/community#faq) level-concat-iterator@2.0.1: resolution: {integrity: sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==} engines: {node: '>=6'} + deprecated: Superseded by abstract-level (https://github.com/Level/community#faq) level-errors@2.0.1: resolution: {integrity: sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==} engines: {node: '>=6'} + deprecated: Superseded by abstract-level (https://github.com/Level/community#faq) level-iterator-stream@4.0.2: resolution: {integrity: sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==} @@ -5816,6 +5823,7 @@ packages: level-packager@5.1.1: resolution: {integrity: sha512-HMwMaQPlTC1IlcwT3+swhqf/NUO+ZhXVz6TY1zZIIZlIR0YSn8GtAAWmIvKjNY16ZkEg/JcpAuQskxsXqC0yOQ==} engines: {node: '>=6'} + deprecated: Superseded by abstract-level (https://github.com/Level/community#faq) level-supports@1.0.1: resolution: {integrity: sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==} @@ -7943,6 +7951,9 @@ packages: vue-component-type-helpers@2.1.10: resolution: {integrity: sha512-lfgdSLQKrUmADiSV6PbBvYgQ33KF3Ztv6gP85MfGaGaSGMTXORVaHT1EHfsqCgzRNBstPKYDmvAV9Do5CmJ07A==} + vue-component-type-helpers@2.2.0: + resolution: {integrity: sha512-cYrAnv2me7bPDcg9kIcGwjJiSB6Qyi08+jLDo9yuvoFQjzHiPTzML7RnkJB1+3P6KMsX/KbCD4QE3Tv/knEllw==} + vue-demi@0.14.10: resolution: {integrity: sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==} engines: {node: '>=12'} @@ -9350,7 +9361,7 @@ snapshots: '@humanwhocodes/retry@0.3.1': {} - '@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2)': + '@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.5.2)(prettier@3.3.2)': dependencies: '@babel/core': 7.25.2 '@babel/generator': 7.26.2 @@ -9359,6 +9370,8 @@ snapshots: '@babel/types': 7.26.0 prettier: 3.3.2 semver: 7.6.3 + optionalDependencies: + '@vue/compiler-sfc': 3.5.2 transitivePeerDependencies: - supports-color optional: true @@ -11072,7 +11085,7 @@ snapshots: ts-dedent: 2.2.0 type-fest: 2.19.0 vue: 3.5.2(typescript@5.5.3) - vue-component-type-helpers: 2.1.10 + vue-component-type-helpers: 2.2.0 '@stripe/react-stripe-js@2.7.2(@stripe/stripe-js@3.5.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: @@ -11999,7 +12012,7 @@ snapshots: app-builder-bin@4.0.0: {} - app-builder-lib@24.13.3(dmg-builder@24.13.3(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)): + app-builder-lib@24.13.3(dmg-builder@24.13.3)(electron-builder-squirrel-windows@24.13.3): dependencies: '@develar/schema-utils': 2.6.5 '@electron/notarize': 2.2.1 @@ -12954,7 +12967,7 @@ snapshots: dmg-builder@24.13.3(electron-builder-squirrel-windows@24.13.3): dependencies: - app-builder-lib: 24.13.3(dmg-builder@24.13.3(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)) + app-builder-lib: 24.13.3(dmg-builder@24.13.3)(electron-builder-squirrel-windows@24.13.3) builder-util: 24.13.1 builder-util-runtime: 9.2.4 fs-extra: 10.1.0 @@ -13047,7 +13060,7 @@ snapshots: electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3): dependencies: - app-builder-lib: 24.13.3(dmg-builder@24.13.3(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)) + app-builder-lib: 24.13.3(dmg-builder@24.13.3)(electron-builder-squirrel-windows@24.13.3) archiver: 5.3.2 builder-util: 24.13.1 fs-extra: 10.1.0 @@ -13055,9 +13068,9 @@ snapshots: - dmg-builder - supports-color - electron-builder@24.13.3(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)): + electron-builder@24.13.3(electron-builder-squirrel-windows@24.13.3): dependencies: - app-builder-lib: 24.13.3(dmg-builder@24.13.3(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@24.13.3)) + app-builder-lib: 24.13.3(dmg-builder@24.13.3)(electron-builder-squirrel-windows@24.13.3) builder-util: 24.13.1 builder-util-runtime: 9.2.4 chalk: 4.1.2 @@ -15312,11 +15325,11 @@ snapshots: optionalDependencies: vue-tsc: 2.0.24(typescript@5.5.3) - prettier-plugin-tailwindcss@0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2): + prettier-plugin-tailwindcss@0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.5.2)(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2): dependencies: prettier: 3.3.2 optionalDependencies: - '@ianvs/prettier-plugin-sort-imports': 4.3.0(prettier@3.3.2) + '@ianvs/prettier-plugin-sort-imports': 4.3.0(@vue/compiler-sfc@3.5.2)(prettier@3.3.2) prettier-plugin-organize-imports: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)) prettier@3.3.2: {} @@ -16823,6 +16836,8 @@ snapshots: vue-component-type-helpers@2.1.10: {} + vue-component-type-helpers@2.2.0: {} + vue-demi@0.14.10(vue@3.5.2(typescript@5.5.3)): dependencies: vue: 3.5.2(typescript@5.5.3) From 936bf457a17955f71753f13acb1c6a8c29ce2fb6 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 26 Dec 2024 17:14:46 +0000 Subject: [PATCH 4/7] feat: enso.dev.inspectPort --- .../main/scala/org/enso/languageserver/boot/MainModule.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala b/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala index 93d369b146c2..a6dd31bbe425 100644 --- a/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala +++ b/engine/language-server/src/main/scala/org/enso/languageserver/boot/MainModule.scala @@ -316,6 +316,11 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) { RuntimeOptions.JOB_PARALLELISM, Runtime.getRuntime.availableProcessors().toString ) + if (System.getProperty("enso.dev.inspectPort") != null) { + val inspectPort = Integer.getInteger("enso.dev.inspectPort", 34567); + extraOptions.put("inspect", s":$inspectPort") + stdErr.attach(arr => System.out.write(arr)) + } val builder = ContextFactory .create() From d9ce757acafa4fc37599d3e73b5d546e106eb5da Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 27 Dec 2024 16:04:35 +0000 Subject: [PATCH 5/7] DRAFT: set widget metadata --- app/ydoc-server-polyglot/src/insight.ts | 45 ++++++++++++++++++++++--- app/ydoc-shared/src/ast/index.ts | 2 +- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/ydoc-server-polyglot/src/insight.ts b/app/ydoc-server-polyglot/src/insight.ts index 5917f23b90ca..d32e43ca822b 100644 --- a/app/ydoc-server-polyglot/src/insight.ts +++ b/app/ydoc-server-polyglot/src/insight.ts @@ -7,8 +7,11 @@ import * as Y from 'yjs' print("Initializing Insight: " + JSON.stringify(insight)); const PROJECT_NAME = 'NewProject1' -const doc = new ModuleDoc(new Y.Doc()); +const RETURN_VALUE_KEY = 'insight_return_value' + +const doc = new ModuleDoc(new Y.Doc()) const syncModule = new Ast.MutableModule(doc.ydoc) +let spanMap = null function parseContents(contents: string, syncModule: Ast.MutableModule) { const { code, idMapJson, metadataJson } = splitFileContents(contents) @@ -16,6 +19,7 @@ function parseContents(contents: string, syncModule: Ast.MutableModule) { const { root, spans } = Ast.parseModuleWithSpans(code, syncModule) syncModule.setRoot(root) + spanMap = spans Ast.setExternalIds(syncModule, spans, parsedIdMap) print(`[parseContents] idMap.entries=${parsedIdMap.entries()}`) @@ -27,14 +31,45 @@ insight.on("source", function(ctx, frame) { print(`[source] MATCHED ctx=${JSON.stringify(ctx)}`) parseContents(ctx.characters, syncModule) } -}); +}) + +function resultToString(result: any): string { + return '' + result; +} +/* + class IdMap { + private readonly rangeToExpr: Map + } + interface SpanMap { + nodes: Map + tokens: Map + } + type NodeKey = TokenKey = SourceRangeKey + */ insight.on("return", function(ctx, frame) { print(`[return] ctx='${JSON.stringify(ctx)}'`) print(`[return] frame='${JSON.stringify(frame)}'`) + print(`[return] ctx.returnValue='${ctx.returnValue(frame)}'`) + + const result = ctx.returnValue(frame) + if (result && spanMap) { + const key = Ast.nodeKey(ctx.charIndex, ctx.charEndIndex - ctx.charIndex) + const asts = spanMap.nodes.get(key) + if (asts) { + const resultValue = resultToString(result) + for (const ast of asts) { + const editAst = syncModule.getVersion(ast) + if (editAst.widgetMetadata(RETURN_VALUE_KEY) !== resultValue) { + print(`[return] setWidgetMetadata ${ast.code()} : ${resultValue}`) + editAst.setWidgetMetadata(RETURN_VALUE_KEY, resultValue) + } + } + } + } }, { - expressions: false, - statements: true, + expressions: true, + statements: false, roots: false, rootNameFilter: ".*main" -}); +}) diff --git a/app/ydoc-shared/src/ast/index.ts b/app/ydoc-shared/src/ast/index.ts index 5ed296596898..0074419d28ec 100644 --- a/app/ydoc-shared/src/ast/index.ts +++ b/app/ydoc-shared/src/ast/index.ts @@ -2,7 +2,7 @@ import { reachable } from '../util/data/graph' import type { Module } from './mutableModule' import type { AstId } from './tree' -export { spanMapToIdMap } from './idMap' +export { nodeKey, spanMapToIdMap } from './idMap' export * from './mutableModule' export * from './parse' export { printWithSpans } from './print' From 50266f9d7028848bd9afef7bcb2052de2c779e7c Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Tue, 31 Dec 2024 19:37:08 +0000 Subject: [PATCH 6/7] DRAFT: y-websocket --- app/ydoc-server-polyglot/package.json | 1 + pnpm-lock.yaml | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/ydoc-server-polyglot/package.json b/app/ydoc-server-polyglot/package.json index bd3640b70936..50158d6d9ffa 100644 --- a/app/ydoc-server-polyglot/package.json +++ b/app/ydoc-server-polyglot/package.json @@ -15,6 +15,7 @@ "lint": "eslint . --cache --max-warnings=0" }, "dependencies": { + "y-websocket": "^1.5.0", "ydoc-server": "workspace:*", "ydoc-shared": "workspace:*", "yjs": "^13.6.7" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24cf168e8201..dd391022fc2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -547,7 +547,7 @@ importers: version: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)) prettier-plugin-tailwindcss: specifier: ^0.5.11 - version: 0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2) + version: 0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.5.2)(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2) resize-observer-polyfill: specifier: 1.5.1 version: 1.5.1 @@ -796,6 +796,9 @@ importers: app/ydoc-server-polyglot: dependencies: + y-websocket: + specifier: ^1.5.0 + version: 1.5.4(yjs@13.6.18) ydoc-server: specifier: workspace:* version: link:../ydoc-server From 93ba1dcfd332f21239ffce487d9bc536cd02b259 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 1 Jan 2025 10:32:31 +0000 Subject: [PATCH 7/7] DRAFT: debug websocket --- app/ydoc-server-polyglot/src/insight.ts | 58 ++++++++++++++++++- .../java/org/enso/common/ContextFactory.java | 4 +- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/app/ydoc-server-polyglot/src/insight.ts b/app/ydoc-server-polyglot/src/insight.ts index d32e43ca822b..05fcf4f383d2 100644 --- a/app/ydoc-server-polyglot/src/insight.ts +++ b/app/ydoc-server-polyglot/src/insight.ts @@ -1,18 +1,69 @@ import { deserializeIdMap } from 'ydoc-server' import * as Ast from 'ydoc-shared/ast' import { splitFileContents } from 'ydoc-shared/ensoFile' -import { ModuleDoc } from 'ydoc-shared/yjsModel' +import { DistributedProject, ModuleDoc } from 'ydoc-shared/yjsModel' +import { WebsocketProvider } from 'y-websocket' import * as Y from 'yjs' +interface SubdocsEvent { + loaded: Set + added: Set + removed: Set +} + print("Initializing Insight: " + JSON.stringify(insight)); const PROJECT_NAME = 'NewProject1' const RETURN_VALUE_KEY = 'insight_return_value' -const doc = new ModuleDoc(new Y.Doc()) -const syncModule = new Ast.MutableModule(doc.ydoc) +//const doc = new ModuleDoc(new Y.Doc()) +const doc = new Y.Doc() +const syncModule = new Ast.MutableModule(doc) let spanMap = null +function attachProvider(url: string, room: string, doc: Y.Doc) { + print(`attachProvider ${url} ${room}`) + const provider = new WebsocketProvider(url, room, doc) + const onSync = () => doc.emit('sync', [true, doc]) + const onDrop = () => doc.emit('sync', [false, doc]) + + const attachedSubdocs = new Map>() + + function onSubdocs(e: SubdocsEvent) { + e.loaded.forEach((subdoc) => { + attachedSubdocs.set(subdoc, attachProvider(url, subdoc.guid, subdoc)) + }) + e.removed.forEach((subdoc) => { + const subdocProvider = attachedSubdocs.get(subdoc) + attachedSubdocs.delete(subdoc) + if (subdocProvider != null) { + subdocProvider.dispose() + } + }) + } + + provider.on('sync', onSync) + provider.on('connection-close', onDrop) + provider.on('connection-error', onDrop) + doc.on('subdocs', onSubdocs) + + function dispose() { + provider.disconnect() + provider.off('sync', onSync) + provider.off('connection-close', onDrop) + provider.off('connection-error', onDrop) + doc.off('subdocs', onSubdocs) + attachedSubdocs.forEach((subdocProvider) => { + subdocProvider.dispose() + }) + } + return { provider, dispose } +} + +const d = new Y.Doc() +const project = new DistributedProject(d) +//const provider = attachProvider('ws://[::1]:5976/project', 'index', d) + function parseContents(contents: string, syncModule: Ast.MutableModule) { const { code, idMapJson, metadataJson } = splitFileContents(contents) const parsedIdMap = deserializeIdMap(idMapJson) @@ -52,6 +103,7 @@ insight.on("return", function(ctx, frame) { print(`[return] frame='${JSON.stringify(frame)}'`) print(`[return] ctx.returnValue='${ctx.returnValue(frame)}'`) + const p = project const result = ctx.returnValue(frame) if (result && spanMap) { const key = Ast.nodeKey(ctx.charIndex, ctx.charEndIndex - ctx.charIndex) diff --git a/engine/common/src/main/java/org/enso/common/ContextFactory.java b/engine/common/src/main/java/org/enso/common/ContextFactory.java index 79c1e5a9ee47..a7deb5796ab6 100644 --- a/engine/common/src/main/java/org/enso/common/ContextFactory.java +++ b/engine/common/src/main/java/org/enso/common/ContextFactory.java @@ -10,6 +10,7 @@ import org.enso.logging.config.LoggerSetup; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.HostAccess; +import org.graalvm.polyglot.io.IOAccess; import org.graalvm.polyglot.io.MessageTransport; import org.slf4j.event.Level; @@ -165,6 +166,7 @@ public Context build() { Context.newBuilder() .allowExperimentalOptions(true) .allowAllAccess(true) + .allowIO(IOAccess.ALL) .allowHostAccess(allWithTypeMapping()) .option(RuntimeOptions.STRICT_ERRORS, Boolean.toString(strictErrors)) .option(RuntimeOptions.DISABLE_LINTING, Boolean.toString(disableLinting)) @@ -252,7 +254,7 @@ public Context build() { } private static HostAccess allWithTypeMapping() { - return HostAccess.newBuilder() + return HostAccess.newBuilder(HostAccess.EXPLICIT) .allowPublicAccess(true) .allowAllImplementations(true) .allowAllClassImplementations(true)