diff --git a/editor/src/Unison/Editor.elm b/editor/src/Unison/Editor.elm index 4ab28954a..ef12379e7 100644 --- a/editor/src/Unison/Editor.elm +++ b/editor/src/Unison/Editor.elm @@ -417,7 +417,7 @@ search2 searchbox reqs = _ -> Nothing openEdit' = let go oe model = List.head [] - in Signal.map openEdit reqs |> JR.send (Node.openEdit host `JR.to` go) + in Signal.map openEdit reqs |> JR.send (Node.localInfo host `JR.to` go) search r = case r of Search typ query -> Just (typ,query) _ -> Nothing diff --git a/editor/src/Unison/Node.elm b/editor/src/Unison/Node.elm index fbeff0484..5464de5fc 100644 --- a/editor/src/Unison/Node.elm +++ b/editor/src/Unison/Node.elm @@ -67,11 +67,6 @@ editType host = Request.post host "edit-type" (Encoder.tuple3 Path.encodePath A.encode T.encodeType) T.decodeType -metadatas : Host -> Request (List Hash) (M.Dict Hash Metadata) -metadatas host = Request.post host "metadatas" - (Encoder.list H.encode) - (Decoder.object MD.decodeMetadata) - type alias LocalInfo = { current : Type , admissible : Type @@ -79,8 +74,8 @@ type alias LocalInfo = , localApplications : List Int , wellTypedLocals : List Term } -openEdit : Host -> Request (Term, Path) LocalInfo -openEdit host = Request.post host "open-edit" +localInfo : Host -> Request (Term, Path) LocalInfo +localInfo host = Request.post host "local-info" (Encoder.tuple2 E.encodeTerm Path.encodePath) (Decoder.product5 LocalInfo T.decodeType @@ -89,6 +84,11 @@ openEdit host = Request.post host "open-edit" (Decoder.list Decoder.int) (Decoder.list E.decodeTerm)) +metadatas : Host -> Request (List Hash) (M.Dict Hash Metadata) +metadatas host = Request.post host "metadatas" + (Encoder.list H.encode) + (Decoder.object MD.decodeMetadata) + search : Host -> Request (Maybe Type, Query) (List Term) search host = Request.post host "search" (Encoder.tuple2 (Encoder.optional T.encodeType) MD.encodeQuery) diff --git a/node/src/Unison/Node.hs b/node/src/Unison/Node.hs index 8560828b5..cec306d0d 100644 --- a/node/src/Unison/Node.hs +++ b/node/src/Unison/Node.hs @@ -23,15 +23,14 @@ data Node m k t e = Node { editTerm :: P.Path -> A.Action -> e -> Noted m e, -- | Modify the given type, which may fail editType :: P.Path -> A.Action -> t -> Noted m t, + -- | Returns ( current type + -- , admissible type + -- , local vars + -- , well-typed applications of focus + -- , well-typed expressions involving local vars ) + localInfo :: e -> P.Path -> Noted m (t, t, [e], [Int], [e]), -- | Access the metadata for the term and/or types identified by @k@ metadatas :: [k] -> Noted m (Map k (MD.Metadata k)), - -- | Open the given location for editing; - -- returns ( current type - -- , admissible type - -- , local vars - -- , well-typed applications of focus - -- , well-typed expressions involving local vars ) - openEdit :: e -> P.Path -> Noted m (t, t, [e], [Int], [e]), -- | Search for a term, optionally constrained to be of the given type search :: Maybe t -> Query -> Noted m [e], -- | Lookup the source of the term identified by @k@ diff --git a/node/src/Unison/Node/Common.hs b/node/src/Unison/Node/Common.hs index 4dee120f4..5275614f5 100644 --- a/node/src/Unison/Node/Common.hs +++ b/node/src/Unison/Node/Common.hs @@ -71,7 +71,7 @@ node eval store = metadatas hs = M.fromList <$> sequence (map (\h -> (,) h <$> readMetadata store h) hs) - openEdit e loc = do + localInfo e loc = do current <- TE.typeOf readTypeOf loc e admissible <- TE.admissibleTypeOf readTypeOf loc e locals <- TE.locals readTypeOf loc e @@ -121,8 +121,8 @@ node eval store = dependents edit editType + localInfo metadatas - openEdit search terms transitiveDependencies diff --git a/node/src/Unison/Node/Server.hs b/node/src/Unison/Node/Server.hs index feb4447c8..bdbaba267 100644 --- a/node/src/Unison/Node/Server.hs +++ b/node/src/Unison/Node/Server.hs @@ -54,80 +54,81 @@ originOptions = do route :: ActionM () -> ActionM () route action = do originPolicy - body <- S.body - liftIO (putStrLn ("request body\n" ++ show body)) action +postRoute :: S.RoutePattern -> ActionM () -> S.ScottyM () +postRoute s action = S.post s (route action) + server :: Int -> Node IO Reference T.Type E.Term -> IO () server port node = S.scotty port $ do S.addroute OPTIONS (S.regex ".*") $ originOptions - S.post "/admissible-type-of" . route $ do + postRoute "/admissible-type-of" $ do (h, path) <- S.jsonData t <- runN $ N.admissibleTypeOf node h path S.json t - S.post "/create-term" $ do + postRoute "/create-term" $ do (e, md) <- S.jsonData k <- runN $ N.createTerm node e md S.json k - S.post "/create-type" $ do + postRoute "/create-type" $ do (t, md) <- S.jsonData k <- runN $ N.createType node t md S.json k - S.get "/dependencies" $ do + postRoute "/dependencies" $ do (limit, h) <- S.jsonData k <- runN $ N.dependencies node limit h S.json k - S.get "/dependents" $ do + postRoute "/dependents" $ do (limit, h) <- S.jsonData k <- runN $ N.dependents node limit h S.json k - S.get "/edit-term" $ do -- this merely computes the new term, hence a GET + postRoute "/edit-term" $ do -- this merely computes the new term, hence a GET (loc, a, e) <- S.jsonData e <- runN $ N.editTerm node loc a e S.json e -- we might follow this up with a 'create-term', which is a POST - S.get "/edit-type" $ do -- this merely computes the new type and its hash, hence a GET! + postRoute "/edit-type" $ do -- this merely computes the new type and its hash, hence a GET! (loc, a, t) <- S.jsonData t <- runN $ N.editType node loc a t S.json t - S.get "/metadatas" $ do + postRoute "/local-info" $ do + (e, path) <- S.jsonData + t <- runN $ N.localInfo node e path + S.json t + postRoute "/metadatas" $ do hs <- S.jsonData md <- runN $ N.metadatas node hs S.json md - S.post "/open-edit" . route $ do - (e, path) <- S.jsonData - t <- runN $ N.openEdit node e path - S.json t - S.get "/search" $ do + postRoute "/search" $ do (t,q) <- S.jsonData es <- runN $ N.search node t q S.json es - S.get "/terms" $ do + postRoute "/terms" $ do hs <- S.jsonData r <- runN $ N.terms node hs S.json r - S.get "/transitive-dependencies" $ do + postRoute "/transitive-dependencies" $ do (limit,h) <- S.jsonData s <- runN $ N.transitiveDependencies node limit h S.json s - S.get "/transitive-dependents" $ do + postRoute "/transitive-dependents" $ do (limit,h) <- S.jsonData s <- runN $ N.transitiveDependents node limit h S.json s - S.get "/types" $ do + postRoute "/types" $ do hs <- S.jsonData ts <- runN $ N.types node hs S.json ts - S.post "/type-of" . route $ do + postRoute "/type-of" . route $ do (h,loc) <- S.jsonData s <- runN $ N.typeOf node h loc S.json s - S.post "/update-metadata" $ do + postRoute "/update-metadata" $ do (h,md) <- S.jsonData s <- runN $ N.updateMetadata node h md S.json s S.defaultHandler $ \msg -> originPolicy *> S.raise msg {- - S.get "/type-of-constructor-argument" $ do + postRoute "/type-of-constructor-argument" $ do (h,loc) <- S.jsonData s <- runN $ N.typeOf node h loc S.json s