Skip to content

Commit

Permalink
Merge branch 'main' into nitin/keyword-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 18, 2024
2 parents f8fb449 + de12501 commit 90b0386
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/swarm-lang/Swarm/Language/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,22 @@ prettyTypeErr :: Text -> ContextualTypeErr -> Doc ann
prettyTypeErr code (CTE l tcStack te) =
vcat
[ teLoc <> ppr te
, ppr (BulletList "" tcStack)
, ppr (BulletList "" (filterTCStack tcStack))
]
where
teLoc = case l of
SrcLoc s e -> (showLoc . fst $ getLocRange code (s, e)) <> ": "
NoLoc -> emptyDoc
showLoc (r, c) = pretty r <> ":" <> pretty c

-- | Filter the TCStack of extravagant Binds.
filterTCStack :: TCStack -> TCStack
filterTCStack tcStack = case tcStack of
[] -> []
t@(LocatedTCFrame _ (TCDef _)) : _ -> [t]
t@(LocatedTCFrame _ TCBindR) : xs -> t : filterTCStack xs
t@(LocatedTCFrame _ TCBindL) : xs -> t : filterTCStack xs

instance PrettyPrec TypeErr where
prettyPrec _ = \case
UnificationErr ue -> ppr ue
Expand Down
17 changes: 15 additions & 2 deletions src/swarm-tui/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ module Swarm.TUI.Controller (
import Brick hiding (Direction, Location)
import Brick.Focus
import Brick.Widgets.Dialog
import Brick.Widgets.Edit (applyEdit, handleEditorEvent)
import Brick.Widgets.Edit (Editor, applyEdit, handleEditorEvent)
import Brick.Widgets.List (handleListEvent)
import Brick.Widgets.List qualified as BL
import Control.Applicative (liftA2, pure)
import Control.Carrier.Lift qualified as Fused
import Control.Carrier.State.Lazy qualified as Fused
import Control.Category ((>>>))
import Control.Lens as Lens
import Control.Lens.Extras as Lens (is)
import Control.Monad (forM_, unless, void, when)
Expand All @@ -66,6 +67,7 @@ import Data.String (fromString)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.IO qualified as T
import Data.Text.Zipper qualified as TZ
import Data.Text.Zipper.Generic.Words qualified as TZ
import Data.Time (getZonedTime)
import Data.Vector qualified as V
Expand Down Expand Up @@ -1206,12 +1208,23 @@ handleREPLEventTyping = \case
uiState . uiGameplay . uiREPL . replPromptEditor %= applyEdit TZ.deletePrevWord
-- finally if none match pass the event to the editor
ev -> do
Brick.zoom (uiState . uiGameplay . uiREPL . replPromptEditor) (handleEditorEvent ev)
Brick.zoom (uiState . uiGameplay . uiREPL . replPromptEditor) $ case ev of
CharKey c | c `elem` ("([{" :: String) -> insertMatchingPair c
_ -> handleEditorEvent ev
uiState . uiGameplay . uiREPL . replPromptType %= \case
CmdPrompt _ -> CmdPrompt [] -- reset completions on any event passed to editor
SearchPrompt a -> SearchPrompt a
modify validateREPLForm

insertMatchingPair :: Char -> EventM Name (Editor Text Name) ()
insertMatchingPair c = modify . applyEdit $ TZ.insertChar c >>> TZ.insertChar (close c) >>> TZ.moveLeft
where
close = \case
'(' -> ')'
'[' -> ']'
'{' -> '}'
_ -> c

data CompletionType
= FunctionName
| EntityName
Expand Down
14 changes: 12 additions & 2 deletions test/unit/TestLanguagePipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,24 @@ testLanguagePipeline =
"1:1: Undefined type U"
)
]
, testCase
"Stop printing context after a definition. - #1336"
( processCompare
(==)
"move; def x = move; say 3 end; move;"
"1:25: Type mismatch:\n From context, expected `3` to have type `Text`,\n but it actually has type `Int`\n\n - While checking the right-hand side of a semicolon\n - While checking the definition of x"
)
]
where
valid = flip process ""

process :: Text -> Text -> Assertion
process code expect = case processTerm code of
process = processCompare T.isPrefixOf

processCompare :: (Text -> Text -> Bool) -> Text -> Text -> Assertion
processCompare cmp code expect = case processTerm code of
Left e
| not (T.null expect) && expect `T.isPrefixOf` e -> pure ()
| not (T.null expect) && cmp expect e -> pure ()
| otherwise ->
error $
"Unexpected failure:\n\n " <> show e <> "\n\nExpected:\n\n " <> show expect <> "\n"
Expand Down

0 comments on commit 90b0386

Please sign in to comment.