fix(editor): bump monaco-editor to 0.55.1 and adapt TypeScript intellisense integration to the updated Monaco API

This commit is contained in:
2025-12-30 16:31:27 +00:00
parent 745cf82fd1
commit f30025957f
8 changed files with 70 additions and 17 deletions

View File

@@ -1,2 +1,2 @@
// Auto-generated by scripts/update-monaco-version.cjs
export const MONACO_VERSION = '0.52.2';
export const MONACO_VERSION = '0.55.1';

View File

@@ -1,6 +1,18 @@
import type * as monaco from 'monaco-editor';
import type { IExecutionEnvironment } from '../../00group-runtime/index.js';
// Monaco TypeScript API types (runtime API still exists, types deprecated in 0.55+)
interface IMonacoTypeScriptAPI {
typescriptDefaults: {
setCompilerOptions(options: Record<string, unknown>): void;
setDiagnosticsOptions(options: Record<string, unknown>): void;
addExtraLib(content: string, filePath?: string): void;
};
ScriptTarget: { ES2020: number };
ModuleKind: { ESNext: number };
ModuleResolutionKind: { NodeJs: number };
}
/**
* Manages TypeScript IntelliSense by loading type definitions
* from the virtual filesystem into Monaco.
@@ -10,6 +22,14 @@ export class TypeScriptIntelliSenseManager {
private monacoInstance: typeof monaco | null = null;
private executionEnvironment: IExecutionEnvironment | null = null;
/**
* Get TypeScript API with proper typing for Monaco 0.55+
*/
private get tsApi(): IMonacoTypeScriptAPI | null {
if (!this.monacoInstance) return null;
return (this.monacoInstance.languages as any).typescript as IMonacoTypeScriptAPI;
}
/**
* Initialize with Monaco and execution environment
*/
@@ -23,12 +43,13 @@ export class TypeScriptIntelliSenseManager {
}
private configureCompilerOptions(): void {
if (!this.monacoInstance) return;
const ts = this.tsApi;
if (!ts) return;
this.monacoInstance.languages.typescript.typescriptDefaults.setCompilerOptions({
target: this.monacoInstance.languages.typescript.ScriptTarget.ES2020,
module: this.monacoInstance.languages.typescript.ModuleKind.ESNext,
moduleResolution: this.monacoInstance.languages.typescript.ModuleResolutionKind.NodeJs,
ts.typescriptDefaults.setCompilerOptions({
target: ts.ScriptTarget.ES2020,
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
allowSyntheticDefaultImports: true,
esModuleInterop: true,
strict: true,
@@ -38,7 +59,7 @@ export class TypeScriptIntelliSenseManager {
lib: ['es2020', 'dom', 'dom.iterable'],
});
this.monacoInstance.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
ts.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
noSyntaxValidation: false,
});
@@ -99,7 +120,8 @@ export class TypeScriptIntelliSenseManager {
}
private async tryLoadPackageTypes(packageName: string): Promise<boolean> {
if (!this.executionEnvironment || !this.monacoInstance) return false;
const ts = this.tsApi;
if (!this.executionEnvironment || !ts) return false;
const basePath = `/node_modules/${packageName}`;
@@ -116,7 +138,7 @@ export class TypeScriptIntelliSenseManager {
const fullTypesPath = `${basePath}/${typesPath}`;
if (await this.executionEnvironment.exists(fullTypesPath)) {
const content = await this.executionEnvironment.readFile(fullTypesPath);
this.monacoInstance.languages.typescript.typescriptDefaults.addExtraLib(
ts.typescriptDefaults.addExtraLib(
content,
`file://${fullTypesPath}`
);
@@ -135,7 +157,7 @@ export class TypeScriptIntelliSenseManager {
for (const dtsPath of commonPaths) {
if (await this.executionEnvironment.exists(dtsPath)) {
const content = await this.executionEnvironment.readFile(dtsPath);
this.monacoInstance.languages.typescript.typescriptDefaults.addExtraLib(
ts.typescriptDefaults.addExtraLib(
content,
`file://${dtsPath}`
);
@@ -150,7 +172,8 @@ export class TypeScriptIntelliSenseManager {
}
private async tryLoadAtTypesPackage(packageName: string): Promise<boolean> {
if (!this.executionEnvironment || !this.monacoInstance) return false;
const ts = this.tsApi;
if (!this.executionEnvironment || !ts) return false;
// Handle scoped packages: @scope/package -> @types/scope__package
const typesPackageName = packageName.startsWith('@')
@@ -163,7 +186,7 @@ export class TypeScriptIntelliSenseManager {
const indexPath = `${basePath}/index.d.ts`;
if (await this.executionEnvironment.exists(indexPath)) {
const content = await this.executionEnvironment.readFile(indexPath);
this.monacoInstance.languages.typescript.typescriptDefaults.addExtraLib(
ts.typescriptDefaults.addExtraLib(
content,
`file://${indexPath}`
);