Skip to content

Commit 57d45f7

Browse files
authored
[ git ] Merge pull request #40 from agda-web/raw-responses
Add a CLI option to let the server respond in JSON-interaction style
2 parents df311b2 + 1c76bbf commit 57d45f7

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

.gitmodules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
[submodule "wasm-submodules/agda"]
66
path = wasm-submodules/agda
7-
url = [email protected]:agda-web/agda.git
7+
url = https://github.com/agda-web/agda
8+
branch = agda-web/release-v2.8.0

src/Agda.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ import GHC.Generics ( Generic )
8888
import Language.LSP.Server ( getConfig )
8989
import Monad
9090
import Options ( Config(configRawAgdaOptions)
91-
, Options(optRawAgdaOptions)
91+
, Options(optRawAgdaOptions, optRawResponses)
9292
, versionNumber
9393
)
9494

95+
import qualified Agda.IR as IR
96+
import Agda.Interaction.JSON ( encode, encodeTCM )
97+
import Agda.Interaction.JSONTop ()
98+
9599
getAgdaVersion :: String
96100
getAgdaVersion = versionWithCommitInfo
97101

@@ -104,8 +108,14 @@ start = do
104108
result <- runAgda $ do
105109
-- decides how to output Response
106110
lift $ setInteractionOutputCallback $ \response -> do
107-
reaction <- fromResponse response
108-
sendResponse env reaction
111+
resp <- if optRawResponses (envOptions env)
112+
then do
113+
value <- (pure . encodeTCM) response
114+
resp' <- fmap IR.ResponseJSONRaw value
115+
return resp'
116+
else fromResponse response
117+
118+
sendResponse env resp
109119

110120
-- keep reading command
111121
commands <- liftIO $ initialiseCommandQueue (readCommand env)

src/Agda/IR.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ data Response
4444
| ResponseMimer Int (Maybe String)
4545
| -- priority: 3
4646
ResponseJumpToError FilePath Int
47+
| -- raw form
48+
ResponseJSONRaw Value
4749
| ResponseEnd
4850
deriving (Generic)
4951

src/Options.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ usageMessage = usageInfo usage options ++ usageAboutAgdaOptions
3939
data Options = Options
4040
{ optViaTCP :: Maybe Int,
4141
optRawAgdaOptions :: [String],
42+
optRawResponses :: Bool,
4243
optSetup :: Bool,
4344
optHelp :: Bool,
4445
optVersion :: Bool
4546
}
4647

4748
defaultOptions :: Options
4849
defaultOptions =
49-
Options {optViaTCP = Nothing, optRawAgdaOptions = [], optSetup = False, optHelp = False, optVersion = False}
50+
Options {optViaTCP = Nothing, optRawAgdaOptions = [], optRawResponses = False, optSetup = False, optHelp = False, optVersion = False}
5051

5152
options :: [OptDescr (Options -> Options)]
5253
options =
@@ -66,6 +67,11 @@ options =
6667
"PORT"
6768
)
6869
"talk with the editor via TCP port (4096 as default)",
70+
Option
71+
[]
72+
["raw"]
73+
(NoArg (\opts -> opts {optRawResponses = True}))
74+
"return all responses in raw JSON format",
6975
#if MIN_VERSION_Agda(2,8,0)
7076
Option
7177
[]

wasm-submodules/agda

Submodule agda updated 2988 files

0 commit comments

Comments
 (0)