diff --git a/package.json b/package.json index a09953a625e5..afb7030c1662 100644 --- a/package.json +++ b/package.json @@ -80,12 +80,12 @@ "dts-cli>eslint-plugin-react-hooks": "-", "dts-cli>eslint-plugin-testing-library": "-", "react-dev-utils>fork-ts-checker-webpack-plugin": "-", - "keyv@<5.5.3": "^5.5.3" + "keyv@<5.5.3": "^5.5.3", + "@vscode/monaco-lsp-client>monaco-editor-core": "-" }, "patchedDependencies": { "@vscode/monaco-lsp-client@0.1.0": "patches/@vscode__monaco-lsp-client@0.1.0.patch", "gatsby-remark-shiki-twoslash@3.0.38": "patches/gatsby-remark-shiki-twoslash@3.0.38.patch", - "monaco-editor-core@0.56.0": "patches/monaco-editor-core@0.56.0.patch", "coi-serviceworker@0.1.7": "patches/coi-serviceworker@0.1.7.patch", "monaco-editor@0.56.0": "patches/monaco-editor@0.56.0.patch", "query-string@6.14.1": "patches/query-string@6.14.1.patch", diff --git a/packages/playground-v2/package.json b/packages/playground-v2/package.json index 280ae51905c2..03c795304d4d 100644 --- a/packages/playground-v2/package.json +++ b/packages/playground-v2/package.json @@ -17,7 +17,6 @@ "jsonc-parser": "^3.3.1", "lz-string": "^1.5.0", "monaco-editor": "0.56.0", - "monaco-editor-core": "0.56.0", "reflect-metadata": "^0.2.2", "semver": "7.7.4", "vscode-json-languageservice": "^5.7.2", diff --git a/packages/playground-v2/scripts/build.mjs b/packages/playground-v2/scripts/build.mjs index 33dae9adbcc5..f9eb7f2e35b2 100644 --- a/packages/playground-v2/scripts/build.mjs +++ b/packages/playground-v2/scripts/build.mjs @@ -16,6 +16,7 @@ const serve = process.argv.includes("--serve") const playgroundBase = serve ? "/" : process.env.PLAYGROUND_BASE ?? playgroundPath const editorWorker = fileURLToPath(import.meta.resolve("monaco-editor/editor/editor.worker")) +const monacoEditorMain = fileURLToPath(import.meta.resolve("monaco-editor/editor/editor.main.js")) const coiServiceWorker = fileURLToPath(import.meta.resolve("coi-serviceworker/coi-serviceworker.min.js")) const indexHtml = (await readFile(resolve(packageDirectory, "src/index.html"), "utf8")).replaceAll( @@ -30,6 +31,26 @@ await Promise.all([ cp(coiServiceWorker, resolve(outputDirectory, "coi-serviceworker.min.js")), ]) +// monaco-editor-core resolves to monaco-editor's editor entry without its +// built-in language registrations, which would compete with the tsgo LSP. +const monacoEditorCorePlugin = { + name: "monaco-editor-core", + setup(build) { + build.onResolve({ filter: /^monaco-editor-core$/ }, () => ({ + path: monacoEditorMain, + namespace: "monaco-editor-core", + })) + build.onLoad({ filter: /.*/, namespace: "monaco-editor-core" }, async () => ({ + contents: (await readFile(monacoEditorMain, "utf8")) + .split("\n") + .filter(line => !/\/languages\/|monaco-lsp-client|\bas (lsp|css|html|json|typescript) \}/.test(line)) + .join("\n"), + loader: "js", + resolveDir: dirname(monacoEditorMain), + })) + }, +} + const buildContext = await context({ absWorkingDir: packageDirectory, bundle: true, @@ -51,6 +72,7 @@ const buildContext = await context({ outdir: outputDirectory, metafile: true, platform: "browser", + plugins: [monacoEditorCorePlugin], sourcemap: true, target: ["es2022"], }) @@ -69,6 +91,12 @@ if (serve) { /node_modules\/(?:@typescript\/)?typescript(?:-wasip1-wasm)?\//.test(path) ) if (compilerInputs.length) throw new Error(`Compiler implementation was bundled: ${compilerInputs.join(", ")}`) + const monacoBuiltinInputs = Object.keys(result.metafile.inputs).filter(path => + /monaco-editor\/esm\/(?:vs\/languages\/features|external\/monaco-lsp-client)\//.test(path) + ) + if (monacoBuiltinInputs.length) { + throw new Error(`Monaco built-in language services were bundled: ${monacoBuiltinInputs.join(", ")}`) + } await buildContext.dispose() await rm(websitePlayDirectory, { force: true, recursive: true }) await cp(outputDirectory, websiteStaticDirectory, { recursive: true }) diff --git a/packages/playground-v2/src/editor-touch-scroll.ts b/packages/playground-v2/src/editor-touch-scroll.ts index 348f1a276588..efd84be5e7fc 100644 --- a/packages/playground-v2/src/editor-touch-scroll.ts +++ b/packages/playground-v2/src/editor-touch-scroll.ts @@ -1,5 +1,5 @@ import type * as monaco from "monaco-editor-core" -import { EventType } from "monaco-editor-core/esm/vs/base/browser/touch.js" +import { EventType } from "monaco-editor/base/browser/touch.js" export function configureEditorTouchScroll(editor: monaco.editor.IStandaloneCodeEditor, mobileLayout: MediaQueryList) { const element = editor.getDomNode() diff --git a/packages/playground-v2/src/global.d.ts b/packages/playground-v2/src/global.d.ts index e4fb1ae047a1..2619df4ad542 100644 --- a/packages/playground-v2/src/global.d.ts +++ b/packages/playground-v2/src/global.d.ts @@ -3,9 +3,8 @@ declare module "*.json" { const value: any export default value } -declare module "monaco-editor/editor/contrib/links/browser/links.js" -declare module "monaco-editor-core/esm/vs/base/browser/touch.js" { +declare module "monaco-editor/base/browser/touch.js" { export const EventType: { Change: string; Tap: string } } diff --git a/packages/playground-v2/src/main.ts b/packages/playground-v2/src/main.ts index f7b31df12421..2069c85371a4 100644 --- a/packages/playground-v2/src/main.ts +++ b/packages/playground-v2/src/main.ts @@ -15,7 +15,6 @@ import { loadLegacyCompilerVersions, publishedNativeCompilerSelection, } from "./compiler-versions" -import "monaco-editor/editor/contrib/links/browser/links.js" import LZString from "lz-string" import "reflect-metadata" import { diff --git a/packages/playground-v2/tsconfig.json b/packages/playground-v2/tsconfig.json index 0c00ec6d4998..61f1cbbf44ec 100644 --- a/packages/playground-v2/tsconfig.json +++ b/packages/playground-v2/tsconfig.json @@ -6,7 +6,10 @@ "lib": ["DOM", "ES2022"], "strict": true, "noEmit": true, - "skipLibCheck": true + "skipLibCheck": true, + "paths": { + "monaco-editor-core": ["./node_modules/monaco-editor/esm/vs/editor/editor.api.d.ts"] + } }, "include": ["src"], "exclude": ["src/**/*.test.ts"] diff --git a/patches/monaco-editor-core@0.56.0.patch b/patches/monaco-editor-core@0.56.0.patch deleted file mode 100644 index 9f8594ef4741..000000000000 --- a/patches/monaco-editor-core@0.56.0.patch +++ /dev/null @@ -1,92 +0,0 @@ -diff --git a/esm/vs/base/browser/domSanitize.js b/esm/vs/base/browser/domSanitize.js ---- a/esm/vs/base/browser/domSanitize.js -+++ b/esm/vs/base/browser/domSanitize.js -@@ -5,7 +5,7 @@ - import { Schemas } from '../common/network.js'; - import { reset } from './dom.js'; - // eslint-disable-next-line no-restricted-imports --import dompurify from './dompurify/dompurify.js'; -+import dompurify from 'dompurify'; - /** - * List of safe, non-input html tags. - */ -diff --git a/esm/vs/base/browser/touch.js b/esm/vs/base/browser/touch.js ---- a/esm/vs/base/browser/touch.js -+++ b/esm/vs/base/browser/touch.js -@@ -43,7 +43,4 @@ export class Gesture extends Disposable { - static addTarget(element) { -- if (!Gesture.isTouchDevice()) { -- return Disposable.None; -- } - if (!Gesture.INSTANCE) { - Gesture.INSTANCE = markAsSingleton(new Gesture()); - } -@@ -53,7 +50,4 @@ export class Gesture extends Disposable { - static ignoreTarget(element) { -- if (!Gesture.isTouchDevice()) { -- return Disposable.None; -- } - if (!Gesture.INSTANCE) { - Gesture.INSTANCE = markAsSingleton(new Gesture()); - } -@@ -90,11 +84,12 @@ export class Gesture extends Disposable { - id: touch.identifier, - initialTarget: touch.target, - initialTimeStamp: timestamp, -+ // Store viewport coordinates so page scrolling does not alter gestures. -- initialPageX: touch.pageX, -- initialPageY: touch.pageY, -+ initialPageX: touch.clientX, -+ initialPageY: touch.clientY, - rollingTimestamps: [timestamp], -- rollingPageX: [touch.pageX], -- rollingPageY: [touch.pageY] -+ rollingPageX: [touch.clientX], -+ rollingPageY: [touch.clientY] - }; - const evt = this.newGestureEvent(EventType.Start, touch.target); - evt.pageX = touch.pageX; -@@ -120,8 +115,8 @@ export class Gesture extends Disposable { - && Math.abs(data.initialPageX - data.rollingPageX.at(-1)) < 30 - && Math.abs(data.initialPageY - data.rollingPageY.at(-1)) < 30) { - const evt = this.newGestureEvent(EventType.Tap, data.initialTarget); -- evt.pageX = data.rollingPageX.at(-1); -- evt.pageY = data.rollingPageY.at(-1); -+ evt.pageX = data.rollingPageX.at(-1) + targetWindow.scrollX; -+ evt.pageY = data.rollingPageY.at(-1) + targetWindow.scrollY; - this.dispatchEvent(evt); - } - else if (holdTime >= Gesture.HOLD_DELAY -@@ -129,8 +124,8 @@ export class Gesture extends Disposable { - && Math.abs(data.initialPageX - data.rollingPageX.at(-1)) < 30 - && Math.abs(data.initialPageY - data.rollingPageY.at(-1)) < 30) { - const evt = this.newGestureEvent(EventType.Contextmenu, data.initialTarget); -- evt.pageX = data.rollingPageX.at(-1); -- evt.pageY = data.rollingPageY.at(-1); -+ evt.pageX = data.rollingPageX.at(-1) + targetWindow.scrollX; -+ evt.pageY = data.rollingPageY.at(-1) + targetWindow.scrollY; - this.dispatchEvent(evt); - } - else if (activeTouchCount === 1) { -@@ -243,8 +238,8 @@ export class Gesture extends Disposable { - } - const data = this.activeTouches[touch.identifier]; - const evt = this.newGestureEvent(EventType.Change, data.initialTarget); -- evt.translationX = touch.pageX - data.rollingPageX.at(-1); -- evt.translationY = touch.pageY - data.rollingPageY.at(-1); -+ evt.translationX = touch.clientX - data.rollingPageX.at(-1); -+ evt.translationY = touch.clientY - data.rollingPageY.at(-1); - evt.pageX = touch.pageX; - evt.pageY = touch.pageY; - this.dispatchEvent(evt); -@@ -256,8 +251,8 @@ export class Gesture extends Disposable { - data.rollingPageY.shift(); - data.rollingTimestamps.shift(); - } -- data.rollingPageX.push(touch.pageX); -- data.rollingPageY.push(touch.pageY); -+ data.rollingPageX.push(touch.clientX); -+ data.rollingPageY.push(touch.clientY); - data.rollingTimestamps.push(timestamp); - } - if (this.dispatched) { diff --git a/patches/monaco-editor@0.56.0.patch b/patches/monaco-editor@0.56.0.patch index 6ff5629732e5..23acb176f187 100644 --- a/patches/monaco-editor@0.56.0.patch +++ b/patches/monaco-editor@0.56.0.patch @@ -1,4 +1,5 @@ diff --git a/esm/vs/base/browser/domSanitize.js b/esm/vs/base/browser/domSanitize.js +index 95061a20c8ecd48ff3ca732dbb1848cd213f7965..4bbb061da3fc2115cfc1917759b1660959dd308f 100644 --- a/esm/vs/base/browser/domSanitize.js +++ b/esm/vs/base/browser/domSanitize.js @@ -1,6 +1,6 @@ @@ -9,3 +10,87 @@ diff --git a/esm/vs/base/browser/domSanitize.js b/esm/vs/base/browser/domSanitiz /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. +diff --git a/esm/vs/base/browser/touch.js b/esm/vs/base/browser/touch.js +index 0bc8accfabad3c860ee2a705418b42254ab9a03b..15fbb29e5e441ca257e3e5aef389a8b8742d1ca3 100644 +--- a/esm/vs/base/browser/touch.js ++++ b/esm/vs/base/browser/touch.js +@@ -42,9 +42,6 @@ class Gesture extends Disposable { + }, { window: mainWindow, disposables: this._store })); + } + static addTarget(element) { +- if (!Gesture.isTouchDevice()) { +- return Disposable.None; +- } + if (!Gesture.INSTANCE) { + Gesture.INSTANCE = markAsSingleton(new Gesture()); + } +@@ -52,9 +49,6 @@ class Gesture extends Disposable { + return toDisposable(remove); + } + static ignoreTarget(element) { +- if (!Gesture.isTouchDevice()) { +- return Disposable.None; +- } + if (!Gesture.INSTANCE) { + Gesture.INSTANCE = markAsSingleton(new Gesture()); + } +@@ -88,11 +82,12 @@ class Gesture extends Disposable { + id: touch.identifier, + initialTarget: touch.target, + initialTimeStamp: timestamp, +- initialPageX: touch.pageX, +- initialPageY: touch.pageY, ++ // Store viewport coordinates so page scrolling does not alter gestures. ++ initialPageX: touch.clientX, ++ initialPageY: touch.clientY, + rollingTimestamps: [timestamp], +- rollingPageX: [touch.pageX], +- rollingPageY: [touch.pageY] ++ rollingPageX: [touch.clientX], ++ rollingPageY: [touch.clientY] + }; + const evt = this.newGestureEvent(EventType.Start, touch.target); + evt.pageX = touch.pageX; +@@ -119,16 +114,16 @@ class Gesture extends Disposable { + && Math.abs(data.initialPageX - data.rollingPageX.at(-1)) < 30 + && Math.abs(data.initialPageY - data.rollingPageY.at(-1)) < 30) { + const evt = this.newGestureEvent(EventType.Tap, data.initialTarget); +- evt.pageX = data.rollingPageX.at(-1); +- evt.pageY = data.rollingPageY.at(-1); ++ evt.pageX = data.rollingPageX.at(-1) + targetWindow.scrollX; ++ evt.pageY = data.rollingPageY.at(-1) + targetWindow.scrollY; + this.dispatchEvent(evt); + } + else if (holdTime >= Gesture.HOLD_DELAY + && Math.abs(data.initialPageX - data.rollingPageX.at(-1)) < 30 + && Math.abs(data.initialPageY - data.rollingPageY.at(-1)) < 30) { + const evt = this.newGestureEvent(EventType.Contextmenu, data.initialTarget); +- evt.pageX = data.rollingPageX.at(-1); +- evt.pageY = data.rollingPageY.at(-1); ++ evt.pageX = data.rollingPageX.at(-1) + targetWindow.scrollX; ++ evt.pageY = data.rollingPageY.at(-1) + targetWindow.scrollY; + this.dispatchEvent(evt); + } + else if (activeTouchCount === 1) { +@@ -244,8 +239,8 @@ class Gesture extends Disposable { + } + const data = this.activeTouches[touch.identifier]; + const evt = this.newGestureEvent(EventType.Change, data.initialTarget); +- evt.translationX = touch.pageX - data.rollingPageX.at(-1); +- evt.translationY = touch.pageY - data.rollingPageY.at(-1); ++ evt.translationX = touch.clientX - data.rollingPageX.at(-1); ++ evt.translationY = touch.clientY - data.rollingPageY.at(-1); + evt.pageX = touch.pageX; + evt.pageY = touch.pageY; + this.dispatchEvent(evt); +@@ -255,8 +250,8 @@ class Gesture extends Disposable { + data.rollingPageY.shift(); + data.rollingTimestamps.shift(); + } +- data.rollingPageX.push(touch.pageX); +- data.rollingPageY.push(touch.pageY); ++ data.rollingPageX.push(touch.clientX); ++ data.rollingPageY.push(touch.clientY); + data.rollingTimestamps.push(timestamp); + } + if (this.dispatched) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2aef418f2d3..2b851d2f56db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,6 +60,7 @@ overrides: dts-cli>eslint-plugin-testing-library: '-' react-dev-utils>fork-ts-checker-webpack-plugin: '-' keyv@<5.5.3: ^5.5.3 + '@vscode/monaco-lsp-client>monaco-editor-core': '-' patchedDependencies: '@vscode/monaco-lsp-client@0.1.0': @@ -83,11 +84,8 @@ patchedDependencies: gatsby@5.16.1: hash: 0a1b922877d3f20541adc51a5f7c375c192f16e6a2cb63f386ab9e8b29ea6195 path: patches/gatsby@5.16.1.patch - monaco-editor-core@0.56.0: - hash: 7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7 - path: patches/monaco-editor-core@0.56.0.patch monaco-editor@0.56.0: - hash: f2016b76fa8202ad749085be423d52abc12840f715b652ae50903f7e26a30b6b + hash: dc5217366a1b239838919f71f26d3a70c8277bdd3a8185b919fef095530b67f4 path: patches/monaco-editor@0.56.0.patch node-stdlib-browser@1.3.1: hash: 4dc49bf21eaa694d5c9ca2d7c9e2fcbcde409753893a1e1c5b0777867e6af3ed @@ -265,7 +263,7 @@ importers: version: 5.3.0 '@vscode/monaco-lsp-client': specifier: github:microsoft/monaco-editor#13f0c872dcf352815cc28d92dfff496c9839ea5c&path:/monaco-lsp-client - version: https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c#path:/monaco-lsp-client(patch_hash=2adc8bf0b3596826d330832fc1ca5385179508eab8541c404f94c460b01115a0)(monaco-editor-core@0.56.0(patch_hash=7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7))(ws@8.23.0) + version: https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c#path:/monaco-lsp-client(patch_hash=2adc8bf0b3596826d330832fc1ca5385179508eab8541c404f94c460b01115a0)(ws@8.23.0) coi-serviceworker: specifier: ^0.1.7 version: 0.1.7(patch_hash=714b4adc6ff6ecd02825ea3646eae7d2f84ef6ea33d2023e8e03d1d236243e2f) @@ -280,10 +278,7 @@ importers: version: 1.5.0 monaco-editor: specifier: 0.56.0 - version: 0.56.0(patch_hash=f2016b76fa8202ad749085be423d52abc12840f715b652ae50903f7e26a30b6b) - monaco-editor-core: - specifier: 0.56.0 - version: 0.56.0(patch_hash=7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7) + version: 0.56.0(patch_hash=dc5217366a1b239838919f71f26d3a70c8277bdd3a8185b919fef095530b67f4) reflect-metadata: specifier: ^0.2.2 version: 0.2.2 @@ -3188,8 +3183,6 @@ packages: '@vscode/monaco-lsp-client@https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c#path:/monaco-lsp-client': resolution: {path: /monaco-lsp-client, tarball: https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c} version: 0.1.0 - peerDependencies: - monaco-editor-core: '*' '@webassemblyjs/ast@1.14.1': resolution: {integrity: sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ==} @@ -6634,9 +6627,6 @@ packages: moment@2.31.0: resolution: {integrity: sha512-0acOTfMiWOheYS4eoWb80yYMb/JLvVv9SHbs2PehaDzfUG0Bw855SKyk0IKTnPGa5+U2bmi3W68l1+sGLX/pvw==} - monaco-editor-core@0.56.0: - resolution: {integrity: sha512-zuY3UTjedTxWnEUDs84Us/6tvYH9mG89fkHMpzXuvrqTdyWgybn536GR/TG6XNyG5N5heYICRMxT1ox5hZ7rxQ==} - monaco-editor@0.32.1: resolution: {integrity: sha512-LUt2wsUvQmEi2tfTOK+tjAPvt7eQ+K5C4rZPr6SeuyzjAuAHrIvlUloTcOiGjZW3fn3a/jFQCONrEJbNOaCqbA==} @@ -12040,12 +12030,11 @@ snapshots: '@vscode/l10n@0.0.18': {} - '@vscode/monaco-lsp-client@https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c#path:/monaco-lsp-client(patch_hash=2adc8bf0b3596826d330832fc1ca5385179508eab8541c404f94c460b01115a0)(monaco-editor-core@0.56.0(patch_hash=7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7))(ws@8.23.0)': + '@vscode/monaco-lsp-client@https://codeload.github.com/microsoft/monaco-editor/tar.gz/13f0c872dcf352815cc28d92dfff496c9839ea5c#path:/monaco-lsp-client(patch_hash=2adc8bf0b3596826d330832fc1ca5385179508eab8541c404f94c460b01115a0)(ws@8.23.0)': dependencies: '@hediet/json-rpc': 0.5.0 '@hediet/json-rpc-browser': 0.5.1 '@hediet/json-rpc-websocket': 0.5.1(ws@8.23.0) - monaco-editor-core: 0.56.0(patch_hash=7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7) transitivePeerDependencies: - ws @@ -16787,14 +16776,9 @@ snapshots: moment@2.31.0: {} - monaco-editor-core@0.56.0(patch_hash=7aaaaeeffb89ac7ceead19dc1485eebbe3b2a22f83d507194096fbff9b2549f7): - dependencies: - dompurify: 3.4.17 - marked: 14.0.0 - monaco-editor@0.32.1: {} - monaco-editor@0.56.0(patch_hash=f2016b76fa8202ad749085be423d52abc12840f715b652ae50903f7e26a30b6b): + monaco-editor@0.56.0(patch_hash=dc5217366a1b239838919f71f26d3a70c8277bdd3a8185b919fef095530b67f4): dependencies: dompurify: 3.4.17 marked: 14.0.0