fix suggestion order
This commit is contained in:
parent
46baad7cf4
commit
1ff4b181ff
8 changed files with 91 additions and 168 deletions
|
|
@ -3,7 +3,7 @@ import { memo, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|||
import { getType, prettyT, trie } from "dope2";
|
||||
|
||||
import { EnvContext } from "./EnvContext";
|
||||
import type { Dynamic } from "./eval";
|
||||
import type { Dynamic, ResolvedType } from "./eval";
|
||||
import "./InputBlock.css";
|
||||
import { Type } from "./Type";
|
||||
import type { State2Props } from "./Editor";
|
||||
|
|
@ -33,11 +33,10 @@ export type SuggestionType = ['literal'|'name', string, Dynamic];
|
|||
export type PrioritizedSuggestionType = [number, ...SuggestionType];
|
||||
|
||||
interface InputBlockProps extends State2Props<InputBlockState> {
|
||||
suggestionPriority: (suggestion: SuggestionType) => number;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
const computeSuggestions = (text, env, suggestionPriority: (s: SuggestionType) => number): PrioritizedSuggestionType[] => {
|
||||
const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) => number): PrioritizedSuggestionType[] => {
|
||||
const literals = attemptParseLiteral(text, env);
|
||||
|
||||
const ls: SuggestionType[] = [
|
||||
|
|
@ -46,11 +45,17 @@ const computeSuggestions = (text, env, suggestionPriority: (s: SuggestionType) =
|
|||
|
||||
// names
|
||||
... trie.suggest(env.name2dyn)(text)(Infinity)
|
||||
.map(([name,type]) => ["name", name, {...type, substitutions: new Map()}]),
|
||||
.map(([name,type]) => [
|
||||
"name",
|
||||
name, {
|
||||
...type,
|
||||
substitutions: type.substitutions || new Map(),
|
||||
kind: type.kind || "value",
|
||||
}]),
|
||||
]
|
||||
// return ls;
|
||||
return ls
|
||||
.map(suggestion => [suggestionPriority(suggestion), ...suggestion] as PrioritizedSuggestionType)
|
||||
.map(suggestion => [suggestionPriority(suggestion[2]), ...suggestion] as PrioritizedSuggestionType)
|
||||
.sort(([priorityA], [priorityB]) => priorityB - priorityA)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue