From d8b60ccf761a7887cb75309bf9828d6112ae7257 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 3 Dec 2021 02:06:17 +0100 Subject: [PATCH] ts-plugin. Works in VS Code, haven't managed to configure Emacs to work with it yet. --- .../ts-plugin/examples/typescript/src/box.ts | 14 +++++++++----- .../examples/typescript/src/client.ts | 12 +++++++++--- .../ts-plugin/examples/typescript/src/index.ts | 15 +++++++++------ .../examples/typescript/src/protocol.ts | 4 ++-- packages/ts-plugin/package.json | 4 ++-- packages/ts-plugin/src/index.ts | 18 ++++++++++++++---- packages/tsc/package.json | 4 ++-- 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/packages/ts-plugin/examples/typescript/src/box.ts b/packages/ts-plugin/examples/typescript/src/box.ts index 0df308e..ce72186 100644 --- a/packages/ts-plugin/examples/typescript/src/box.ts +++ b/packages/ts-plugin/examples/typescript/src/box.ts @@ -2,13 +2,17 @@ /// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones import { BoxState, SetBox, N } from './protocol.js'; +import { Ref } from '@syndicate-lang/core'; -boot { +export function boot(ds: Ref) { spawn named 'box' { - field value: number = 0; - assert BoxState(this.value); - stop on (this.value === N) + field boxValue: number = 0; + at ds { + assert BoxState(boxValue.value); + on message SetBox($v: number) => boxValue.value = v; + } + stop on (boxValue.value === N) { console.log('terminated box root facet'); - on message SetBox($v: number) => this.value = v; + } } } diff --git a/packages/ts-plugin/examples/typescript/src/client.ts b/packages/ts-plugin/examples/typescript/src/client.ts index b1765d1..f572f49 100644 --- a/packages/ts-plugin/examples/typescript/src/client.ts +++ b/packages/ts-plugin/examples/typescript/src/client.ts @@ -2,10 +2,16 @@ /// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones import { BoxState, SetBox } from './protocol.js'; +import { Ref } from '@syndicate-lang/core'; -boot { +export function boot(ds: Ref, doneCallback: () => void) { spawn named 'client' { - on asserted BoxState($v: number) => send message SetBox(v + 1); - on retracted BoxState(_) => console.log('box gone'); + at ds { + on asserted BoxState($v: number) => send message SetBox(v + 1); + on retracted BoxState(_) => { + console.log('box gone'); + doneCallback(); + } + } } } diff --git a/packages/ts-plugin/examples/typescript/src/index.ts b/packages/ts-plugin/examples/typescript/src/index.ts index ae242bd..7aad83f 100644 --- a/packages/ts-plugin/examples/typescript/src/index.ts +++ b/packages/ts-plugin/examples/typescript/src/index.ts @@ -2,11 +2,14 @@ /// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones import { N } from './protocol.js'; -activate import './box.js'; -activate import './client.js'; +import * as Box from './box.js'; +import * as Client from './client.js'; +import { Actor, Dataspace, Turn } from '@syndicate-lang/core'; console.time('box-and-client-' + N.toString()); -boot { - thisFacet.actor.dataspace.ground().addStopHandler(() => - console.timeEnd('box-and-client-' + N.toString())); -} +Actor.boot(() => { + Turn.activeFacet.preventInertCheck(); + const ds = create new Dataspace(); + Box.boot(ds); + Client.boot(ds, () => console.timeEnd('box-and-client-' + N.toString())); +}); diff --git a/packages/ts-plugin/examples/typescript/src/protocol.ts b/packages/ts-plugin/examples/typescript/src/protocol.ts index 551aeba..4e4ed3b 100644 --- a/packages/ts-plugin/examples/typescript/src/protocol.ts +++ b/packages/ts-plugin/examples/typescript/src/protocol.ts @@ -1,7 +1,7 @@ /// SPDX-License-Identifier: GPL-3.0-or-later /// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones -export assertion type BoxState(value); -export message type SetBox(newValue); +export assertion type BoxState(value: number); +export message type SetBox(newValue: number); export const N = 100000; diff --git a/packages/ts-plugin/package.json b/packages/ts-plugin/package.json index a22e401..c03f6a3 100644 --- a/packages/ts-plugin/package.json +++ b/packages/ts-plugin/package.json @@ -21,9 +21,9 @@ "@syndicate-lang/core": "^0.6.0" }, "devDependencies": { - "typescript": "^4.1.3" + "typescript": "^4.5" }, "peerDependencies": { - "typescript": "^4.1.3" + "typescript": "^4.5" } } diff --git a/packages/ts-plugin/src/index.ts b/packages/ts-plugin/src/index.ts index 7a3c269..b33ffac 100644 --- a/packages/ts-plugin/src/index.ts +++ b/packages/ts-plugin/src/index.ts @@ -173,7 +173,7 @@ const boot: tslib.server.PluginModuleFactory = ({ typescript: ts }) => { return sf; } catch (e) { console.error(e); - onError?.(e.message); + onError?.((e as any).message ?? ''); return undefined; } } else { @@ -223,6 +223,10 @@ const boot: tslib.server.PluginModuleFactory = ({ typescript: ts }) => { this.inner = inner; } + provideInlayHints(fileName: string, span: ts.TextSpan, preferences: ts.UserPreferences | undefined): ts.InlayHint[] { + throw new Error('Method not implemented.'); + } + getFileReferences(fileName: string): tslib.ReferenceEntry[] { throw new Error('Method not implemented.'); } @@ -330,13 +334,19 @@ const boot: tslib.server.PluginModuleFactory = ({ typescript: ts }) => { }); } - getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: ts.FormatCodeOptions | ts.FormatCodeSettings | undefined, source: string | undefined, preferences: ts.UserPreferences | undefined): ts.CompletionEntryDetails | undefined { + getCompletionEntryDetails(fileName: string, + position: number, + entryName: string, + formatOptions: ts.FormatCodeOptions | ts.FormatCodeSettings | undefined, + source: string | undefined, + preferences: ts.UserPreferences | undefined, + data: ts.CompletionEntryData | undefined): ts.CompletionEntryDetails | undefined { return withPosition( fileName, position, - () => this.inner.getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences), + () => this.inner.getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data), () => void 0, (fixup) => { - const d = this.inner.getCompletionEntryDetails(fileName, fixup.targetStart, entryName, formatOptions, source, preferences); + const d = this.inner.getCompletionEntryDetails(fileName, fixup.targetStart, entryName, formatOptions, source, preferences, data); if (d !== void 0) { d.codeActions?.forEach(a => a.changes.forEach(c => diff --git a/packages/tsc/package.json b/packages/tsc/package.json index d880d07..1ee6fe6 100644 --- a/packages/tsc/package.json +++ b/packages/tsc/package.json @@ -25,9 +25,9 @@ }, "devDependencies": { "@types/yargs": "^15.0.12", - "typescript": "^4.1.3" + "typescript": "^4.5" }, "peerDependencies": { - "typescript": "^4.1.3" + "typescript": "^4.5" } }