Skip to content

Commit

Permalink
Support latest wasm-tools version (#184)
Browse files Browse the repository at this point in the history
* Add functions to WorldType

* Support latest wasm-tools version
  • Loading branch information
dbaeumer authored Aug 26, 2024
1 parent 9e7dab8 commit 8a5c437
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions wasm-component-model/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wasm-component-model/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions wasm-component-model/src/common/componentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4035,11 +4035,16 @@ export type WorldType = {
readonly imports?: {
readonly functions?: Map<string, FunctionType<JFunction>>;
readonly interfaces?: Map<string, InterfaceType>;
create?(service: any, context: WasmContext): any;
loop?(service: any, context: WasmContext): any;
};
readonly exports?: {
readonly functions?: Map<string, FunctionType<JFunction>>;
readonly interfaces?: Map<string, InterfaceType>;
bind?(service: any, context: WasmContext): any;
};
bind?(service: any, code: Code, context?: ComponentModelContext): Promise<any>;
bind?(service: any, code: Code, port: RAL.ConnectionPort, context?: ComponentModelContext): Promise<any>;
};

export type PackageType = {
Expand Down
16 changes: 14 additions & 2 deletions wasm-component-model/src/tools/wit-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions wasm-component-model/src/tools/wit2ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a5c437

Please sign in to comment.