suggestions work again, improve error reporting
This commit is contained in:
parent
9050581a10
commit
69175c8cb1
12 changed files with 259 additions and 282 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { useContext } from "react";
|
||||
|
||||
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 { GlobalContext } from "../../context/GlobalContext";
|
||||
|
||||
|
|
@ -30,11 +29,7 @@ function nestedFnProperties({state, setState, score}: CallBlockProps, env: Envir
|
|||
setState(state => state.input); // we become our input
|
||||
};
|
||||
const scoreFn = (fnSuggestion: ExprBlockState) => {
|
||||
return score({
|
||||
kind: "call",
|
||||
fn: fnSuggestion,
|
||||
input: state.input,
|
||||
});
|
||||
return score({ ...state, fn: fnSuggestion });
|
||||
};
|
||||
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
|
||||
};
|
||||
const scoreInput = (inputSuggestion: ExprBlockState) => {
|
||||
return score({
|
||||
kind: "call",
|
||||
fn: state.fn,
|
||||
input: inputSuggestion,
|
||||
});
|
||||
return score({ ...state, input: inputSuggestion });
|
||||
};
|
||||
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) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
|
|
@ -80,9 +62,6 @@ export function CallBlock(props: CallBlockProps) {
|
|||
{/* Sequence of input parameters */}
|
||||
<InputParams
|
||||
{...props}
|
||||
depth={0}
|
||||
// errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1}
|
||||
errorDepth={-1}
|
||||
addParam={addParam}
|
||||
/>
|
||||
{/* { (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 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" : "")}>
|
||||
{rest.state.fn.kind === "call"
|
||||
&& globalContext?.syntacticSugar
|
||||
&& <InputParams
|
||||
{...nestedFnProperties(rest as CallBlockProps, env)}
|
||||
depth={depth+1}
|
||||
errorDepth={errorDepth}
|
||||
/>}
|
||||
{/* Our own input param */}
|
||||
<EnvContext value={inferTypeCall(rest.state, env).inputEnv}>
|
||||
<EnvContext value={inputEnv}>
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(rest as CallBlockProps, env)}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue