diff --git a/wasm-component-model/package-lock.json b/wasm-component-model/package-lock.json index 744675b3..fc210d3b 100644 --- a/wasm-component-model/package-lock.json +++ b/wasm-component-model/package-lock.json @@ -1,12 +1,12 @@ { "name": "@vscode/wasm-component-model", - "version": "0.1.0-pre.13", + "version": "0.1.0-pre.16", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@vscode/wasm-component-model", - "version": "0.1.0-pre.13", + "version": "0.1.0-pre.16", "license": "MIT", "dependencies": { "semver": "^7.6.0", diff --git a/wasm-component-model/package.json b/wasm-component-model/package.json index fa4214d6..d4c1ad7c 100644 --- a/wasm-component-model/package.json +++ b/wasm-component-model/package.json @@ -1,6 +1,6 @@ { "name": "@vscode/wasm-component-model", - "version": "0.1.0-pre.15", + "version": "0.1.0-pre.16", "description": "A VS Code specific component model implementation", "author": "Visual Studio Code Team", "license": "MIT", diff --git a/wasm-component-model/src/common/componentModel.ts b/wasm-component-model/src/common/componentModel.ts index 907669b5..7b1dc054 100644 --- a/wasm-component-model/src/common/componentModel.ts +++ b/wasm-component-model/src/common/componentModel.ts @@ -4035,11 +4035,16 @@ export type WorldType = { readonly imports?: { readonly functions?: Map>; readonly interfaces?: Map; + create?(service: any, context: WasmContext): any; + loop?(service: any, context: WasmContext): any; }; readonly exports?: { readonly functions?: Map>; readonly interfaces?: Map; + bind?(service: any, context: WasmContext): any; }; + bind?(service: any, code: Code, context?: ComponentModelContext): Promise; + bind?(service: any, code: Code, port: RAL.ConnectionPort, context?: ComponentModelContext): Promise; }; export type PackageType = { diff --git a/wasm-component-model/src/tools/wit-json.ts b/wasm-component-model/src/tools/wit-json.ts index f0e71244..e9e59b1c 100644 --- a/wasm-component-model/src/tools/wit-json.ts +++ b/wasm-component-model/src/tools/wit-json.ts @@ -419,7 +419,7 @@ export namespace ObjectKind { return typeof (kind as FuncObject).function === 'object'; } export function isInterfaceObject(kind: ObjectKind): kind is InterfaceObject { - return typeof (kind as InterfaceObject).interface === 'number'; + return InterfaceObjectId.is((kind as InterfaceObject).interface); } } @@ -431,8 +431,20 @@ export interface FuncObject { function: Func; } +export type InterfaceObjectId = number | { id: number}; +export namespace InterfaceObjectId { + export function isNumber(value: InterfaceObjectId): value is number { + return typeof value === 'number'; + } + export function isId(value: InterfaceObjectId): value is { id: number } { + return typeof value === 'object' && typeof (value as { id: number }).id === 'number'; + } + export function is(value: InterfaceObjectId): value is { id: number } { + return isNumber(value) || isId(value); + } +} export interface InterfaceObject { - interface: number; + interface: InterfaceObjectId; } export type TypeReference = number | string; diff --git a/wasm-component-model/src/tools/wit2ts.ts b/wasm-component-model/src/tools/wit2ts.ts index 91f63992..4b288725 100644 --- a/wasm-component-model/src/tools/wit2ts.ts +++ b/wasm-component-model/src/tools/wit2ts.ts @@ -9,7 +9,7 @@ import * as path from 'node:path'; import { ResolvedOptions } from './options'; import { AbstractType, BaseType, BorrowHandleType, Callable, Constructor, Document, Documentation, EnumCase, EnumType, Field, Flag, - FlagsType, Func, Interface, ListType, Member, Method, ObjectKind, OptionType, OwnHandleType, Owner, Package, Param, + FlagsType, Func, Interface, InterfaceObjectId, ListType, Member, Method, ObjectKind, OptionType, OwnHandleType, Owner, Package, Param, RecordType, ReferenceType, ResourceType, ResultType, StaticMethod, TupleType, Type, TypeKind, TypeReference, VariantCase, VariantType, World, type InterfaceObject, type PackageNameParts, type TypeObject } from './wit-json'; @@ -720,8 +720,14 @@ class SymbolTable { return this.resultErrorTypes.has(item); } - public getInterface(ref: number): Interface { - return this.document.interfaces[ref]; + public getInterface(ref: InterfaceObjectId): Interface { + if (InterfaceObjectId.isNumber(ref)) { + return this.document.interfaces[ref]; + } else if (InterfaceObjectId.isId(ref)) { + return this.document.interfaces[ref.id]; + } else { + throw new Error(`Unknown interface object id ${JSON.stringify(ref)}`); + } } public getPackage(ref: number): Package {