infer all types once at the root level, and pass the result down deeply
This commit is contained in:
parent
b2584a2495
commit
d000839878
6 changed files with 75 additions and 80 deletions
|
|
@ -2,15 +2,16 @@ import { memo, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|||
|
||||
import { trie } from "dope2";
|
||||
|
||||
import { EnvContext } from "../../context/EnvContext";
|
||||
import "./InputBlock.css";
|
||||
import type { ExprBlockState, State2Props } from "./ExprBlock";
|
||||
import { Input } from "../other/Input";
|
||||
import { CallContext } from "../../context/CallContext";
|
||||
import { getActions } from "../app/actions";
|
||||
import { EnvContext } from "../../context/EnvContext";
|
||||
import { GlobalContext } from "../../context/GlobalContext";
|
||||
import { inferType, inferTypeInput, type Environment, type Type } from "../../eval/infer_type";
|
||||
import { inferTypeInput, type Environment, type Type, type TypeInfoInput } from "../../eval/infer_type";
|
||||
import { getActions } from "../app/actions";
|
||||
import { Input } from "../other/Input";
|
||||
import { Type as TypeBlock } from "../other/Type";
|
||||
import type { ExprBlockState, State2Props } from "./ExprBlock";
|
||||
|
||||
import "./InputBlock.css";
|
||||
|
||||
interface Literal {
|
||||
kind: "literal";
|
||||
|
|
@ -35,6 +36,7 @@ export type PrioritizedSuggestionType = [number, Type, InputBlockState];
|
|||
|
||||
export interface InputBlockProps extends State2Props<InputBlockState,ExprBlockState> {
|
||||
onCancel: () => void;
|
||||
typeInfo: TypeInfoInput;
|
||||
}
|
||||
|
||||
const attemptLiterals = [
|
||||
|
|
@ -68,11 +70,11 @@ const computeSuggestions = (
|
|||
})),
|
||||
];
|
||||
// return []; // <-- uncomment to disable suggestions (useful for debugging)
|
||||
return ls.map((state) => [score(state), inferType(state, env).type, state] as PrioritizedSuggestionType)
|
||||
return ls.map((state) => [score(state), inferTypeInput(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, typeInfo }: InputBlockProps) {
|
||||
const {text, focus} = state;
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const env = useContext(EnvContext);
|
||||
|
|
@ -133,8 +135,6 @@ export function InputBlock({ state, setState, score, onCancel }: InputBlockProps
|
|||
},
|
||||
};
|
||||
|
||||
const typeInfo = inferTypeInput(state, env);
|
||||
|
||||
return <><Input
|
||||
placeholder="<name or literal>"
|
||||
onCancel={onCancel}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue