suggestions work again, improve error reporting

This commit is contained in:
Joeri Exelmans 2025-05-24 09:42:26 +02:00
parent 9050581a10
commit 69175c8cb1
12 changed files with 259 additions and 282 deletions

View file

@ -10,7 +10,7 @@ export default tseslint.config(
extends: [js.configs.recommended, ...tseslint.configs.recommended], extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'], files: ['**/*.{ts,tsx}'],
languageOptions: { languageOptions: {
ecmaVersion: 2020, ecmaVersion: "latest",
globals: globals.browser, globals: globals.browser,
}, },
plugins: { plugins: {

176
pnpm-lock.yaml generated
View file

@ -16,7 +16,7 @@ importers:
version: 5.2.5 version: 5.2.5
dope2: dope2:
specifier: git+https://deemz.org/git/joeri/dope2.git specifier: git+https://deemz.org/git/joeri/dope2.git
version: git+https://deemz.org/git/joeri/dope2.git#664f31447fb313be3a01b80b220216b3374ef24f version: git+https://deemz.org/git/joeri/dope2.git#cac0cb7f81c4359f8014caa508707ecf41e09092
react: react:
specifier: ^19.1.0 specifier: ^19.1.0
version: 19.1.0 version: 19.1.0
@ -289,103 +289,103 @@ packages:
'@rolldown/pluginutils@1.0.0-beta.9': '@rolldown/pluginutils@1.0.0-beta.9':
resolution: {integrity: sha512-e9MeMtVWo186sgvFFJOPGy7/d2j2mZhLJIdVW0C/xDluuOvymEATqz6zKsP0ZmXGzQtqlyjz5sC1sYQUoJG98w==} resolution: {integrity: sha512-e9MeMtVWo186sgvFFJOPGy7/d2j2mZhLJIdVW0C/xDluuOvymEATqz6zKsP0ZmXGzQtqlyjz5sC1sYQUoJG98w==}
'@rollup/rollup-android-arm-eabi@4.41.0': '@rollup/rollup-android-arm-eabi@4.41.1':
resolution: {integrity: sha512-KxN+zCjOYHGwCl4UCtSfZ6jrq/qi88JDUtiEFk8LELEHq2Egfc/FgW+jItZiOLRuQfb/3xJSgFuNPC9jzggX+A==} resolution: {integrity: sha512-NELNvyEWZ6R9QMkiytB4/L4zSEaBC03KIXEghptLGLZWJ6VPrL63ooZQCOnlx36aQPGhzuOMwDerC1Eb2VmrLw==}
cpu: [arm] cpu: [arm]
os: [android] os: [android]
'@rollup/rollup-android-arm64@4.41.0': '@rollup/rollup-android-arm64@4.41.1':
resolution: {integrity: sha512-yDvqx3lWlcugozax3DItKJI5j05B0d4Kvnjx+5mwiUpWramVvmAByYigMplaoAQ3pvdprGCTCE03eduqE/8mPQ==} resolution: {integrity: sha512-DXdQe1BJ6TK47ukAoZLehRHhfKnKg9BjnQYUu9gzhI8Mwa1d2fzxA1aw2JixHVl403bwp1+/o/NhhHtxWJBgEA==}
cpu: [arm64] cpu: [arm64]
os: [android] os: [android]
'@rollup/rollup-darwin-arm64@4.41.0': '@rollup/rollup-darwin-arm64@4.41.1':
resolution: {integrity: sha512-2KOU574vD3gzcPSjxO0eyR5iWlnxxtmW1F5CkNOHmMlueKNCQkxR6+ekgWyVnz6zaZihpUNkGxjsYrkTJKhkaw==} resolution: {integrity: sha512-5afxvwszzdulsU2w8JKWwY8/sJOLPzf0e1bFuvcW5h9zsEg+RQAojdW0ux2zyYAz7R8HvvzKCjLNJhVq965U7w==}
cpu: [arm64] cpu: [arm64]
os: [darwin] os: [darwin]
'@rollup/rollup-darwin-x64@4.41.0': '@rollup/rollup-darwin-x64@4.41.1':
resolution: {integrity: sha512-gE5ACNSxHcEZyP2BA9TuTakfZvULEW4YAOtxl/A/YDbIir/wPKukde0BNPlnBiP88ecaN4BJI2TtAd+HKuZPQQ==} resolution: {integrity: sha512-egpJACny8QOdHNNMZKf8xY0Is6gIMz+tuqXlusxquWu3F833DcMwmGM7WlvCO9sB3OsPjdC4U0wHw5FabzCGZg==}
cpu: [x64] cpu: [x64]
os: [darwin] os: [darwin]
'@rollup/rollup-freebsd-arm64@4.41.0': '@rollup/rollup-freebsd-arm64@4.41.1':
resolution: {integrity: sha512-GSxU6r5HnWij7FoSo7cZg3l5GPg4HFLkzsFFh0N/b16q5buW1NAWuCJ+HMtIdUEi6XF0qH+hN0TEd78laRp7Dg==} resolution: {integrity: sha512-DBVMZH5vbjgRk3r0OzgjS38z+atlupJ7xfKIDJdZZL6sM6wjfDNo64aowcLPKIx7LMQi8vybB56uh1Ftck/Atg==}
cpu: [arm64] cpu: [arm64]
os: [freebsd] os: [freebsd]
'@rollup/rollup-freebsd-x64@4.41.0': '@rollup/rollup-freebsd-x64@4.41.1':
resolution: {integrity: sha512-KGiGKGDg8qLRyOWmk6IeiHJzsN/OYxO6nSbT0Vj4MwjS2XQy/5emsmtoqLAabqrohbgLWJ5GV3s/ljdrIr8Qjg==} resolution: {integrity: sha512-3FkydeohozEskBxNWEIbPfOE0aqQgB6ttTkJ159uWOFn42VLyfAiyD9UK5mhu+ItWzft60DycIN1Xdgiy8o/SA==}
cpu: [x64] cpu: [x64]
os: [freebsd] os: [freebsd]
'@rollup/rollup-linux-arm-gnueabihf@4.41.0': '@rollup/rollup-linux-arm-gnueabihf@4.41.1':
resolution: {integrity: sha512-46OzWeqEVQyX3N2/QdiU/CMXYDH/lSHpgfBkuhl3igpZiaB3ZIfSjKuOnybFVBQzjsLwkus2mjaESy8H41SzvA==} resolution: {integrity: sha512-wC53ZNDgt0pqx5xCAgNunkTzFE8GTgdZ9EwYGVcg+jEjJdZGtq9xPjDnFgfFozQI/Xm1mh+D9YlYtl+ueswNEg==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
'@rollup/rollup-linux-arm-musleabihf@4.41.0': '@rollup/rollup-linux-arm-musleabihf@4.41.1':
resolution: {integrity: sha512-lfgW3KtQP4YauqdPpcUZHPcqQXmTmH4nYU0cplNeW583CMkAGjtImw4PKli09NFi2iQgChk4e9erkwlfYem6Lg==} resolution: {integrity: sha512-jwKCca1gbZkZLhLRtsrka5N8sFAaxrGz/7wRJ8Wwvq3jug7toO21vWlViihG85ei7uJTpzbXZRcORotE+xyrLA==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
'@rollup/rollup-linux-arm64-gnu@4.41.0': '@rollup/rollup-linux-arm64-gnu@4.41.1':
resolution: {integrity: sha512-nn8mEyzMbdEJzT7cwxgObuwviMx6kPRxzYiOl6o/o+ChQq23gfdlZcUNnt89lPhhz3BYsZ72rp0rxNqBSfqlqw==} resolution: {integrity: sha512-g0UBcNknsmmNQ8V2d/zD2P7WWfJKU0F1nu0k5pW4rvdb+BIqMm8ToluW/eeRmxCared5dD76lS04uL4UaNgpNA==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
'@rollup/rollup-linux-arm64-musl@4.41.0': '@rollup/rollup-linux-arm64-musl@4.41.1':
resolution: {integrity: sha512-l+QK99je2zUKGd31Gh+45c4pGDAqZSuWQiuRFCdHYC2CSiO47qUWsCcenrI6p22hvHZrDje9QjwSMAFL3iwXwQ==} resolution: {integrity: sha512-XZpeGB5TKEZWzIrj7sXr+BEaSgo/ma/kCgrZgL0oo5qdB1JlTzIYQKel/RmhT6vMAvOdM2teYlAaOGJpJ9lahg==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
'@rollup/rollup-linux-loongarch64-gnu@4.41.0': '@rollup/rollup-linux-loongarch64-gnu@4.41.1':
resolution: {integrity: sha512-WbnJaxPv1gPIm6S8O/Wg+wfE/OzGSXlBMbOe4ie+zMyykMOeqmgD1BhPxZQuDqwUN+0T/xOFtL2RUWBspnZj3w==} resolution: {integrity: sha512-bkCfDJ4qzWfFRCNt5RVV4DOw6KEgFTUZi2r2RuYhGWC8WhCA8lCAJhDeAmrM/fdiAH54m0mA0Vk2FGRPyzI+tw==}
cpu: [loong64] cpu: [loong64]
os: [linux] os: [linux]
'@rollup/rollup-linux-powerpc64le-gnu@4.41.0': '@rollup/rollup-linux-powerpc64le-gnu@4.41.1':
resolution: {integrity: sha512-eRDWR5t67/b2g8Q/S8XPi0YdbKcCs4WQ8vklNnUYLaSWF+Cbv2axZsp4jni6/j7eKvMLYCYdcsv8dcU+a6QNFg==} resolution: {integrity: sha512-3mr3Xm+gvMX+/8EKogIZSIEF0WUu0HL9di+YWlJpO8CQBnoLAEL/roTCxuLncEdgcfJcvA4UMOf+2dnjl4Ut1A==}
cpu: [ppc64] cpu: [ppc64]
os: [linux] os: [linux]
'@rollup/rollup-linux-riscv64-gnu@4.41.0': '@rollup/rollup-linux-riscv64-gnu@4.41.1':
resolution: {integrity: sha512-TWrZb6GF5jsEKG7T1IHwlLMDRy2f3DPqYldmIhnA2DVqvvhY2Ai184vZGgahRrg8k9UBWoSlHv+suRfTN7Ua4A==} resolution: {integrity: sha512-3rwCIh6MQ1LGrvKJitQjZFuQnT2wxfU+ivhNBzmxXTXPllewOF7JR1s2vMX/tWtUYFgphygxjqMl76q4aMotGw==}
cpu: [riscv64] cpu: [riscv64]
os: [linux] os: [linux]
'@rollup/rollup-linux-riscv64-musl@4.41.0': '@rollup/rollup-linux-riscv64-musl@4.41.1':
resolution: {integrity: sha512-ieQljaZKuJpmWvd8gW87ZmSFwid6AxMDk5bhONJ57U8zT77zpZ/TPKkU9HpnnFrM4zsgr4kiGuzbIbZTGi7u9A==} resolution: {integrity: sha512-LdIUOb3gvfmpkgFZuccNa2uYiqtgZAz3PTzjuM5bH3nvuy9ty6RGc/Q0+HDFrHrizJGVpjnTZ1yS5TNNjFlklw==}
cpu: [riscv64] cpu: [riscv64]
os: [linux] os: [linux]
'@rollup/rollup-linux-s390x-gnu@4.41.0': '@rollup/rollup-linux-s390x-gnu@4.41.1':
resolution: {integrity: sha512-/L3pW48SxrWAlVsKCN0dGLB2bi8Nv8pr5S5ocSM+S0XCn5RCVCXqi8GVtHFsOBBCSeR+u9brV2zno5+mg3S4Aw==} resolution: {integrity: sha512-oIE6M8WC9ma6xYqjvPhzZYk6NbobIURvP/lEbh7FWplcMO6gn7MM2yHKA1eC/GvYwzNKK/1LYgqzdkZ8YFxR8g==}
cpu: [s390x] cpu: [s390x]
os: [linux] os: [linux]
'@rollup/rollup-linux-x64-gnu@4.41.0': '@rollup/rollup-linux-x64-gnu@4.41.1':
resolution: {integrity: sha512-XMLeKjyH8NsEDCRptf6LO8lJk23o9wvB+dJwcXMaH6ZQbbkHu2dbGIUindbMtRN6ux1xKi16iXWu6q9mu7gDhQ==} resolution: {integrity: sha512-cWBOvayNvA+SyeQMp79BHPK8ws6sHSsYnK5zDcsC3Hsxr1dgTABKjMnMslPq1DvZIp6uO7kIWhiGwaTdR4Og9A==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
'@rollup/rollup-linux-x64-musl@4.41.0': '@rollup/rollup-linux-x64-musl@4.41.1':
resolution: {integrity: sha512-m/P7LycHZTvSQeXhFmgmdqEiTqSV80zn6xHaQ1JSqwCtD1YGtwEK515Qmy9DcB2HK4dOUVypQxvhVSy06cJPEg==} resolution: {integrity: sha512-y5CbN44M+pUCdGDlZFzGGBSKCA4A/J2ZH4edTYSSxFg7ce1Xt3GtydbVKWLlzL+INfFIZAEg1ZV6hh9+QQf9YQ==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
'@rollup/rollup-win32-arm64-msvc@4.41.0': '@rollup/rollup-win32-arm64-msvc@4.41.1':
resolution: {integrity: sha512-4yodtcOrFHpbomJGVEqZ8fzD4kfBeCbpsUy5Pqk4RluXOdsWdjLnjhiKy2w3qzcASWd04fp52Xz7JKarVJ5BTg==} resolution: {integrity: sha512-lZkCxIrjlJlMt1dLO/FbpZbzt6J/A8p4DnqzSa4PWqPEUUUnzXLeki/iyPLfV0BmHItlYgHUqJe+3KiyydmiNQ==}
cpu: [arm64] cpu: [arm64]
os: [win32] os: [win32]
'@rollup/rollup-win32-ia32-msvc@4.41.0': '@rollup/rollup-win32-ia32-msvc@4.41.1':
resolution: {integrity: sha512-tmazCrAsKzdkXssEc65zIE1oC6xPHwfy9d5Ta25SRCDOZS+I6RypVVShWALNuU9bxIfGA0aqrmzlzoM5wO5SPQ==} resolution: {integrity: sha512-+psFT9+pIh2iuGsxFYYa/LhS5MFKmuivRsx9iPJWNSGbh2XVEjk90fmpUEjCnILPEPJnikAU6SFDiEUyOv90Pg==}
cpu: [ia32] cpu: [ia32]
os: [win32] os: [win32]
'@rollup/rollup-win32-x64-msvc@4.41.0': '@rollup/rollup-win32-x64-msvc@4.41.1':
resolution: {integrity: sha512-h1J+Yzjo/X+0EAvR2kIXJDuTuyT7drc+t2ALY0nIcGPbTatNOf0VWdhEA2Z4AAjv6X1NJV7SYo5oCTYRJhSlVA==} resolution: {integrity: sha512-Wq2zpapRYLfi4aKxf2Xff0tN+7slj2d4R87WEzqw7ZLsVvO5zwYCIuEGSZYiK41+GlwUo1HiR+GdkLEJnCKTCw==}
cpu: [x64] cpu: [x64]
os: [win32] os: [win32]
@ -600,8 +600,8 @@ packages:
deep-is@0.1.4: deep-is@0.1.4:
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
dope2@git+https://deemz.org/git/joeri/dope2.git#664f31447fb313be3a01b80b220216b3374ef24f: dope2@git+https://deemz.org/git/joeri/dope2.git#cac0cb7f81c4359f8014caa508707ecf41e09092:
resolution: {commit: 664f31447fb313be3a01b80b220216b3374ef24f, repo: https://deemz.org/git/joeri/dope2.git, type: git} resolution: {commit: cac0cb7f81c4359f8014caa508707ecf41e09092, repo: https://deemz.org/git/joeri/dope2.git, type: git}
version: 0.0.1 version: 0.0.1
esbuild@0.25.4: esbuild@0.25.4:
@ -891,8 +891,8 @@ packages:
resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==} resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==}
engines: {iojs: '>=1.0.0', node: '>=0.10.0'} engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
rollup@4.41.0: rollup@4.41.1:
resolution: {integrity: sha512-HqMFpUbWlf/tvcxBFNKnJyzc7Lk+XO3FGc3pbNBLqEbOz0gPLRgcrlS3UF4MfUrVlstOaP/q0kM6GVvi+LrLRg==} resolution: {integrity: sha512-cPmwD3FnFv8rKMBc1MxWCwVQFxwf1JEmSX3iQXrRVVG15zerAIXRjMFVWnd5Q5QvgKF7Aj+5ykXFhUl+QGnyOw==}
engines: {node: '>=18.0.0', npm: '>=8.0.0'} engines: {node: '>=18.0.0', npm: '>=8.0.0'}
hasBin: true hasBin: true
@ -1165,64 +1165,64 @@ snapshots:
'@rolldown/pluginutils@1.0.0-beta.9': {} '@rolldown/pluginutils@1.0.0-beta.9': {}
'@rollup/rollup-android-arm-eabi@4.41.0': '@rollup/rollup-android-arm-eabi@4.41.1':
optional: true optional: true
'@rollup/rollup-android-arm64@4.41.0': '@rollup/rollup-android-arm64@4.41.1':
optional: true optional: true
'@rollup/rollup-darwin-arm64@4.41.0': '@rollup/rollup-darwin-arm64@4.41.1':
optional: true optional: true
'@rollup/rollup-darwin-x64@4.41.0': '@rollup/rollup-darwin-x64@4.41.1':
optional: true optional: true
'@rollup/rollup-freebsd-arm64@4.41.0': '@rollup/rollup-freebsd-arm64@4.41.1':
optional: true optional: true
'@rollup/rollup-freebsd-x64@4.41.0': '@rollup/rollup-freebsd-x64@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-arm-gnueabihf@4.41.0': '@rollup/rollup-linux-arm-gnueabihf@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-arm-musleabihf@4.41.0': '@rollup/rollup-linux-arm-musleabihf@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-arm64-gnu@4.41.0': '@rollup/rollup-linux-arm64-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-arm64-musl@4.41.0': '@rollup/rollup-linux-arm64-musl@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-loongarch64-gnu@4.41.0': '@rollup/rollup-linux-loongarch64-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-powerpc64le-gnu@4.41.0': '@rollup/rollup-linux-powerpc64le-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-riscv64-gnu@4.41.0': '@rollup/rollup-linux-riscv64-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-riscv64-musl@4.41.0': '@rollup/rollup-linux-riscv64-musl@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-s390x-gnu@4.41.0': '@rollup/rollup-linux-s390x-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-x64-gnu@4.41.0': '@rollup/rollup-linux-x64-gnu@4.41.1':
optional: true optional: true
'@rollup/rollup-linux-x64-musl@4.41.0': '@rollup/rollup-linux-x64-musl@4.41.1':
optional: true optional: true
'@rollup/rollup-win32-arm64-msvc@4.41.0': '@rollup/rollup-win32-arm64-msvc@4.41.1':
optional: true optional: true
'@rollup/rollup-win32-ia32-msvc@4.41.0': '@rollup/rollup-win32-ia32-msvc@4.41.1':
optional: true optional: true
'@rollup/rollup-win32-x64-msvc@4.41.0': '@rollup/rollup-win32-x64-msvc@4.41.1':
optional: true optional: true
'@swc/core-darwin-arm64@1.11.29': '@swc/core-darwin-arm64@1.11.29':
@ -1437,7 +1437,7 @@ snapshots:
deep-is@0.1.4: {} deep-is@0.1.4: {}
dope2@git+https://deemz.org/git/joeri/dope2.git#664f31447fb313be3a01b80b220216b3374ef24f: dope2@git+https://deemz.org/git/joeri/dope2.git#cac0cb7f81c4359f8014caa508707ecf41e09092:
dependencies: dependencies:
functional-red-black-tree: 1.0.1 functional-red-black-tree: 1.0.1
@ -1730,30 +1730,30 @@ snapshots:
reusify@1.1.0: {} reusify@1.1.0: {}
rollup@4.41.0: rollup@4.41.1:
dependencies: dependencies:
'@types/estree': 1.0.7 '@types/estree': 1.0.7
optionalDependencies: optionalDependencies:
'@rollup/rollup-android-arm-eabi': 4.41.0 '@rollup/rollup-android-arm-eabi': 4.41.1
'@rollup/rollup-android-arm64': 4.41.0 '@rollup/rollup-android-arm64': 4.41.1
'@rollup/rollup-darwin-arm64': 4.41.0 '@rollup/rollup-darwin-arm64': 4.41.1
'@rollup/rollup-darwin-x64': 4.41.0 '@rollup/rollup-darwin-x64': 4.41.1
'@rollup/rollup-freebsd-arm64': 4.41.0 '@rollup/rollup-freebsd-arm64': 4.41.1
'@rollup/rollup-freebsd-x64': 4.41.0 '@rollup/rollup-freebsd-x64': 4.41.1
'@rollup/rollup-linux-arm-gnueabihf': 4.41.0 '@rollup/rollup-linux-arm-gnueabihf': 4.41.1
'@rollup/rollup-linux-arm-musleabihf': 4.41.0 '@rollup/rollup-linux-arm-musleabihf': 4.41.1
'@rollup/rollup-linux-arm64-gnu': 4.41.0 '@rollup/rollup-linux-arm64-gnu': 4.41.1
'@rollup/rollup-linux-arm64-musl': 4.41.0 '@rollup/rollup-linux-arm64-musl': 4.41.1
'@rollup/rollup-linux-loongarch64-gnu': 4.41.0 '@rollup/rollup-linux-loongarch64-gnu': 4.41.1
'@rollup/rollup-linux-powerpc64le-gnu': 4.41.0 '@rollup/rollup-linux-powerpc64le-gnu': 4.41.1
'@rollup/rollup-linux-riscv64-gnu': 4.41.0 '@rollup/rollup-linux-riscv64-gnu': 4.41.1
'@rollup/rollup-linux-riscv64-musl': 4.41.0 '@rollup/rollup-linux-riscv64-musl': 4.41.1
'@rollup/rollup-linux-s390x-gnu': 4.41.0 '@rollup/rollup-linux-s390x-gnu': 4.41.1
'@rollup/rollup-linux-x64-gnu': 4.41.0 '@rollup/rollup-linux-x64-gnu': 4.41.1
'@rollup/rollup-linux-x64-musl': 4.41.0 '@rollup/rollup-linux-x64-musl': 4.41.1
'@rollup/rollup-win32-arm64-msvc': 4.41.0 '@rollup/rollup-win32-arm64-msvc': 4.41.1
'@rollup/rollup-win32-ia32-msvc': 4.41.0 '@rollup/rollup-win32-ia32-msvc': 4.41.1
'@rollup/rollup-win32-x64-msvc': 4.41.0 '@rollup/rollup-win32-x64-msvc': 4.41.1
fsevents: 2.3.3 fsevents: 2.3.3
run-parallel@1.2.0: run-parallel@1.2.0:
@ -1817,7 +1817,7 @@ snapshots:
fdir: 6.4.4(picomatch@4.0.2) fdir: 6.4.4(picomatch@4.0.2)
picomatch: 4.0.2 picomatch: 4.0.2
postcss: 8.5.3 postcss: 8.5.3
rollup: 4.41.0 rollup: 4.41.1
tinyglobby: 0.2.13 tinyglobby: 0.2.13
optionalDependencies: optionalDependencies:
fsevents: 2.3.3 fsevents: 2.3.3

View file

@ -1,11 +1,14 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import './App.css'; import { extendedEnv } from '../../context/EnvContext';
import { ExprBlock, type ExprBlockState } from '../expr/ExprBlock';
import { GlobalContext } from '../../context/GlobalContext'; import { GlobalContext } from '../../context/GlobalContext';
import { biggerExample, emptySet, factorial, higherOrder, higherOrder2Params, inc, initialEditorState, lambda2Params, nonEmptyEditorState, pushBool, tripleFunctionCallEditorState } from "./configurations"; import { inferType, scoreTypeInfo } from '../../eval/infer_type';
import { ExprBlock, type ExprBlockState } from '../expr/ExprBlock';
import { actionShortcuts } from './actions'; import { actionShortcuts } from './actions';
import { biggerExample, emptySet, factorial, higherOrder, higherOrder2Params, inc, initialEditorState, lambda2Params, nonEmptyEditorState, pushBool, setOfListOfBool, tripleFunctionCallEditorState } from "./configurations";
// import { scoreResolved, type ResolvedType } from './eval'; // import { scoreResolved, type ResolvedType } from './eval';
import './App.css';
const examples: [string, ExprBlockState][] = [ const examples: [string, ExprBlockState][] = [
["empty editor" , initialEditorState ], ["empty editor" , initialEditorState ],
@ -19,6 +22,7 @@ const examples: [string, ExprBlockState][] = [
["inc" , inc ], ["inc" , inc ],
["empty set" , emptySet ], ["empty set" , emptySet ],
["factorial" , factorial ], ["factorial" , factorial ],
["set of list of bool" , setOfListOfBool ],
]; ];
type AppState = { type AppState = {
@ -124,7 +128,6 @@ export function App() {
const onSelectExample = (e: React.SyntheticEvent<HTMLSelectElement>) => { const onSelectExample = (e: React.SyntheticEvent<HTMLSelectElement>) => {
// @ts-ignore // @ts-ignore
if (e.target.value >= 0) { if (e.target.value >= 0) {
// @ts-ignore
// @ts-ignore // @ts-ignore
pushHistory(_ => examples[e.target.value][1]); pushHistory(_ => examples[e.target.value][1]);
} }
@ -168,7 +171,10 @@ export function App() {
state={appState.history.at(-1)!} state={appState.history.at(-1)!}
setState={pushHistory} setState={pushHistory}
onCancel={() => {}} onCancel={() => {}}
score={() => 0} score={(state: ExprBlockState) => {
const typeInfo = inferType(state, extendedEnv);
return scoreTypeInfo(typeInfo);
}}
/> />
</GlobalContext> </GlobalContext>
</main> </main>

View file

@ -3,7 +3,7 @@ import type { ExprBlockState } from "../expr/ExprBlock";
export const initialEditorState: ExprBlockState = { export const initialEditorState: ExprBlockState = {
kind: "input", kind: "input",
text: "", text: "",
value: { kind: "text" }, value: { kind: "gibberish" },
focus: true, focus: true,
}; };
@ -75,7 +75,7 @@ export const tripleFunctionCallEditorState: ExprBlockState = {
}, },
}; };
export const biggerExample: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"text"},"focus":false},"name":"myListInc","value":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.map","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.map","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"myList","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"inc","value":{"kind":"name"},"focus":false}}},"input":{"kind":"input","text":"id","value":{"kind":"name"},"focus":true}}},"name":"myList","value":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"list.emptyList","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"input","text":"2","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"input","text":"3","value":{"kind":"literal","type":"Int"},"focus":false}}},"name":"id","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}}},"name":"inc","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":true}}}}; export const biggerExample: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"gibberish"},"focus":false},"name":"myListInc","value":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.map","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.map","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"myList","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"inc","value":{"kind":"name"},"focus":false}}},"input":{"kind":"input","text":"id","value":{"kind":"name"},"focus":true}}},"name":"myList","value":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"list.push","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"list.emptyList","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"input","text":"2","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"input","text":"3","value":{"kind":"literal","type":"Int"},"focus":false}}},"name":"id","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}}},"name":"inc","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":true}}}};
export const lambda2Params: ExprBlockState = { export const lambda2Params: ExprBlockState = {
"kind": "let", "kind": "let",
@ -83,7 +83,7 @@ export const lambda2Params: ExprBlockState = {
"kind": "input", "kind": "input",
"text": "", "text": "",
"value": { "value": {
"kind": "text" "kind": "gibberish"
}, },
"focus": false "focus": false
}, },
@ -131,7 +131,7 @@ export const lambda2Params: ExprBlockState = {
} }
}; };
export const higherOrder: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"text"},"focus":false},"name":"myBinaryApply","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"lambda","focus":false,"paramName":"fn","expr":{"kind":"call","fn":{"kind":"input","text":"fn","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}}}}}; export const higherOrder: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"gibberish"},"focus":false},"name":"myBinaryApply","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"lambda","focus":false,"paramName":"fn","expr":{"kind":"call","fn":{"kind":"input","text":"fn","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}}}}};
export const higherOrder2Params: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"call","fn":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"myBinaryApply","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"2","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":true}},"name":"myBinaryApply","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"lambda","focus":false,"paramName":"y","expr":{"kind":"lambda","focus":false,"paramName":"fn","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"fn","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"y","value":{"kind":"name"},"focus":true}}}}}}; export const higherOrder2Params: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"call","fn":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"myBinaryApply","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"2","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":true}},"name":"myBinaryApply","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"lambda","focus":false,"paramName":"y","expr":{"kind":"lambda","focus":false,"paramName":"fn","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"fn","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"y","value":{"kind":"name"},"focus":true}}}}}};
@ -139,6 +139,8 @@ export const pushBool: ExprBlockState = {"kind":"call","fn":{"kind":"call","fn":
export const inc: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"name"},"focus":false},"name":"inc","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":true}}}}; export const inc: ExprBlockState = {"kind":"let","focus":false,"inner":{"kind":"input","text":"","value":{"kind":"name"},"focus":false},"name":"inc","value":{"kind":"lambda","focus":false,"paramName":"x","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"x","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":true}}}};
export const emptySet: ExprBlockState = {"kind":"call","fn":{"kind":"input","text":"set.emptySet","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"","value":{"kind":"text"},"focus":true}}; export const emptySet: ExprBlockState = {"kind":"call","fn":{"kind":"input","text":"set.emptySet","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"","value":{"kind":"gibberish"},"focus":true}};
export const factorial: ExprBlockState = {"kind":"lambda","paramName":"factorial","focus":true,"expr":{"kind":"lambda","paramName":"n","focus":true,"expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"leqZero","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":false}},"input":{"kind":"lambda","paramName":"_","focus":false,"expr":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"lambda","paramName":"_","focus":false,"expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"mulInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":true}},"input":{"kind":"call","fn":{"kind":"input","text":"factorial","value":{"kind":"name"},"focus":true},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"-1","value":{"kind":"literal","type":"Int"},"focus":false}}}}}}}}; export const factorial: ExprBlockState = {"kind":"lambda","paramName":"factorial","focus":true,"expr":{"kind":"lambda","paramName":"n","focus":true,"expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"leqZero","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":false}},"input":{"kind":"lambda","paramName":"_","focus":false,"expr":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}}},"input":{"kind":"lambda","paramName":"_","focus":false,"expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"mulInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":true}},"input":{"kind":"call","fn":{"kind":"input","text":"factorial","value":{"kind":"name"},"focus":true},"input":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"n","value":{"kind":"name"},"focus":false}},"input":{"kind":"input","text":"-1","value":{"kind":"literal","type":"Int"},"focus":false}}}}}}}};
export const setOfListOfBool: ExprBlockState = {"kind":"call","fn":{"kind":"input","text":"set.emptySet","value":{"kind":"name"},"focus":false},"input":{"kind":"call","fn":{"kind":"input","text":"compareLists","value":{"kind":"name"}},"input":{"kind":"input","text":"compareDoubles","value":{"kind":"name"}}}};

View file

@ -1,7 +1,6 @@
import { useContext } from "react"; import { useContext } from "react";
import { EnvContext } from "../../context/EnvContext"; import { EnvContext } from "../../context/EnvContext";
// import { addFocusRightMost, evalCallBlock2, evalExprBlock, recomputeTypeVarsForEnv, scoreResolved, type Environment, type ResolvedType } from "./eval";
import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock"; import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock";
import { GlobalContext } from "../../context/GlobalContext"; import { GlobalContext } from "../../context/GlobalContext";
@ -30,11 +29,7 @@ function nestedFnProperties({state, setState, score}: CallBlockProps, env: Envir
setState(state => state.input); // we become our input setState(state => state.input); // we become our input
}; };
const scoreFn = (fnSuggestion: ExprBlockState) => { const scoreFn = (fnSuggestion: ExprBlockState) => {
return score({ return score({ ...state, fn: fnSuggestion });
kind: "call",
fn: fnSuggestion,
input: state.input,
});
}; };
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn}; return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn};
} }
@ -47,24 +42,11 @@ function nestedInputProperties({state, setState, score}: CallBlockProps, env: En
setState(state => /*addFocusRightMost*/(state.fn)); // we become our function setState(state => /*addFocusRightMost*/(state.fn)); // we become our function
}; };
const scoreInput = (inputSuggestion: ExprBlockState) => { const scoreInput = (inputSuggestion: ExprBlockState) => {
return score({ return score({ ...state, input: inputSuggestion });
kind: "call",
fn: state.fn,
input: inputSuggestion,
});
}; };
return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput}; return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput};
} }
// function computePriority(fn: ResolvedType, input: ResolvedType, outPriority: (s: ResolvedType) => number, env) {
// // dirty, but works:
// const [fnR, env2] = recomputeTypeVarsForEnv('<fn>', fn, env);
// const [inR, env3] = recomputeTypeVarsForEnv('<in>', input, env2);
// const [resolved] = evalCallBlock2(fnR, inR, env3);
// const score = scoreResolved(resolved, outPriority);
// return score;
// }
export function CallBlock(props: CallBlockProps) { export function CallBlock(props: CallBlockProps) {
const env = useContext(EnvContext); const env = useContext(EnvContext);
const globalContext = useContext(GlobalContext); const globalContext = useContext(GlobalContext);
@ -80,9 +62,6 @@ export function CallBlock(props: CallBlockProps) {
{/* Sequence of input parameters */} {/* Sequence of input parameters */}
<InputParams <InputParams
{...props} {...props}
depth={0}
// errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1}
errorDepth={-1}
addParam={addParam} addParam={addParam}
/> />
{/* { (resolved.kind === "error") && resolved.e.toString() {/* { (resolved.kind === "error") && resolved.e.toString()
@ -113,20 +92,20 @@ function FunctionHeader(props) {
} }
} }
function InputParams({ depth, errorDepth, ...rest }) { function InputParams({ ...rest }) {
const env = useContext(EnvContext); const env = useContext(EnvContext);
const globalContext = useContext(GlobalContext); const globalContext = useContext(GlobalContext);
const isOffending = depth === errorDepth; const typeInfo = inferTypeCall(rest.state, env);
const inputEnv = typeInfo.fn.newEnv;
const isOffending = rest.state.err;
return <div className={"inputParam" + (isOffending ? " offending" : "")}> return <div className={"inputParam" + (isOffending ? " offending" : "")}>
{rest.state.fn.kind === "call" {rest.state.fn.kind === "call"
&& globalContext?.syntacticSugar && globalContext?.syntacticSugar
&& <InputParams && <InputParams
{...nestedFnProperties(rest as CallBlockProps, env)} {...nestedFnProperties(rest as CallBlockProps, env)}
depth={depth+1}
errorDepth={errorDepth}
/>} />}
{/* Our own input param */} {/* Our own input param */}
<EnvContext value={inferTypeCall(rest.state, env).inputEnv}> <EnvContext value={inputEnv}>
<ExprBlock <ExprBlock
{...nestedInputProperties(rest as CallBlockProps, env)} {...nestedInputProperties(rest as CallBlockProps, env)}
/> />

View file

@ -1,7 +1,5 @@
import { useContext } from "react"; import { useContext } from "react";
import { getType } from "dope2";
import { CallBlock, type CallBlockProps, type CallBlockState } from "./CallBlock"; import { CallBlock, type CallBlockProps, type CallBlockState } from "./CallBlock";
import { EnvContext } from "../../context/EnvContext"; import { EnvContext } from "../../context/EnvContext";
import { GlobalContext } from "../../context/GlobalContext"; import { GlobalContext } from "../../context/GlobalContext";
@ -13,6 +11,7 @@ import { LetInBlock, type LetInBlockProps, type LetInBlockState } from "./LetInB
import "./ExprBlock.css"; import "./ExprBlock.css";
import { Input } from "../other/Input"; import { Input } from "../other/Input";
import { getActions } from "../app/actions"; import { getActions } from "../app/actions";
import { inferType, type Type } from "../../eval/infer_type";
export type ExprBlockState = export type ExprBlockState =
InputBlockState InputBlockState
@ -49,16 +48,14 @@ export function ExprBlock(props: ExprBlockProps) {
const extraHandlers = Object.fromEntries(Object.entries(actions).map(([shortcut, action]) => const extraHandlers = Object.fromEntries(Object.entries(actions).map(([shortcut, action]) =>
[shortcut, (e) => { e.preventDefault(); action(); }])) [shortcut, (e) => { e.preventDefault(); action(); }]))
// return <span className={"editor" + ((resolved.kind!=="value") ? " "+resolved.kind : "")}> const typeInfo = inferType(props.state, env);
return <span className={"editor"}> return <span className={"editor" + (typeInfo.err ? " error" : "")}>
{renderBlock[props.state.kind]()} {renderBlock[props.state.kind]()}
{/* @ts-ignore */} {typeInfo.err &&
{/* <div className={"typeSignature" + (resolved.__debug ? ' gotDebug' : '')}> */} <div>
{/* &nbsp;::&nbsp;<Type type={typeInfo.type} /> */} {typeInfo.err.message.split('\n')[1]}
{/* @ts-ignore */} </div>}
{/* {resolved.__debug && <div className="typeDebug">{resolved.__debug}</div>} */}
{/* </div> */}
<Input <Input
placeholder="<c>" placeholder="<c>"
text="" text=""

View file

@ -3,16 +3,14 @@ import { memo, useContext, useEffect, useMemo, useRef, useState } from "react";
import { trie } from "dope2"; import { trie } from "dope2";
import { EnvContext } from "../../context/EnvContext"; import { EnvContext } from "../../context/EnvContext";
// import type { Environment, ResolvedType } from "./eval";
import "./InputBlock.css"; import "./InputBlock.css";
import { Type } from "../other/Type";
import type { ExprBlockState, State2Props } from "./ExprBlock"; import type { ExprBlockState, State2Props } from "./ExprBlock";
// import { attemptParseLiteral } from "./eval";
import { Input } from "../other/Input"; import { Input } from "../other/Input";
import { CallContext } from "../../context/CallContext"; import { CallContext } from "../../context/CallContext";
import { getActions } from "../app/actions"; import { getActions } from "../app/actions";
import { GlobalContext } from "../../context/GlobalContext"; import { GlobalContext } from "../../context/GlobalContext";
import { inferTypeInput } from "../../eval/infer_type"; import { inferType, inferTypeInput, type Environment, type Type } from "../../eval/infer_type";
import { Type as TypeBlock } from "../other/Type";
interface Literal { interface Literal {
kind: "literal"; kind: "literal";
@ -21,47 +19,60 @@ interface Literal {
interface Name { interface Name {
kind: "name"; kind: "name";
} }
interface Text { interface Gibberish {
kind: "text"; kind: "gibberish";
} }
export type InputValueType = Literal | Name | Text; export type InputValueType = Literal | Name | Gibberish;
export interface InputBlockState { export interface InputBlockState {
kind: "input"; kind: "input";
text: string; text: string;
value: InputValueType; value: InputValueType;
focus: boolean focus?: boolean;
} }
// export type SuggestionType = ["literal"|"name", string, ResolvedType]; export type PrioritizedSuggestionType = [number, Type, InputBlockState];
// export type PrioritizedSuggestionType = [number, ...SuggestionType];
export interface InputBlockProps extends State2Props<InputBlockState,ExprBlockState> { export interface InputBlockProps extends State2Props<InputBlockState,ExprBlockState> {
onCancel: () => void; onCancel: () => void;
} }
// const computeSuggestions = ( const attemptLiterals = [
// text: string, ["Double", text => (text !== '') && !Number.isNaN(Number(text))],
// env: Environment, ["Int" , text => /^-?[0-9]+$/.test(text)]
// score: InputBlockProps['score'], ] as [string, (text: string) => boolean][];
// ): PrioritizedSuggestionType[] => {
// const literals = attemptParseLiteral(text, env);
// const ls: SuggestionType[] = [
// // literals
// ... literals.map((resolved) => ["literal", text, resolved]),
// // names const computeSuggestions = (
// ... trie.suggest(env.names)(text)(Infinity) text: string,
// .map(([name, resolved]) => ["name", name, resolved]), env: Environment,
// ] score: InputBlockProps['score'],
// // return []; // <-- uncomment to disable suggestions (useful for debugging) ): PrioritizedSuggestionType[] => {
// return ls const ls = [
// .map((suggestion: SuggestionType) => ...attemptLiterals
// [score(suggestion[2]), ...suggestion] as PrioritizedSuggestionType) .filter(([_, test]) => test(text))
// .sort(([priorityA], [priorityB]) => priorityB - priorityA) .map(([typename]) => ({
// } kind: "input",
text,
value: {
kind: "literal",
type: typename,
},
})),
...trie.suggest(env.names)(text)(Infinity)
.map(([name]) => ({
kind: "input",
text: name,
value: {
kind: "name",
},
})),
];
// return []; // <-- uncomment to disable suggestions (useful for debugging)
return ls.map((state) => [score(state), inferType(state, env).type, state] as PrioritizedSuggestionType)
.sort(([a],[b]) => b-a);
}
export function InputBlock({ state, setState, /*score,*/ onCancel }: InputBlockProps) { export function InputBlock({ state, setState, score, onCancel }: InputBlockProps) {
const {text, focus} = state; const {text, focus} = state;
const globalContext = useContext(GlobalContext); const globalContext = useContext(GlobalContext);
const env = useContext(EnvContext); const env = useContext(EnvContext);
@ -70,8 +81,7 @@ export function InputBlock({ state, setState, /*score,*/ onCancel }: InputBlockP
const [i, setI] = useState(0); // selected suggestion idx const [i, setI] = useState(0); // selected suggestion idx
const singleSuggestion = trie.growPrefix(env.names)(text); const singleSuggestion = trie.growPrefix(env.names)(text);
// const suggestions = useMemo(() => computeSuggestions(text, env, score), [text, score, env]); const suggestions = useMemo(() => computeSuggestions(text, env, score), [text, score, env]);
const suggestions = useMemo(() => [], []);
useEffect(() => { useEffect(() => {
@ -96,21 +106,8 @@ export function InputBlock({ state, setState, /*score,*/ onCancel }: InputBlockP
} }
const onSelectSuggestion = () => { const onSelectSuggestion = () => {
// const [_priority, kind, name, dynamic] = suggestions[i]; const [_priority, _type, inputState] = suggestions[i];
// if (kind === "literal") { setState(_ => inputState);
// setState(state => ({
// ...state,
// text: name,
// value: {kind, type: prettyT(getType(dynamic))},
// }));
// }
// else {
// setState(state => ({
// ...state,
// text: name,
// value: {kind},
// }))
// }
}; };
const extraHandlers = { const extraHandlers = {
@ -154,7 +151,7 @@ export function InputBlock({ state, setState, /*score,*/ onCancel }: InputBlockP
i={i} setI={setI} /> i={i} setI={setI} />
</span> </span>
</Input> </Input>
::<Type type={typeInfo.type} /> ::<TypeBlock type={typeInfo.type} />
</> </>
} }
@ -176,10 +173,10 @@ interface SuggestionProps {
j: number; j: number;
onSelect: any; onSelect: any;
highlighted: boolean; highlighted: boolean;
// suggestion: PrioritizedSuggestionType; suggestion: PrioritizedSuggestionType;
} }
function Suggestion({ setI, j, onSelect, highlighted, /*suggestion: [priority, kind, text, resolved]*/ }: SuggestionProps) { function Suggestion({ setI, j, onSelect, highlighted, suggestion: [priority, type, {text, value: {kind} }] }: SuggestionProps) {
const onMouseEnter = j => () => { const onMouseEnter = j => () => {
setI(j); setI(j);
}; };
@ -192,7 +189,7 @@ function Suggestion({ setI, j, onSelect, highlighted, /*suggestion: [priority, k
className={(highlighted ? " selected" : "")} className={(highlighted ? " selected" : "")}
onMouseEnter={onMouseEnter(j)} onMouseEnter={onMouseEnter(j)}
onMouseDown={onMouseDown(j)}> onMouseDown={onMouseDown(j)}>
{/* ({priority}) ({kind}) {text} :: <Type type={resolved.t} /> */} ({priority}) ({kind}) {text} :: <TypeBlock type={type} />
</div> </div>
} }

View file

@ -71,10 +71,7 @@ export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
state={state.expr} state={state.expr}
setState={setExpr} setState={setExpr}
onCancel={() => setState(state => state.expr)} onCancel={() => setState(state => state.expr)}
score={(s) => { score={suggestion => score({...state, expr: suggestion})}
// console.log('suggestionPriority of lambdaInner... just passing through');
return score(s);
}}
/> />
</EnvContext> </EnvContext>
</div> </div>

View file

@ -2,7 +2,6 @@ import { useContext } from "react";
import { ExprBlock, type ExprBlockState } from "./ExprBlock"; import { ExprBlock, type ExprBlockState } from "./ExprBlock";
import { EnvContext } from "../../context/EnvContext"; import { EnvContext } from "../../context/EnvContext";
// import { evalExprBlock, makeInnerEnv, scoreResolved, type ResolvedType } from "./eval";
import { type State2Props } from "./ExprBlock"; import { type State2Props } from "./ExprBlock";
import { GlobalContext } from "../../context/GlobalContext"; import { GlobalContext } from "../../context/GlobalContext";
@ -40,16 +39,7 @@ function DeclColumns({state, setState, score}) {
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)})); const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
const setValue = callback => setState(state => ({...state, value: callback(state.value)})); const setValue = callback => setState(state => ({...state, value: callback(state.value)}));
// const valueSuggestionPriority = (suggestion: ResolvedType) => { const {value: valueTypeInfo, innerEnv} = inferTypeLet(state, env);
// const innerEnv = makeInnerEnv(env, name, suggestion);
// const [resolved] = evalExprBlock(inner, innerEnv);
// return scoreResolved(resolved, score);
// };
// const [valueResolved] = evalExprBlock(value, env);
// const innerEnv = makeInnerEnv(env, name, valueResolved);
const {paramType, innerEnv} = inferTypeLet(state, env);
return <> return <>
<span className="keyword column">let&nbsp;</span> <span className="keyword column">let&nbsp;</span>
@ -63,14 +53,14 @@ function DeclColumns({state, setState, score}) {
onTextChange={name => setState(state => ({...state, name}))} onTextChange={name => setState(state => ({...state, name}))}
extraHandlers={{}} extraHandlers={{}}
/> />
:: <Type type={paramType} /> :: <Type type={valueTypeInfo.type} />
</span> </span>
<span className="keyword column">&nbsp;=&nbsp;</span> <span className="keyword column">&nbsp;=&nbsp;</span>
<span className="column"> <span className="column">
<ExprBlock <ExprBlock
state={state.value} state={state.value}
setState={setValue} setState={setValue}
score={() => 0} score={suggestion => score({ ...state, value: suggestion })}
onCancel={() => setState(state => state.inner)} // keep inner onCancel={() => setState(state => state.inner)} // keep inner
/> />
</span> </span>
@ -80,7 +70,7 @@ function DeclColumns({state, setState, score}) {
<DeclColumns <DeclColumns
state={state.inner} state={state.inner}
setState={setInner} setState={setInner}
score={score} score={suggestion => score({ ...state, inner: suggestion })}
/> />
</EnvContext> </EnvContext>
} }
@ -93,14 +83,14 @@ function InnerMost({state, setState, score}) {
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)})); const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
// const [valueResolved] = evalExprBlock(state.value, env); // const [valueResolved] = evalExprBlock(state.value, env);
// const innerEnv = makeInnerEnv(env, state.name, valueResolved); // const innerEnv = makeInnerEnv(env, state.name, valueResolved);
const {paramType, innerEnv} = inferTypeLet(state, env); const {innerEnv} = inferTypeLet(state, env);
const onCancel = () => setState(state => state.value); const onCancel = () => setState(state => state.value);
if (state.inner.kind === "let" && globalContext?.syntacticSugar) { if (state.inner.kind === "let" && globalContext?.syntacticSugar) {
return <EnvContext value={innerEnv}> return <EnvContext value={innerEnv}>
<InnerMost <InnerMost
state={state.inner} state={state.inner}
setState={setInner} setState={setInner}
score={score} score={suggestion => score({ ...state, inner: suggestion })}
/> />
</EnvContext>; </EnvContext>;
} }
@ -109,7 +99,7 @@ function InnerMost({state, setState, score}) {
<ExprBlock <ExprBlock
state={state.inner} state={state.inner}
setState={setInner} setState={setInner}
score={score} score={suggestion => score({ ...state, inner: suggestion })}
onCancel={onCancel} // keep value onCancel={onCancel} // keep value
/> />
</EnvContext> </EnvContext>

View file

@ -1,7 +1,7 @@
import { createContext } from "react"; import { createContext } from "react";
import { getDefaultTypeParser, module2Env, ModuleStd } from "dope2"; import { getDefaultTypeParser, module2Env, ModuleStd } from "dope2";
// import type { Dynamic, Environment } from "./eval"; // import type { Dynamic, Environment } from "./eval";
import type { Environment } from "./infer_type"; import type { Environment } from "../eval/infer_type";
export const functionWith3Params = i => j => k => i+j+k; export const functionWith3Params = i => j => k => i+j+k;
export const functionWith4Params = i => j => k => l => i+j+k+l; export const functionWith4Params = i => j => k => l => i+j+k+l;

View file

@ -460,53 +460,6 @@
// } // }
// } // }
// function parseLiteral(text: string, type: string, env: Environment): [ResolvedType,Environment] {
// // dirty
// if (type === "Int") {
// return parseAsInt(text, env);
// }
// if (type === "Double") {
// return parseAsDouble(text, env);
// }
// return makeError(env, new Error("Failed to parse"));
// }
// function parseAsDouble(text: string, env: Environment): [ResolvedType,Environment] {
// if (text !== '') {
// const num = Number(text);
// if (!Number.isNaN(num)) {
// return [{
// kind: "value",
// i: num,
// t: Double,
// unification: new Map(),
// }, env];
// }
// }
// return makeError(env, new Error("Failed to parse as Double"));
// }
// function parseAsInt(text: string, env: Environment): [ResolvedType,Environment] {
// if (text !== '') {
// try {
// return [{
// kind: "value",
// i: BigInt(text),
// t: Int,
// unification: new Map(),
// }, env]; // may throw
// }
// catch {}
// }
// return makeError(env, new Error("Failed to parse as Int"));
// }
// const literalParsers = [parseAsDouble, parseAsInt];
// export function attemptParseLiteral(text: string, env: Environment): Dynamic[] {
// return literalParsers.map(parseFn => parseFn(text, env))
// .map(([resolved]) => resolved)
// .filter((resolved) => (resolved.kind !== "unknown" && resolved.kind !== "error")) as unknown as Dynamic[];
// }
// export function scoreResolved(resolved: ResolvedType, outPriority: (s:ResolvedType) => number) { // export function scoreResolved(resolved: ResolvedType, outPriority: (s:ResolvedType) => number) {
// const bias = outPriority(resolved); // const bias = outPriority(resolved);

View file

@ -1,4 +1,4 @@
import { Double, eqType, fnType, IncompatibleTypesError, Int, mergeSubstitutionsN, occurring, prettySS, recomputeTypeVars, substitute, trie, TYPE_VARS, UNBOUND_SYMBOLS, unify } from "dope2"; import { Double, eqType, fnType, IncompatibleTypesError, Int, mergeSubstitutionsN, occurring, prettyS, prettySS, prettyT, recomputeTypeVars, substitute, SubstitutionCycle, trie, TYPE_VARS, UNBOUND_SYMBOLS, unify } from "dope2";
import type { CallBlockState } from "../component/expr/CallBlock"; import type { CallBlockState } from "../component/expr/CallBlock";
import type { ExprBlockState } from "../component/expr/ExprBlock"; import type { ExprBlockState } from "../component/expr/ExprBlock";
@ -18,20 +18,35 @@ export interface Type {
export type Substitutions = Map<string, Type>; export type Substitutions = Map<string, Type>;
export interface TypeInfo { interface TypeInfoCommon {
type: Type; type: Type;
subs: Substitutions; subs: Substitutions;
newEnv: Environment; newEnv: Environment;
err?: IncompatibleTypesError; err?: IncompatibleTypesError;
} }
export interface TypeInfoLambda extends TypeInfo { export interface TypeInfoInput extends TypeInfoCommon {
kind: "input";
}
export interface TypeInfoCall extends TypeInfoCommon {
kind: "call";
fn: TypeInfo;
input: TypeInfo;
}
export interface TypeInfoLet extends TypeInfoCommon {
kind: "let";
innerEnv: Environment;
value: TypeInfo;
inner: TypeInfo;
}
export interface TypeInfoLambda extends TypeInfoCommon {
kind: "lambda";
paramType: Type; paramType: Type;
inner: TypeInfo;
innerEnv: Environment; innerEnv: Environment;
} }
export interface TypeInfoCall extends TypeInfo {
inputEnv: Environment; export type TypeInfo = TypeInfoInput | TypeInfoCall | TypeInfoLet | TypeInfoLambda;
}
export function inferType(s: ExprBlockState, env: Environment): TypeInfo { export function inferType(s: ExprBlockState, env: Environment): TypeInfo {
if (s.kind === "input") { if (s.kind === "input") {
@ -48,13 +63,14 @@ export function inferType(s: ExprBlockState, env: Environment): TypeInfo {
} }
} }
export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfo { export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfoInput {
if (s.value.kind === "literal") { if (s.value.kind === "literal") {
const type = { const type = {
Int: Int, Int: Int,
Double: Double, Double: Double,
}[s.value.type] as Type; }[s.value.type] as Type;
return { return {
kind: "input",
type, type,
subs: new Map(), subs: new Map(),
newEnv: env, newEnv: env,
@ -67,18 +83,21 @@ export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfo {
? [found.t, env] ? [found.t, env]
: rewriteType(found.t, env); : rewriteType(found.t, env);
return { return {
kind: "input",
type, type,
subs: new Map(), subs: new Map(),
newEnv, newEnv,
}; };
} }
} }
// kind === "text", or name not found // kind === "gibberish", or name not found
const [type, newEnv] = typeUnknown(env); const [type, newEnv] = typeUnknown(env);
return { return {
kind: "input",
type, type,
subs: new Map(), subs: new Map(),
newEnv, newEnv,
err: new Error("Gibberish"),
} }
} }
@ -104,41 +123,59 @@ export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfoCall
type = returnType; type = returnType;
newEnv = envWithReturn; newEnv = envWithReturn;
} }
const mergedSubs = mergeSubstitutionsN([ let mergedSubs;
fnTypeInfo.subs, try {
inputTypeInfo.subs, mergedSubs = mergeSubstitutionsN([
subs, fnTypeInfo.subs,
]); inputTypeInfo.subs,
subs,
]);
} catch (e) {
if (e instanceof SubstitutionCycle) {
// wrap error
throw new IncompatibleTypesError(fnTypeInfo.type, fakeFnType, e);
}
throw e;
}
return { return {
kind: "call",
type, type,
subs: mergedSubs, subs: mergedSubs,
newEnv, newEnv,
inputEnv, fn: fnTypeInfo,
input: inputTypeInfo,
}; };
} }
catch (e) { catch (e) {
if (e instanceof IncompatibleTypesError) { if (e instanceof IncompatibleTypesError) {
const [type, newEnv] = typeUnknown(env); const [type, newEnv] = typeUnknown(env);
return { return {
kind: "call",
type, type,
subs: new Map(), subs: new Map(),
newEnv, newEnv,
err: e, err: e,
inputEnv, fn: fnTypeInfo,
input: inputTypeInfo,
} }
} }
} }
} }
export function inferTypeLet(s: LetInBlockState, env: Environment): TypeInfoLambda { export function inferTypeLet(s: LetInBlockState, env: Environment): TypeInfoLet {
const valTypeInfo = inferType(s.value, env); const valTypeInfo = inferType(s.value, env);
const innerEnv = { const innerEnv = {
names: trie.insert(env.names)(s.name)({kind: "value", t: valTypeInfo.type}), names: trie.insert(env.names)(s.name)({kind: "value", t: valTypeInfo.type}),
typevars: env.typevars, typevars: env.typevars,
}; };
const innerTypeInfo = inferType(s.inner, innerEnv);
return { return {
...inferType(s.inner, innerEnv), kind: "let",
paramType: valTypeInfo.type, type: innerTypeInfo.type,
subs: innerTypeInfo.subs,
newEnv: env,
value: valTypeInfo,
inner: innerTypeInfo,
innerEnv, innerEnv,
}; };
} }
@ -154,21 +191,23 @@ export function inferTypeLambda(s: LambdaBlockState, env: Environment): TypeInfo
names: trie.insert(env.names)(s.paramName)({kind: "unknown", t: paramType}), names: trie.insert(env.names)(s.paramName)({kind: "unknown", t: paramType}),
typevars: env.typevars.union(occurring(paramType) as Set<string>), typevars: env.typevars.union(occurring(paramType) as Set<string>),
}; };
const typeInfo = inferType(s.expr, innerEnv); const innerTypeInfo = inferType(s.expr, innerEnv);
const subsWithoutPType = new Map(typeInfo.subs); const subsWithoutPType = new Map(innerTypeInfo.subs);
subsWithoutPType.delete(paramTypeVar); subsWithoutPType.delete(paramTypeVar);
const inferredPType = substitute(paramType, typeInfo.subs, []); const inferredPType = substitute(paramType, innerTypeInfo.subs, []);
const inferredPType2 = rewriteInferredType(inferredPType, env); const inferredPType2 = rewriteInferredType(inferredPType, env);
if (eqType(inferredPType2)(paramType)) { if (eqType(inferredPType2)(paramType)) {
return { return {
type: fnType(_ => paramType)(_ => typeInfo.type), kind: "lambda",
type: fnType(_ => paramType)(_ => innerTypeInfo.type),
subs: subsWithoutPType, subs: subsWithoutPType,
newEnv: env, // no change newEnv: env, // no change
paramType, paramType,
inner: innerTypeInfo,
innerEnv, innerEnv,
}; };
} }
if ((iterations++) == 4) { if ((iterations++) == 10) {
throw new Error("too many iterations!"); throw new Error("too many iterations!");
} }
// console.log("-----------------", iterations); // console.log("-----------------", iterations);
@ -192,9 +231,10 @@ const highestTypeVar2 = (typevars: Iterable<string>) => {
} }
function rewriteType(type: Type, env: Environment): [Type, Environment] { function rewriteType(type: Type, env: Environment): [Type, Environment] {
const [recomputed] = recomputeTypeVars([type], highestTypeVar2(env.typevars)+1); const [recomputed] = recomputeTypeVars([type], highestTypeVar2(env.typevars)+1);
return [type, { const newTypeVars = occurring(recomputed);
return [recomputed, {
names: env.names, names: env.names,
typevars: env.typevars.union(occurring(recomputed)), typevars: env.typevars.union(newTypeVars),
}]; }];
} }
function typeUnknown(env: Environment): [Type, Environment] { function typeUnknown(env: Environment): [Type, Environment] {
@ -218,3 +258,19 @@ function rewriteInferredType(type: Type, env: Environment) {
} }
return substitute(type, substitutions, []); return substitute(type, substitutions, []);
} }
export function scoreTypeInfo(typeInfo: TypeInfo): number {
const bias = typeInfo.err ? -1 : 0;
if (typeInfo.kind === "input") {
return bias;
}
else if (typeInfo.kind === "call") {
return bias + scoreTypeInfo(typeInfo.fn) + scoreTypeInfo(typeInfo.input);
}
else if (typeInfo.kind === "let") {
return bias + scoreTypeInfo(typeInfo.value) + scoreTypeInfo(typeInfo.inner);
}
else if (typeInfo.kind === "lambda") {
return bias + scoreTypeInfo(typeInfo.inner);
}
return 0; // shut up typescript
}