Let ... in ... block autocomplete also sorted by best 'match', type-wise
This commit is contained in:
parent
2d81e42447
commit
8abbac4bc9
7 changed files with 66 additions and 43 deletions
29
src/eval.ts
29
src/eval.ts
|
|
@ -38,9 +38,7 @@ export const evalEditorBlock = (s: EditorState, env): ResolvedType => {
|
|||
return evalCallBlock(fn, input);
|
||||
}
|
||||
if (s.kind === "let") {
|
||||
const value = evalEditorBlock(s.value, env);
|
||||
const innerEnv = makeInnerEnv(env, s.name, value)
|
||||
return evalEditorBlock(s.inner, innerEnv);
|
||||
return evalLetInBlock(s.value, s.name, s.inner, env);
|
||||
}
|
||||
if (s.kind === "lambda") {
|
||||
const expr = evalEditorBlock(s.expr, env);
|
||||
|
|
@ -125,6 +123,12 @@ export function evalCallBlock(fn: ResolvedType, input: ResolvedType): ResolvedTy
|
|||
}
|
||||
}
|
||||
|
||||
export function evalLetInBlock(value: EditorState, name: string, inner: EditorState, env) {
|
||||
const valueResolved = evalEditorBlock(value, env);
|
||||
const innerEnv = makeInnerEnv(env, name, valueResolved)
|
||||
return evalEditorBlock(inner, innerEnv);
|
||||
}
|
||||
|
||||
export function haveValue(resolved: ResolvedType) {
|
||||
// return resolved && !(resolved instanceof DeepError);
|
||||
return resolved.kind === "value";
|
||||
|
|
@ -166,3 +170,22 @@ export function attemptParseLiteral(text: string): Dynamic[] {
|
|||
return literalParsers.map(parseFn => parseFn(text))
|
||||
.filter(resolved => (resolved.kind !== "unknown" && resolved.kind !== "error")) as unknown as Dynamic[];
|
||||
}
|
||||
|
||||
export function scoreResolved(resolved: ResolvedType, outPriority) {
|
||||
const bias = outPriority(['literal', '<computed>',
|
||||
// @ts-ignore: // TODO fix this
|
||||
{t: resolved.t}]);
|
||||
|
||||
if (resolved.kind === "value") {
|
||||
return 1 + bias;
|
||||
}
|
||||
else if (resolved.kind === "unknown") {
|
||||
return 0 + bias;
|
||||
}
|
||||
if (resolved.e instanceof UnifyError) {
|
||||
return -1 + bias; // parameter doesn't match
|
||||
}
|
||||
else {
|
||||
return -2 + bias; // even worse: fn is not a function!
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue