Skip to content

Commit 85d2c1d

Browse files
committed
WIP: Add IDE process
1 parent a989a85 commit 85d2c1d

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

server/Main.hs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Data.Aeson ((.=))
2020
import Data.Bifunctor (first, second, bimap)
2121
import qualified Data.ByteString.Lazy as BL
2222
import Data.Default (def)
23-
import Data.Function (on)
23+
import Data.Function (on, fix)
2424
import qualified Data.IORef as IORef
2525
import Data.List (nubBy)
2626
import qualified Data.List.NonEmpty as NE
@@ -43,10 +43,12 @@ import qualified Language.PureScript.Make as Make
4343
import qualified Language.PureScript.Make.Cache as Cache
4444
import qualified Language.PureScript.TypeChecker.TypeSearch as TS
4545
import qualified Network.Wai.Handler.Warp as Warp
46+
import qualified System.Directory as Directory
4647
import System.Environment (getArgs)
4748
import System.Exit (exitFailure)
4849
import System.FilePath.Glob (glob)
4950
import qualified System.IO as IO
51+
import qualified System.Process as Process
5052
import Web.Scotty
5153
import qualified Web.Scotty as Scotty
5254

@@ -113,6 +115,54 @@ buildMakeActions codegenRef =
113115
outputPrimDocs :: Make.Make ()
114116
outputPrimDocs = pure ()
115117

118+
exampleQuery str = "\
119+
\{ \"command\": \"complete\",\
120+
\\"currentModule\": \"Main\",\
121+
\\"matcher\": {\
122+
\\"matcher\": \"flex\",\
123+
\\"params\": {\
124+
\\"search\": \"" <> str <> "\",\
125+
\\"maxResults\": 10\
126+
\}\
127+
\},\
128+
\\"params\": {\
129+
\\"filters\": [{\
130+
\\"filter\": \"prefix\",\
131+
\\"params\": {\
132+
\\"search\": \"" <> str <> "\"\
133+
\}\
134+
\}],\
135+
\\"options\": {\
136+
\\"maxResults\": 20,\
137+
\\"groupReexports\": true\
138+
\}\
139+
\}\
140+
\}\
141+
\"
142+
143+
ideProcess :: IO ()
144+
ideProcess = do
145+
currentDirectory <- Directory.getCurrentDirectory
146+
let ideServer =
147+
(Process.proc "purs" ["ide", "server"])
148+
{ Process.cwd = Just (currentDirectory <> "/staging")
149+
}
150+
ideClient =
151+
Process.createProcess_ "purs-ide-client"
152+
(Process.proc "purs" ["ide", "client"])
153+
{ Process.std_in = Process.CreatePipe
154+
, Process.std_out = Process.CreatePipe
155+
}
156+
Process.withCreateProcess ideServer $
157+
\_ _ _ _ -> fix $ \loop -> do
158+
getLine >>= \case
159+
"STOP" -> pure ()
160+
arg -> do
161+
(Just handleIn, Just handleOut, _, _) <- ideClient
162+
IO.hPutStrLn handleIn (exampleQuery arg)
163+
IO.hGetContents handleOut >>= putStrLn
164+
loop
165+
116166
server :: [P.ExternsFile] -> P.Env -> P.Environment -> Int -> IO ()
117167
server externs initNamesEnv initEnv port = do
118168
codegenRef <- IORef.newIORef Nothing

stack.yaml.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55

66
packages:
77
- completed:
8-
hackage: purescript-0.14.3@sha256:4b75604e86c335711e1b1f1f73ef381108d047c9277df1cdc71922ec7da7c181,18623
8+
hackage: purescript-0.14.5@sha256:511f50e7f267b65e1f656cdff9f9665073496efdf4375a3a86aa68496dae7281,18623
99
pantry-tree:
10-
size: 132222
11-
sha256: e3957c9d2c96434fcf5e8f310b34f4ea696cc8e5f63e60958eae5c6e31aba4c6
10+
size: 121096
11+
sha256: 895dfc2fc938d99930f4ad17d1c475baf59efb4ad0c64519dfd09e482db38ff3
1212
original:
13-
hackage: purescript-0.14.3
13+
hackage: purescript-0.14.5
1414
- completed:
15-
hackage: purescript-cst-0.3.0.0@sha256:369317d52737c4fa8c74a875283ed6cc0ef68e7c64db13d6e5bb7a7f72b76572,3861
15+
hackage: purescript-cst-0.4.0.0@sha256:bfe7be3962e83b645a4a8cd1805f31de17db3d3456962e1a2d17016fe5d7f96d,3861
1616
pantry-tree:
1717
size: 3018
18-
sha256: 38f94bcc121068215c6082bab39b6c555cadd3b88e786740c394a5c4b98c4100
18+
sha256: 1681432cc9fa87bc6344e7c604f94a15a016af6e4b7c3519ee035f0f51d90c9c
1919
original:
20-
hackage: purescript-cst-0.3.0.0
20+
hackage: purescript-cst-0.4.0.0
2121
- completed:
2222
hackage: language-javascript-0.7.0.0@sha256:3eab0262b8ac5621936a4beab6a0f97d0e00a63455a8b0e3ac1547b4088dae7d,3898
2323
pantry-tree:

trypurescript.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ executable trypurescript
3232
http-types -any,
3333
transformers -any,
3434
mtl -any,
35+
process -any,
3536
text -any,
3637
time -any,
3738
warp -any

0 commit comments

Comments
 (0)