Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support latest wasm-tools version #184

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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