Let ... in ... block autocomplete also sorted by best 'match', type-wise

This commit is contained in:
Joeri Exelmans 2025-05-16 08:51:58 +02:00
parent 2d81e42447
commit 8abbac4bc9
7 changed files with 66 additions and 43 deletions

View file

@ -3,26 +3,23 @@ import { useContext, useInsertionEffect } from "react";
import { Editor, type EditorState } from "./Editor";
import { Value } from "./Value";
import { type SetStateFn, type State2Props } from "./Editor";
import { evalCallBlock, evalEditorBlock } from "./eval";
import { evalCallBlock, evalEditorBlock, scoreResolved } from "./eval";
import { type ResolvedType } from "./eval";
import "./CallBlock.css";
import { EnvContext } from "./EnvContext";
import type { SuggestionType } from "./InputBlock";
import { UnifyError } from "dope2";
export interface CallBlockState<
FnState=EditorState,
InputState=EditorState,
> {
export interface CallBlockState {
kind: "call";
fn: FnState;
input: InputState;
fn: EditorState;
input: EditorState;
}
interface CallBlockProps<
FnState=EditorState,
InputState=EditorState,
> extends State2Props<CallBlockState<FnState,InputState>,EditorState> {
> extends State2Props<CallBlockState,EditorState> {
suggestionPriority: (suggestion: SuggestionType) => number;
}
@ -110,25 +107,7 @@ export function CallBlockNoSugar({ state, setState, suggestionPriority }: CallBl
function computePriority(fn: ResolvedType, input: ResolvedType, outPriority: (s: SuggestionType) => number) {
const resolved = evalCallBlock(fn, input);
const r = outPriority(['literal', '<computed>',
// @ts-ignore: // TODO fix this
{t: resolved.t}]);
if (resolved.kind === "value") {
// The computed output becomes an input for the surrounding block, which may also have a priority function defined, for instance our output is the input to another function
console.log('r:', r);
return 1 + r;
}
else if (resolved.kind === "unknown") {
return 0 + r;
}
if (resolved.e instanceof UnifyError) {
return -1 + r; // parameter doesn't match
}
else {
return -2 + r; // even worse: fn is not a function!
}
return scoreResolved(resolved, outPriority);
}
function FunctionHeader({ fn, setFn, input, onFnCancel, suggestionPriority }) {