Skip to content
This repository was archived by the owner on Feb 1, 2019. It is now read-only.

Commit f3242f1

Browse files
committed
Evaluate Haskell code on the server.
1 parent c38b39b commit f3242f1

File tree

5 files changed

+133
-246
lines changed

5 files changed

+133
-246
lines changed

haskell.behaviors

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
:lt.plugins.haskell/editor-reformat-result
1212
:lt.plugins.haskell/editor-syntax-result
1313
:lt.plugins.haskell/editor-lint-result
14+
1415
:lt.plugins.haskell/on-eval-one
16+
:lt.plugins.haskell/haskell-result
17+
:lt.plugins.haskell/haskell-exception
1518
:lt.plugins.haskell/on-eval-type
1619

1720
[:lt.object/add-tag :docable]

haskell/LTHaskellClient.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import System.Exit (exitSuccess)
99
import System.IO (Handle, hClose, hFlush, hGetLine,
1010
hPutStrLn, stderr, stdout)
1111

12-
import Control.Applicative ((<$>))
12+
import Control.Applicative ((<$>), (<*>))
1313

1414
import Data.Aeson (FromJSON (..), ToJSON (..),
1515
Value (..), eitherDecode, encode,
16-
object, (.:), (.=))
16+
object, (.:), (.:?), (.=), (.!=))
1717
import qualified Data.ByteString.Lazy.Char8 as BS
1818

1919
import GHC.Generics (Generic)
@@ -73,7 +73,7 @@ execCommand state (LTCommand (cId, command, Just ltPayload)) =
7373
where
7474
go "haskell.api.reformat" payloadData = do
7575
reformattedCode <- format payloadData
76-
respond "editor.haskell.reformat.result" $ LTPayload reformattedCode
76+
respond "editor.haskell.reformat.result" $ LTPayload reformattedCode 0
7777

7878
go "haskell.api.syntax" payloadData = do
7979
syntaxIssues <- getSyntaxIssues payloadData
@@ -85,9 +85,10 @@ execCommand state (LTCommand (cId, command, Just ltPayload)) =
8585

8686
go "haskell.api.eval" payloadData = do
8787
result <- evalInSession payloadData $ ltReplSession state
88+
let line = ltLine ltPayload
8889
case result of
89-
Left msg -> respond "editor.eval.haskell.exception" $ LTPayload msg
90-
Right msg -> respond "editor.evak.haskell.success" $ LTPayload msg
90+
Left msg -> respond "editor.eval.haskell.exception" $ LTPayload msg line
91+
Right msg -> respond "editor.eval.haskell.result" $ LTPayload msg line
9192

9293
respond :: (ToJSON a) => Command -> a -> IO ()
9394
respond respCommand respPayload = sendResponse (ltHandle state) $ LTCommand (cId, respCommand, respPayload)
@@ -101,12 +102,12 @@ data LTCommand a = LTCommand (Client, Command, a) deriving (Show, Generic)
101102
instance (FromJSON a) => FromJSON (LTCommand a)
102103
instance (ToJSON a) => ToJSON (LTCommand a)
103104

104-
data LTPayload = LTPayload { ltData :: String } deriving (Show)
105+
data LTPayload = LTPayload { ltData :: String, ltLine :: Int } deriving (Show)
105106
instance FromJSON LTPayload where
106-
parseJSON (Object v) = LTPayload <$> v .: "data"
107+
parseJSON (Object v) = LTPayload <$> v .: "data" <*> (v .:? "line" .!= 0)
107108

108109
instance ToJSON LTPayload where
109-
toJSON payload = object [ "data" .= ltData payload ]
110+
toJSON payload = object [ "data" .= ltData payload, "line" .= ltLine payload ]
110111

111112
data LTArrayPayload = LTArrayPayload { ltDataArray :: [String] } deriving (Show)
112113
instance FromJSON LTArrayPayload where

0 commit comments

Comments
 (0)