diff --git a/editor/src/Unison/Editor.elm b/editor/src/Unison/Editor.elm index 53c751cfc..23bec2b30 100644 --- a/editor/src/Unison/Editor.elm +++ b/editor/src/Unison/Editor.elm @@ -419,7 +419,7 @@ setSearchbox sink origin modifier content model = req = if ok then Nothing else case model'.localInfo of Nothing -> Nothing - Just info -> Just (Search 10 + Just info -> Just (Search 5 (Just info.admissible) (Metadata.Query content.string)) in (req, refreshExplorer sink model') @@ -616,7 +616,7 @@ search2 searchbox origin reqs = openEdit' = let mkreq model info = case model.searchResults of Just _ -> Nothing - Nothing -> Just (Search 10 (Just info.admissible) + Nothing -> Just (Search 5 (Just info.admissible) (Metadata.Query (explorerInput model))) go info model = ( mkreq model info diff --git a/node/src/Node.hs b/node/src/Node.hs index f30e513f3..8ce7820b5 100644 --- a/node/src/Node.hs +++ b/node/src/Node.hs @@ -4,6 +4,8 @@ module Main where import Control.Applicative +import Data.Monoid +import Data.Text (Text) import Unison.Edit.Term.Eval (Eval) import Unison.Node (Node) import qualified Unison.Node as Node @@ -35,32 +37,48 @@ numeric2 sym f = I.Primop 2 $ \xs -> case xs of (x,y) -> sym `Term.App` x `Term.App` y _ -> error "unpossible" +string2 :: Term -> (Text -> Text -> Text) -> I.Primop (N.Noted IO) +string2 sym f = I.Primop 2 $ \xs -> case xs of + [x,y] -> do + xr <- whnf x + yr <- whnf y + pure $ case (xr, yr) of + (Term.Lit (Term.String x), Term.Lit (Term.String y)) -> Term.Lit (Term.String (f x y)) + (x,y) -> sym `Term.App` x `Term.App` y + _ -> error "unpossible" + builtins :: [(R.Reference, I.Primop (N.Noted IO), Type)] builtins = [ let r = R.Builtin "Number.plus" in (r, numeric2 (Term.Ref r) (+), t) , let r = R.Builtin "Number.minus" in (r, numeric2 (Term.Ref r) (-), t) , let r = R.Builtin "Number.times" in (r, numeric2 (Term.Ref r) (*), t) - , let r = R.Builtin "Number.divide" in (r, numeric2 (Term.Ref r) (/), t) ] + , let r = R.Builtin "Number.divide" in (r, numeric2 (Term.Ref r) (/), t) + , let r = R.Builtin "Text.append" in (r, string2 (Term.Ref r) mappend, st) ] where t = numopTyp + st = strOpTyp +str = Type.Unit Type.String num = Type.Unit Type.Number arr = Type.Arrow numopTyp = num `arr` (num `arr` num) +strOpTyp = str `arr` (str `arr` str) builtinMetadatas :: Node IO R.Reference Type Term -> N.Noted IO () builtinMetadatas node = do - Node.updateMetadata node (R.Builtin "Number.plus") (md 4 "+") - Node.updateMetadata node (R.Builtin "Number.minus") (md 4 "-") - Node.updateMetadata node (R.Builtin "Number.times") (md 5 "*") - Node.updateMetadata node (R.Builtin "Number.divide") (md 5 "/") - Store.annotateTerm store (R.Builtin "Number.plus") numopTyp - Store.annotateTerm store (R.Builtin "Number.minus") numopTyp - Store.annotateTerm store (R.Builtin "Number.times") numopTyp - Store.annotateTerm store (R.Builtin "Number.divide") numopTyp - where md n s = Metadata Metadata.Term - (Metadata.Names [Metadata.Symbol s Metadata.InfixL n ]) - [] - Nothing + Node.updateMetadata node (R.Builtin "Number.plus") (opl 4 "+") + Node.updateMetadata node (R.Builtin "Number.minus") (opl 4 "-") + Node.updateMetadata node (R.Builtin "Number.times") (opl 5 "*") + Node.updateMetadata node (R.Builtin "Number.divide") (opl 5 "/") + Node.updateMetadata node (R.Builtin "Text.append") (opp "append") + mapM_ (\(r,_,t) -> Store.annotateTerm store r t) builtins + where opl n s = Metadata Metadata.Term + (Metadata.Names [Metadata.Symbol s Metadata.InfixL n ]) + [] + Nothing + opp s = Metadata Metadata.Term + (Metadata.Names [Metadata.Symbol s Metadata.Prefix 9]) + [] + Nothing store :: Store IO store = F.store "store" diff --git a/node/src/Unison/Node/Common.hs b/node/src/Unison/Node/Common.hs index c07662374..5a332d5d5 100644 --- a/node/src/Unison/Node/Common.hs +++ b/node/src/Unison/Node/Common.hs @@ -88,7 +88,7 @@ node eval store = let trim rs = (take limit rs, length (drop limit rs)) hs <- hashes store Nothing tmatches <- do es <- traverse elaborate (S.toList hs) - filterM typeOk (join es) + filterM typeOk (join (take limit es)) qmatches <- filterM queryOk tmatches qmatches' <- filterM queryOk (map E.Ref (S.toList hs)) illtypedQmatches <- @@ -99,7 +99,7 @@ node eval store = (S.toList (S.unions (map E.dependencies' qmatches))) pure $ SearchResults mds - (trim qmatches) + (qmatches, length (drop limit qmatches)) (trim illtypedQmatches) (MD.queryPositions query) diff --git a/node/unison.cabal b/node/unison.cabal index ec4e997c5..f05980d94 100644 --- a/node/unison.cabal +++ b/node/unison.cabal @@ -126,6 +126,7 @@ executable node build-depends: unison, + text, containers, base