mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-23 16:28:02 +03:00
implemented search
This commit is contained in:
parent
a9359fd5dc
commit
e5c40aa0e7
@ -1,9 +1,9 @@
|
||||
module Unison.Node where
|
||||
|
||||
import Data.Set as S
|
||||
import Data.Text
|
||||
import Data.Map as M
|
||||
import Unison.Node.Panel
|
||||
import Unison.Node.Metadata as M
|
||||
import Unison.Node.Metadata as MD
|
||||
import Unison.Edit.Term.Action as A
|
||||
import Unison.Edit.Term.Path as P
|
||||
import Unison.Edit.Type.Path as TP
|
||||
@ -11,9 +11,9 @@ import Unison.Note as N
|
||||
|
||||
data Node m k t e = Node {
|
||||
-- | Create a new term and provide its metadata
|
||||
createTerm :: e -> M.Metadata k -> Noted m k,
|
||||
createTerm :: e -> MD.Metadata k -> Noted m k,
|
||||
-- | Create a new type and provide its metadata
|
||||
createType :: t -> M.Metadata k -> Noted m k,
|
||||
createType :: t -> MD.Metadata k -> Noted m k,
|
||||
-- | Lookup the direct dependencies of @k@, optionally limited to the given set
|
||||
dependencies :: Maybe (S.Set k) -> k -> Noted m (S.Set k),
|
||||
-- | Lookup the set of terms/types depending directly on the given @k@, optionally limited to the given set
|
||||
@ -23,11 +23,12 @@ data Node m k t e = Node {
|
||||
-- | Modify the given type, which may fail
|
||||
editType :: k -> P.Path -> A.Action t -> Noted m (k, t),
|
||||
-- | Access the metadata for the term or type identified by @k@
|
||||
metadata :: k -> Noted m (M.Metadata k),
|
||||
metadata :: k -> Noted m (MD.Metadata k),
|
||||
-- | Render the term or type identified by @k@ as a panel--
|
||||
panel :: k -> Noted m (Panel k t e),
|
||||
-- | Search for a term, optionally constrained to be of the given type
|
||||
search :: Maybe t -> Query -> Noted m [(k, Metadata k)],
|
||||
-- and contained in the given set
|
||||
search :: Maybe t -> (Maybe (S.Set k)) -> Query -> Noted m (Map k (Metadata k)),
|
||||
-- | Search for a term in local scope, optionally constrained to be of the given type
|
||||
searchLocal :: Maybe t -> Query -> Noted m [(e, Metadata k)],
|
||||
-- | Lookup the source of the term identified by @k@
|
||||
@ -43,13 +44,11 @@ data Node m k t e = Node {
|
||||
-- | Obtain the type of a constructor argument of a type
|
||||
typeOfConstructorArg :: k -> TP.Path -> Noted m t,
|
||||
-- | Update the metadata associated with the given term or type
|
||||
updateMetadata :: k -> M.Metadata k -> Noted m ()
|
||||
updateMetadata :: k -> MD.Metadata k -> Noted m ()
|
||||
|
||||
-- possibly later
|
||||
-- editConstructor :: k -> -> A.Action -> m (Either N.Note (k, t)), -- ^ Modify the given type, which may fail
|
||||
-- examples :: k -> m (Maybe [k]), -- ^
|
||||
}
|
||||
|
||||
data Query = Query Text
|
||||
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
module Unison.Node.Implementations.Common where
|
||||
|
||||
import Data.Map as M
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Set as S
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Unison.Node.Metadata as MD
|
||||
import qualified Unison.Type as Type
|
||||
import Unison.Syntax.Hash as H
|
||||
@ -48,35 +49,57 @@ node eval store =
|
||||
writeTypeOf store h t
|
||||
writeMetadata store h md
|
||||
pure h
|
||||
|
||||
createType t md = let h = T.finalizeHash t in do
|
||||
writeType store h t
|
||||
writeMetadata store h md
|
||||
pure h -- todo: kindchecking
|
||||
|
||||
dependencies limit h = let trim = maybe id S.intersection limit in do
|
||||
e <- readTerm store h
|
||||
pure $ trim (E.dependencies e)
|
||||
|
||||
dependents limit h = do
|
||||
hs <- hashes store limit
|
||||
hs' <- mapM (\h -> (,) h <$> dependencies Nothing h)
|
||||
(S.toList hs)
|
||||
pure $ S.fromList [x | (x,deps) <- hs', S.member h deps]
|
||||
|
||||
edit k path action = do
|
||||
e <- readTerm store k
|
||||
e' <- TE.apply eval path action e
|
||||
pure $ (E.finalizeHash e', e')
|
||||
|
||||
editType = error "todo later"
|
||||
|
||||
metadata = readMetadata store
|
||||
|
||||
panel = error "todo"
|
||||
search = error "todo"
|
||||
|
||||
search t limit query = do
|
||||
hs <- hashes store limit
|
||||
hs' <- case t of
|
||||
Nothing -> pure $ S.toList hs
|
||||
Just t -> filterM (\h -> flip Type.isSubtype t <$> readTypeOf store h) (S.toList hs)
|
||||
mds <- mapM (\h -> (,) h <$> metadata h) hs'
|
||||
pure . M.fromList . filter (\(_,md) -> MD.matches query md) $ mds
|
||||
|
||||
searchLocal = error "todo"
|
||||
|
||||
term = readTerm store
|
||||
|
||||
transitiveDependencies = error "todo"
|
||||
|
||||
transitiveDependents = error "todo"
|
||||
|
||||
typ = readType store
|
||||
|
||||
typeOf h p = case p of
|
||||
P.Path [] -> readTypeOf store h
|
||||
P.Path _ -> error "todo: typeOf"
|
||||
|
||||
typeOfConstructorArg = error "todo"
|
||||
|
||||
updateMetadata = writeMetadata store
|
||||
in N.Node
|
||||
createTerm
|
||||
|
@ -7,6 +7,12 @@ data Metadata k
|
||||
| Type Names [Names] k k -- ^ @Type names paramNames description kind
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
matches :: Query -> Metadata k -> Bool
|
||||
matches (Query txt) (Term (Names ns) _ _ _) = txt `elem` ns
|
||||
matches (Query txt) (Type (Names ns) _ _ _) = txt `elem` ns
|
||||
|
||||
data Names = Names [Text] deriving (Eq,Ord,Show,Read)
|
||||
|
||||
data Query = Query Text
|
||||
|
||||
-- data Examples k = Examples [(k, k)]
|
||||
|
@ -44,3 +44,8 @@ subtype :: T.Type -> T.Type -> Either Note T.Type
|
||||
subtype t1 t2 = case C.subtype (C.context []) t1 t2 of
|
||||
Left e -> Left e
|
||||
Right _ -> Right t2
|
||||
|
||||
isSubtype :: T.Type -> T.Type -> Bool
|
||||
isSubtype t1 t2 = case C.subtype (C.context []) t1 t2 of
|
||||
Left e -> False
|
||||
Right _ -> True
|
||||
|
Loading…
Reference in New Issue
Block a user