From e0178ef6e3d615c183e4c76cb866cdd2b42d97f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 5 Apr 2023 17:40:37 +0200 Subject: [PATCH 1/7] fix: typo --- rollup/rollup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup/rollup.config.ts b/rollup/rollup.config.ts index e0cf1f73..15de9886 100644 --- a/rollup/rollup.config.ts +++ b/rollup/rollup.config.ts @@ -36,7 +36,7 @@ const PURE_FUNCTIONS = new Set([ 'darken', 'lighten', 'Color.fromHex', - 'asBroswerUri', + 'asBrowserUri', 'values', 'keys', 'toString', From e7a9c1d09750991916d49f4a143517871039e07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 5 Apr 2023 17:41:27 +0200 Subject: [PATCH 2/7] lib: install rollup-plugin-glob-import --- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + rollup/rollup.config.ts | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/package-lock.json b/package-lock.json index 7d98163b..11a95fcd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "rollup": "^3.20.2", "rollup-plugin-dts": "^5.3.0", "rollup-plugin-external-assets": "^3.0.1", + "rollup-plugin-glob-import": "^0.5.0", "rollup-plugin-styles": "^4.0.0", "semver": "^7.3.8", "ts-node": "^10.9.1", @@ -6427,6 +6428,19 @@ "node": ">= 4" } }, + "node_modules/rollup-plugin-glob-import": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-glob-import/-/rollup-plugin-glob-import-0.5.0.tgz", + "integrity": "sha512-GpinkWAEihianHz1yGpGT89tjEf6HUqRBsMycd1E8M0r6UVNM4pWctHyTnIGpSYSzLra9amDpYVYlYUAqkMRbA==", + "dev": true, + "dependencies": { + "fast-glob": "^3.2.5", + "rollup-pluginutils": "^2.8.2" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/rollup-plugin-styles": { "version": "4.0.0", "dev": true, @@ -6470,6 +6484,21 @@ "node": ">= 8.0.0" } }, + "node_modules/rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "dependencies": { + "estree-walker": "^0.6.1" + } + }, + "node_modules/rollup-pluginutils/node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "node_modules/run-parallel": { "version": "1.2.0", "dev": true, diff --git a/package.json b/package.json index a71f86f5..4a3eb683 100644 --- a/package.json +++ b/package.json @@ -195,6 +195,7 @@ "rollup": "^3.20.2", "rollup-plugin-dts": "^5.3.0", "rollup-plugin-external-assets": "^3.0.1", + "rollup-plugin-glob-import": "^0.5.0", "rollup-plugin-styles": "^4.0.0", "semver": "^7.3.8", "ts-node": "^10.9.1", diff --git a/rollup/rollup.config.ts b/rollup/rollup.config.ts index 15de9886..87b3a46a 100644 --- a/rollup/rollup.config.ts +++ b/rollup/rollup.config.ts @@ -13,6 +13,7 @@ import * as babylonParser from 'recast/parsers/babylon.js' import dynamicImportVars from '@rollup/plugin-dynamic-import-vars' import inject from '@rollup/plugin-inject' import externalAssets from 'rollup-plugin-external-assets' +import globImport from 'rollup-plugin-glob-import' import * as fs from 'fs' import * as path from 'path' import * as vm from 'vm' @@ -391,6 +392,12 @@ export default (args: Record): rollup.RollupOptions[] => { inject({ require: path.resolve('src/custom-require.js') }), + globImport({ + format: 'default', + rename (name, id) { + return path.relative(VSCODE_DIR, id).replace(/[/.]/g, '_') + } + }), { name: 'vscode-resource-loading-plugin', resolveId (id) { From 2617608cefa458bb342ecffcef0c39cb237a8eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 5 Apr 2023 17:50:21 +0200 Subject: [PATCH 3/7] fix: improve the way assets are handled Do not import assets that are not used --- rollup/rollup.config.ts | 31 +------------------------------ src/assets.ts | 18 ++++++++++++++++++ src/service-override/audioCue.ts | 4 ++++ src/service-override/textmate.ts | 5 +++++ src/types.d.ts | 5 +++++ 5 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 src/assets.ts diff --git a/rollup/rollup.config.ts b/rollup/rollup.config.ts index 87b3a46a..6ebc29f3 100644 --- a/rollup/rollup.config.ts +++ b/rollup/rollup.config.ts @@ -390,7 +390,7 @@ export default (args: Record): rollup.RollupOptions[] => { }), // Create a require instance with a toUrl method (like in vscode) to load static resources (mp3, wasm...) inject({ - require: path.resolve('src/custom-require.js') + require: path.resolve('src/assets') }), globImport({ format: 'default', @@ -398,35 +398,6 @@ export default (args: Record): rollup.RollupOptions[] => { return path.relative(VSCODE_DIR, id).replace(/[/.]/g, '_') } }), - { - name: 'vscode-resource-loading-plugin', - resolveId (id) { - if (id.endsWith('custom-require.js')) { - return id - } - return undefined - }, - load (id) { - if (!id.endsWith('custom-require.js')) { - return - } - const sounds = fs.readdirSync(path.resolve(VSCODE_DIR, 'vs/platform/audioCues/browser/media/')) - const code = ` -${sounds.map(sound => `import _${path.parse(sound).name} from 'vscode/vs/platform/audioCues/browser/media/${sound}'`).join('\n')} -import _onigWasm from 'vscode-oniguruma/release/onig.wasm' - -const fileUrls = { - 'vscode-oniguruma/../onig.wasm': _onigWasm, -${sounds.map(sound => ` 'vs/platform/audioCues/browser/media/${sound}': _${path.parse(sound).name}`).join(',\n')} -} - -export default { - toUrl: (id) => fileUrls[id] -} -` - return code - } - }, externalAssets(['**/*.mp3', '**/*.wasm']), { name: 'dynamic-import-polyfill', diff --git a/src/assets.ts b/src/assets.ts new file mode 100644 index 00000000..c430dabd --- /dev/null +++ b/src/assets.ts @@ -0,0 +1,18 @@ + +let assetUrls: Record = {} +export function registerAssets (assets: Record): void { + assetUrls = { + ...assetUrls, + ...assets + } +} + +function toUrl (name: string): string | undefined { + return assetUrls[name] ?? assetUrls[name.replace(/[/.]/g, '_')] +} + +const customRequire = { + toUrl +} + +export default customRequire diff --git a/src/service-override/audioCue.ts b/src/service-override/audioCue.ts index da008450..0678bc5c 100644 --- a/src/service-override/audioCue.ts +++ b/src/service-override/audioCue.ts @@ -8,7 +8,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { AudioCueLineFeatureContribution } from 'vs/workbench/contrib/audioCues/browser/audioCueLineFeatureContribution' import { AudioCueLineDebuggerContribution } from 'vs/workbench/contrib/audioCues/browser/audioCueDebuggerContribution' import { onServicesInitialized } from './tools' +// @ts-ignore +import * as audioAssets from '../../vscode/vs/platform/audioCues/browser/media/*.mp3' +import { registerAssets } from '../assets' import 'vs/workbench/contrib/audioCues/browser/audioCues.contribution' +registerAssets(audioAssets) function initialize (instantiationService: IInstantiationService) { setTimeout(() => { diff --git a/src/service-override/textmate.ts b/src/service-override/textmate.ts index 217cf072..78b064fe 100644 --- a/src/service-override/textmate.ts +++ b/src/service-override/textmate.ts @@ -5,8 +5,13 @@ import { ITextMateTokenizationService } from 'vs/workbench/services/textMate/bro import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors' import { TextMateTokenizationFeature } from 'vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl' +import _onigWasm from 'vscode-oniguruma/release/onig.wasm' import getFileServiceOverride from './files' import { onServicesInitialized } from './tools' +import { registerAssets } from '../assets' +registerAssets({ + 'vscode-oniguruma/../onig.wasm': _onigWasm +}) function initialize (instantiationService: IInstantiationService) { // Force load the service diff --git a/src/types.d.ts b/src/types.d.ts index 5191a24c..989e26f4 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1 +1,6 @@ declare const VSCODE_VERSION: string + +declare module '*.wasm' { + const url: string + export default url +} From c2b56ce984e474f55ecd122d770d6c5dcad8d30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 6 Apr 2023 09:33:47 +0200 Subject: [PATCH 4/7] fix: do not hash asset names --- rollup/rollup.config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rollup/rollup.config.ts b/rollup/rollup.config.ts index 6ebc29f3..efe6fb88 100644 --- a/rollup/rollup.config.ts +++ b/rollup/rollup.config.ts @@ -202,6 +202,7 @@ export default (args: Record): rollup.RollupOptions[] => { }, external, output: [{ + assetFileNames: 'assets/[name][extname]', format: 'esm', dir: 'dist', entryFileNames: '[name].js', @@ -425,6 +426,7 @@ export default (args: Record): rollup.RollupOptions[] => { external, input: Object.values(input).map(f => `./dist/${path.basename(f, '.ts')}`), output: [{ + assetFileNames: 'assets/[name][extname]', format: 'esm', dir: 'dist', entryFileNames: '[name].js', From d4bfc964c4d4de707e039146fbfe43a6d3d5b7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 6 Apr 2023 09:57:28 +0200 Subject: [PATCH 5/7] fix: disable wrong eslint warnings --- src/polyfill.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/polyfill.ts b/src/polyfill.ts index 77b9301a..084c23a0 100644 --- a/src/polyfill.ts +++ b/src/polyfill.ts @@ -231,6 +231,7 @@ Object.defineProperty(MonacoDefaultConfiguration.prototype, 'onDidChangeConfigur MonacoPieceTreeTextBufferBuilder.prototype.finish = VScodePieceTreeTextBufferBuilder.prototype.finish const jsonContributionRegistry = Registry.as(JsonExtensions.JSONContribution) +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition jsonContributionRegistry.getSchemaContributions ??= () => ({ // eslint-disable-next-line @typescript-eslint/no-explicit-any schemas: (jsonContributionRegistry as any).schemasById @@ -252,6 +253,7 @@ configurationRegistry.onDidUpdateConfiguration ??= (configurationRegistry as any // eslint-disable-next-line @typescript-eslint/no-explicit-any configurationRegistry.onDidSchemaChange ??= (configurationRegistry as any)._onDidSchemaChange.event +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition configurationRegistry.notifyConfigurationSchemaUpdated ??= () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any (configurationRegistry as any)._onDidSchemaChange.fire() @@ -343,6 +345,7 @@ Object.defineProperty(AudioCue, 'allAudioCues', { onServicesInitialized(() => { // polyfill for StandaloneWorkspaceContextService const workspaceContextService = StandaloneServices.get(IWorkspaceContextService) + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition workspaceContextService.getCompleteWorkspace ??= function (this: IWorkspaceContextService) { return Promise.resolve(this.getWorkspace()) }.bind(workspaceContextService) @@ -351,5 +354,6 @@ onServicesInitialized(() => { workspaceContextService.onDidChangeWorkspaceFolders ??= Event.None // @ts-ignore workspaceContextService.onDidChangeWorkbenchState ??= Event.None + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition workspaceContextService.getWorkbenchState ??= () => WorkbenchState.EMPTY }) From 15a3fbcc876ed48c4d36a42186cadfdf8ef426b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 6 Apr 2023 10:51:53 +0200 Subject: [PATCH 6/7] cleanup: remove unused polyfill --- src/polyfill.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/polyfill.ts b/src/polyfill.ts index 084c23a0..3a6e36af 100644 --- a/src/polyfill.ts +++ b/src/polyfill.ts @@ -116,14 +116,6 @@ import { onServicesInitialized } from './service-override/tools' // Unfortunately, it makes some class not respect anymore the interface they are supposed to implement // In this file we are restoring some method that are treeshaked out of monaco-editor but that are needed in this library -if (SnippetParser.prototype.text == null) { - SnippetParser.prototype.text = function (value: string) { - return this.parse(value).toString() - } -} else { - console.warn('Useless polyfill: SnippetParser') -} - /** * Assign all properties of b to A */ From c3b40887e9ae39d602286385e930b2e469cad7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 6 Apr 2023 10:57:27 +0200 Subject: [PATCH 7/7] fix: prevent disabling ts/eslint as much as possible --- src/polyfill.ts | 74 +++++++++++---------------------------------- tsconfig.json | 3 ++ tsconfig.types.json | 3 ++ 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/src/polyfill.ts b/src/polyfill.ts index 3a6e36af..e345c202 100644 --- a/src/polyfill.ts +++ b/src/polyfill.ts @@ -1,117 +1,87 @@ +/* eslint-disable dot-notation */ import { QuickInputController } from 'vs/platform/quickinput/browser/quickInput' -// @ts-ignore Creating a d.ts is not worth it import { VSBuffer as MonacoVSBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js' import { VSBuffer as VScodeVSBuffer } from 'vscode/vs/base/common/buffer.js' -// @ts-ignore Creating a d.ts is not worth it import { Themable as MonacoThemable } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js' import { Extensions as ThemeExtensions, IThemingRegistry, Themable as VScodeThemable } from 'vscode/vs/platform/theme/common/themeService.js' import { Extensions as JsonExtensions, IJSONContributionRegistry } from 'vscode/vs/platform/jsonschemas/common/jsonContributionRegistry.js' -// @ts-ignore Creating a d.ts is not worth it import { ProgressBar as MonacoProgressBar } from 'monaco-editor/esm/vs/base/browser/ui/progressbar/progressbar.js' import { ProgressBar as VScodeProgressBar } from 'vscode/vs/base/browser/ui/progressbar/progressbar.js' import { getSingletonServiceDescriptors } from 'vs/platform/instantiation/common/extensions' import { ILabelService } from 'vs/platform/label/common/label' import { Emitter, Event } from 'vs/base/common/event' import { IQuickInput, IQuickPick } from 'vs/platform/quickinput/common/quickInput' -// @ts-ignore Creating a d.ts is not worth it import { LanguageService as MonacoLanguageService } from 'monaco-editor/esm/vs/editor/common/services/languageService.js' import { LanguageService as VScodeLanguageService } from 'vscode/vs/editor/common/services/languageService.js' -// @ts-ignore Creating a d.ts is not worth it import { NoOpNotification as MonacoNoOpNotification } from 'monaco-editor/esm/vs/platform/notification/common/notification.js' import { NoOpNotification as VScodeNoOpNotification } from 'vscode/vs/platform/notification/common/notification.js' import { Registry } from 'vs/platform/registry/common/platform' import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry' import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices' -// @ts-ignore Creating a d.ts is not worth it import { StandaloneConfigurationService as MonacoStandaloneConfigurationService } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js' import { StandaloneConfigurationService as VScodeStandaloneConfigurationService } from 'vscode/vs/editor/standalone/browser/standaloneServices.js' -// @ts-ignore Creating a d.ts is not worth it import { TernarySearchTree as MonacoTernarySearchTree } from 'monaco-editor/esm/vs/base/common/ternarySearchTree.js' import { TernarySearchTree as VScodeTernarySearchTree } from 'vscode/vs/base/common/ternarySearchTree.js' -// @ts-ignore Creating a d.ts is not worth it import { Configuration as MonacoConfiguration } from 'monaco-editor/esm/vs/platform/configuration/common/configurationModels.js' import { Configuration as VScodeConfiguration } from 'vscode/vs/platform/configuration/common/configurationModels.js' -// @ts-ignore Creating a d.ts is not worth it import { RawContextKey as MonacoRawContextKey, ContextKeyExpr as MonacoContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js' import { RawContextKey as VScodeRawContextKey, ContextKeyExpr as VScodeContextKeyExpr } from 'vscode/vs/platform/contextkey/common/contextkey.js' -// @ts-ignore Creating a d.ts is not worth it import { ErrorHandler as MonacoErrorHandler } from 'monaco-editor/esm/vs/base/common/errors.js' import { ErrorHandler as VScodeErrorHandler } from 'vscode/vs/base/common/errors.js' -// @ts-ignore Creating a d.ts is not worth it import { LanguagesRegistry as MonacoLanguagesRegistry } from 'monaco-editor/esm/vs/editor/common/services/languagesRegistry.js' import { LanguagesRegistry as VScodeLanguagesRegistry } from 'vscode/vs/editor/common/services/languagesRegistry.js' -// @ts-ignore Creating a d.ts is not worth it import { WorkspaceFolder as MonacoWorkspaceFolder } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js' import { IWorkspaceContextService, WorkbenchState, WorkspaceFolder as VScodeWorkspaceFolder } from 'vscode/vs/platform/workspace/common/workspace.js' -// @ts-ignore Creating a d.ts is not worth it import { List as MonacoList } from 'monaco-editor/esm/vs/base/browser/ui/list/listWidget.js' import { List as VScodeList } from 'vscode/vs/base/browser/ui/list/listWidget.js' -// @ts-ignore Creating a d.ts is not worth it import { Color as MonacoColor, RGBA as MonacoRGBA } from 'monaco-editor/esm/vs/base/common/color.js' import { Color as VScodeColor, RGBA as VScodeRGBA } from 'vscode/vs/base/common/color.js' -// @ts-ignore Creating a d.ts is not worth it import { LogService as MonacoLogService } from 'monaco-editor/esm/vs/platform/log/common/logService.js' import { LogService as VScodeLogService } from 'vscode/vs/platform/log/common/logService.js' -// @ts-ignore Creating a d.ts is not worth it -import { SnippetParser } from 'monaco-editor/esm/vs/editor/contrib/snippet/browser/snippetParser.js' -// @ts-ignore Creating a d.ts is not worth it import { DefaultConfiguration as MonacoDefaultConfiguration } from 'monaco-editor/esm/vs/platform/configuration/common/configurations.js' import { DefaultConfiguration as VScodeDefaultConfiguration } from 'vscode/vs/platform/configuration/common/configurations.js' -// @ts-ignore Creating a d.ts is not worth it import { Keybinding as MonacoKeybinding, KeyCodeChord as MonacoKeyCodeChord } from 'monaco-editor/esm/vs/base/common/keybindings.js' import { Keybinding as VScodeKeybinding, KeyCodeChord as VScodeKeyCodeChord } from 'vscode/vs/base/common/keybindings.js' -// @ts-ignore Creating a d.ts is not worth it import { DisposableMap as MonacoDisposableMap } from 'monaco-editor/esm/vs/base/common/lifecycle.js' import { DisposableMap as VScodeDisposableMap } from 'vscode/vs/base/common/lifecycle.js' -// @ts-ignore Creating a d.ts is not worth it import { FileAccess as MonacoFileAccess } from 'monaco-editor/esm/vs/base/common/network.js' import { FileAccess as VScodeFileAccess } from 'vscode/vs/base/common/network.js' import { GhostTextController } from 'vs/editor/contrib/inlineCompletions/browser/ghostTextController' -// @ts-ignore Creating a d.ts is not worth it import { AsyncDataTree as MonacoAsyncDataTree } from 'monaco-editor/esm/vs/base/browser/ui/tree/asyncDataTree.js' import { AsyncDataTree as VScodeAsyncDataTree } from 'vscode/vs/base/browser/ui/tree/asyncDataTree.js' -// @ts-ignore Creating a d.ts is not worth it import { AbstractTree as MonacoAbstractTree } from 'monaco-editor/esm/vs/base/browser/ui/tree/abstractTree.js' import { AbstractTree as VScodeAbstractTree } from 'vscode/vs/base/browser/ui/tree/abstractTree.js' -// @ts-ignore Creating a d.ts is not worth it import { AbstractCodeEditorService as MonacoAbstractCodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/abstractCodeEditorService.js' import { AbstractCodeEditorService as VScodeAbstractCodeEditorService } from 'vscode/vs/editor/browser/services/abstractCodeEditorService.js' -// @ts-ignore Creating a d.ts is not worth it import { CodeEditorWidget as MonacoCodeEditorWidget } from 'monaco-editor/esm/vs/editor/browser/widget/codeEditorWidget.js' import { CodeEditorWidget as VScodeCodeEditorWidget } from 'vscode/vs/editor/browser/widget/codeEditorWidget.js' -// @ts-ignore Creating a d.ts is not worth it import { PieceTreeTextBufferBuilder as MonacoPieceTreeTextBufferBuilder } from 'monaco-editor/esm/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder.js' import { PieceTreeTextBufferBuilder as VScodePieceTreeTextBufferBuilder } from 'vscode/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder.js' -// @ts-ignore Creating a d.ts is not worth it import { PieceTreeTextBuffer as MonacoPieceTreeTextBuffer } from 'monaco-editor/esm/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.js' import { PieceTreeTextBuffer as VScodePieceTreeTextBuffer } from 'vscode/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.js' -// @ts-ignore Creating a d.ts is not worth it import { ModelService as MonacoModelService } from 'monaco-editor/esm/vs/editor/common/services/modelService.js' import { ModelService as VScodeModelService } from 'vscode/vs/editor/common/services/modelService.js' -// @ts-ignore Creating a d.ts is not worth it import { AbstractContextKeyService as MonacoAbstractContextKeyService } from 'monaco-editor/esm/vs/platform/contextkey/browser/contextKeyService.js' import { AbstractContextKeyService as VScodeAbstractContextKeyService } from 'vscode/vs/platform/contextkey/browser/contextKeyService.js' -// @ts-ignore Creating a d.ts is not worth it import { ListView as MonacoListView } from 'monaco-editor/esm/vs/base/browser/ui/list/listView.js' import { ListView as VScodeListView } from 'vscode/vs/base/browser/ui/list/listView.js' -// @ts-ignore Creating a d.ts is not worth it import { CallbackIterable as MonacoCallbackIterable } from 'monaco-editor/esm/vs/base/common/arrays.js' import { CallbackIterable as VScodeCallbackIterable } from 'vscode/vs/base/common/arrays.js' -// @ts-ignore Creating a d.ts is not worth it import { SelectActionViewItem as MonacoSelectActionViewItem } from 'monaco-editor/esm/vs/base/browser/ui/actionbar/actionViewItems.js' import { SelectActionViewItem as VScodeSelectActionViewItem } from 'vscode/vs/base/browser/ui/actionbar/actionViewItems.js' -// @ts-ignore Creating a d.ts is not worth it import { QuickInputService as MonacoQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/browser/quickInputService.js' import { QuickInputService as VScodeQuickInputService } from 'vscode/vs/platform/quickinput/browser/quickInputService.js' -// @ts-ignore Creating a d.ts is not worth it import { TextModel as MonacoTextModel } from 'monaco-editor/esm/vs/editor/common/model/textModel.js' -// @ts-ignore Creating a d.ts is not worth it import { Extensions as KeybindingsExtensions } from 'monaco-editor/esm/vs/platform/keybinding/common/keybindingsRegistry.js' import { KeybindingsRegistryImpl as VScodeKeybindingsRegistryImpl } from 'vscode/vs/platform/keybinding/common/keybindingsRegistry.js' import { ITextBuffer } from 'vs/editor/common/model' import { AudioCue } from 'vs/platform/audioCues/browser/audioCueService' import { onServicesInitialized } from './service-override/tools' +type PartialMutable = Partial<{ + -readonly [key in keyof T]: T[key] +}> + // Monaco build process treeshaking is very aggressive and everything that is not used in monaco is removed // Unfortunately, it makes some class not respect anymore the interface they are supposed to implement // In this file we are restoring some method that are treeshaked out of monaco-editor but that are needed in this library @@ -183,9 +153,9 @@ polyfillPrototypeSimple(MonacoQuickInputService.prototype, VScodeQuickInputServi const keydinbingsRegistry = Registry.as(KeybindingsExtensions.EditorModes) polyfillPrototypeSimple(keydinbingsRegistry.constructor.prototype, VScodeKeybindingsRegistryImpl.prototype) -MonacoTextModel.prototype.equalsTextBuffer = function (other: ITextBuffer): boolean { - this._assertNotDisposed() - return this._buffer.equals(other) +MonacoTextModel.prototype.equalsTextBuffer = function (this: MonacoTextModel, other: ITextBuffer): boolean { + this['_assertNotDisposed']() + return this['_buffer'].equals(other) } Object.defineProperty(MonacoListView.prototype, 'onDidChangeContentHeight', { @@ -222,37 +192,30 @@ Object.defineProperty(MonacoDefaultConfiguration.prototype, 'onDidChangeConfigur // To polyfill PieceTreeTextBufferFactory MonacoPieceTreeTextBufferBuilder.prototype.finish = VScodePieceTreeTextBufferBuilder.prototype.finish -const jsonContributionRegistry = Registry.as(JsonExtensions.JSONContribution) -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition +const jsonContributionRegistry = Registry.as>(JsonExtensions.JSONContribution) jsonContributionRegistry.getSchemaContributions ??= () => ({ // eslint-disable-next-line @typescript-eslint/no-explicit-any schemas: (jsonContributionRegistry as any).schemasById }) -// @ts-ignore Override of a readonly property // eslint-disable-next-line @typescript-eslint/no-explicit-any jsonContributionRegistry.onDidChangeSchema ??= (jsonContributionRegistry as any)._onDidChangeSchema.event -const themeRegistry = Registry.as(ThemeExtensions.ThemingContribution) -// @ts-ignore Override of a readonly property +const themeRegistry = Registry.as>(ThemeExtensions.ThemingContribution) // eslint-disable-next-line @typescript-eslint/no-explicit-any themeRegistry.onThemingParticipantAdded ??= (themeRegistry as any).onThemingParticipantAddedEmitter.event -const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration) -// @ts-ignore Override of a readonly property +const configurationRegistry = Registry.as>(ConfigurationExtensions.Configuration) // eslint-disable-next-line @typescript-eslint/no-explicit-any configurationRegistry.onDidUpdateConfiguration ??= (configurationRegistry as any)._onDidUpdateConfiguration.event -// @ts-ignore Override of a readonly property // eslint-disable-next-line @typescript-eslint/no-explicit-any configurationRegistry.onDidSchemaChange ??= (configurationRegistry as any)._onDidSchemaChange.event -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition configurationRegistry.notifyConfigurationSchemaUpdated ??= () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any (configurationRegistry as any)._onDidSchemaChange.fire() } -// @ts-ignore Override of a readonly property -MonacoNoOpNotification.prototype.onDidClose ??= Event.None +(MonacoNoOpNotification.prototype as PartialMutable).onDidClose ??= Event.None Object.defineProperty(GhostTextController.prototype, 'onActiveModelDidChange', { get () { @@ -263,7 +226,7 @@ Object.defineProperty(GhostTextController.prototype, 'onActiveModelDidChange', { function polyfillQuickInput (fn: () => T): () => T { return function (this: QuickInputController) { const quickInput = fn.call(this) - // @ts-ignore Override of a readonly property + // @ts-expect-error quickInput.onDidTriggerButton ??= quickInput.onDidTriggerButtonEmitter.event return quickInput } @@ -300,6 +263,7 @@ for (const key of Object.getOwnPropertyNames(VScodeVSBuffer)) { if (!Object.hasOwnProperty.call(MonacoVSBuffer, key)) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const method = (VScodeVSBuffer as any)[key]; + // @ts-expect-error // eslint-disable-next-line @typescript-eslint/no-explicit-any (VScodeVSBuffer as any)[key] = MonacoVSBuffer[key] = function (...args: any[]) { return toMonacoVSBuffer(method.call(MonacoVSBuffer, ...args.map(toVSCodeVSBuffer))) @@ -336,16 +300,12 @@ Object.defineProperty(AudioCue, 'allAudioCues', { onServicesInitialized(() => { // polyfill for StandaloneWorkspaceContextService - const workspaceContextService = StandaloneServices.get(IWorkspaceContextService) - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - workspaceContextService.getCompleteWorkspace ??= function (this: IWorkspaceContextService) { - return Promise.resolve(this.getWorkspace()) + const workspaceContextService: PartialMutable = StandaloneServices.get(IWorkspaceContextService) + workspaceContextService.getCompleteWorkspace ??= function (this: Partial) { + return Promise.resolve(this.getWorkspace!()) }.bind(workspaceContextService) - // @ts-ignore workspaceContextService.onDidChangeWorkspaceFolders ??= Event.None - // @ts-ignore workspaceContextService.onDidChangeWorkbenchState ??= Event.None - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition workspaceContextService.getWorkbenchState ??= () => WorkbenchState.EMPTY }) diff --git a/tsconfig.json b/tsconfig.json index a5602388..8146e2ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,9 @@ ], "vscode/*": [ "./vscode/*" + ], + "monaco-editor/esm/*": [ + "./vscode/*" ] }, "preserveConstEnums": true diff --git a/tsconfig.types.json b/tsconfig.types.json index 6f1a3f6b..2679dc2d 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -46,6 +46,9 @@ ], "vscode/*": [ "./vscode/*" + ], + "monaco-editor/esm/*": [ + "./vscode/*" ] }, "declaration": true,