mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-15 14:35:01 +03:00
finished keyedCompletions
This commit is contained in:
parent
0a0e4b2b1f
commit
0b32f2ae46
@ -31,6 +31,9 @@ join a = case a of
|
||||
map2 : (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c
|
||||
map2 f a b = pure f `ap` a `ap` b
|
||||
|
||||
map3 : (a -> b -> c -> d) -> Maybe a -> Maybe b -> Maybe c -> Maybe d
|
||||
map3 f a b c = pure f `ap` a `ap` b `ap` c
|
||||
|
||||
map : (a -> b) -> Maybe a -> Maybe b
|
||||
map f m = case m of
|
||||
Nothing -> Nothing
|
||||
|
@ -29,6 +29,8 @@ import Touch
|
||||
import Unison.Action as Action
|
||||
import Unison.Explorer as Explorer
|
||||
import Unison.Hash (Hash)
|
||||
import Unison.Reference (Reference)
|
||||
import Unison.Reference as Reference
|
||||
import Unison.Metadata (Metadata)
|
||||
import Unison.Metadata as Metadata
|
||||
import Unison.Node as Node
|
||||
@ -49,7 +51,8 @@ type alias Model =
|
||||
, scope : Scope.Model
|
||||
, localInfo : Maybe Node.LocalInfo
|
||||
, globalMatches : String -> Result (List Term) (List Term)
|
||||
, metadata : Dict Hash Metadata
|
||||
, rootMetadata : Metadata
|
||||
, metadata : Reference -> Metadata
|
||||
, availableWidth : Maybe Int
|
||||
, dependents : Trie Path.E (List Path)
|
||||
, overrides : Trie Path.E (Layout View.L)
|
||||
@ -60,12 +63,38 @@ type alias Model =
|
||||
, explorer : Layout (Result Containment Int) }
|
||||
, errors : List String }
|
||||
|
||||
viewEnv : Model -> View.Env
|
||||
viewEnv model =
|
||||
let explorerTopLeft : Pt
|
||||
explorerTopLeft = case panelHighlight model of
|
||||
Nothing -> Pt 0 0
|
||||
Just region -> { x = region.topLeft.x - 6, y = region.topLeft.y + region.height + 6 }
|
||||
in { rootMetadata = model.rootMetadata
|
||||
, metadata = model.metadata
|
||||
, availableWidth = (Maybe.withDefault 1000 model.availableWidth - explorerTopLeft.x - 12) `max` 40
|
||||
, overrides path = Trie.lookup path model.overrides
|
||||
, overall = model.term }
|
||||
|
||||
keyedCompletions : Model -> List (String,Term,Element)
|
||||
keyedCompletions model = Debug.crash "woot"
|
||||
-- let f e i = let search = e.input.string
|
||||
-- -- todo, use search string to filter wellTypedLocals
|
||||
-- in i.wellTypedLocals ++ Elmz.Result.merge (model.globalMatches search)
|
||||
-- in Maybe.withDefault [] (Elmz.Maybe.map2 f model.explorer model.localInfo)
|
||||
keyedCompletions model =
|
||||
let f e i scope =
|
||||
let search = e.input.string
|
||||
env = viewEnv model
|
||||
render term = Layout.element (View.layout term (viewEnv model))
|
||||
regulars = i.wellTypedLocals ++ Elmz.Result.merge (model.globalMatches search)
|
||||
key e = View.key { model | overall = model.term } { path = scope.focus, term = model.term }
|
||||
format e = (key e, e, render e)
|
||||
box = Term.Embed (Layout.embed { path = [], selectable = False } Styles.currentSymbol)
|
||||
appBlanks n e = if n <= 0 then e else appBlanks (n-1) (Term.App e Term.Blank)
|
||||
showAppBlanks n e =
|
||||
let go n e = if n <= 0 then e else go (n-1) (Term.App e box)
|
||||
in render (go n e)
|
||||
la cur n = (toString i, appBlanks n cur, showAppBlanks n cur)
|
||||
currentApps = case Term.at scope.focus model.term of
|
||||
Nothing -> []
|
||||
Just cur -> List.map (la cur) i.localApplications
|
||||
in List.map format regulars
|
||||
in Maybe.withDefault [] (Elmz.Maybe.map3 f model.explorer model.localInfo model.scope)
|
||||
|
||||
explorerValues : Model -> List Term
|
||||
explorerValues model =
|
||||
@ -103,7 +132,8 @@ model0 =
|
||||
, scope = Nothing
|
||||
, localInfo = Nothing
|
||||
, globalMatches s = Result.Err []
|
||||
, metadata = Dict.empty
|
||||
, rootMetadata = Metadata.anonymousTerm
|
||||
, metadata r = Metadata.anonymousTerm
|
||||
, availableWidth = Nothing
|
||||
, dependents = Trie.empty
|
||||
, overrides = Trie.empty
|
||||
|
@ -92,6 +92,9 @@ carotUp x c =
|
||||
|> E.height (ceiling (toFloat x * sqrt 2.0 / 2.0))
|
||||
|> E.above (E.spacer 1 13)
|
||||
|
||||
currentSymbol : Element
|
||||
currentSymbol = outline' okColor 8 16 16
|
||||
|
||||
numericLiteral : String -> Element
|
||||
numericLiteral s = T.leftAligned (T.style { code | color <- belizeHole } (T.fromString s))
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Unison.View (layout, L) where
|
||||
module Unison.View (Env, key, layout, L) where
|
||||
|
||||
import Array
|
||||
import Color
|
||||
@ -40,7 +40,9 @@ resolveLocal notfound md p e =
|
||||
in (boundAt p e `Maybe.andThen` Metadata.localSymbol md) |>
|
||||
Maybe.withDefault { sym | name <- notfound }
|
||||
|
||||
key : Env -> { path : Path, term : Term } -> String
|
||||
key : { tl | rootMetadata : Metadata, metadata : R.Reference -> Metadata, overall : Term }
|
||||
-> { path : Path, term : Term }
|
||||
-> String
|
||||
key env cur = case cur.term of
|
||||
Blank -> "_"
|
||||
Var v -> (resolveLocal ("v"++toString v) env.rootMetadata cur.path env.overall).name
|
||||
|
Loading…
Reference in New Issue
Block a user