forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLsp.hs
More file actions
48 lines (42 loc) · 1.42 KB
/
Lsp.hs
File metadata and controls
48 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Command.Lsp (command) where
import Language.PureScript.Lsp as Lsp
import Language.PureScript.Lsp.Types (mkEnv)
import Options.Applicative qualified as Opts
import Protolude
import System.Directory (setCurrentDirectory)
data ServerOptions = ServerOptions
{ _serverDirectory :: Maybe FilePath,
_serverOutputPath :: FilePath
}
deriving (Show)
command :: Opts.Parser (IO ())
command = Opts.helper <*> subcommands
where
subcommands :: Opts.Parser (IO ())
subcommands =
(Opts.subparser . fold)
[ Opts.command
"server"
( Opts.info
(fmap server serverOptions <**> Opts.helper)
(Opts.progDesc "Start a server LSP process")
)
]
server :: ServerOptions -> IO ()
server (ServerOptions dir outputPath) = do
maybe (pure ()) setCurrentDirectory dir
putErrLn $ "Starting server with output path: " <> outputPath
env <- mkEnv outputPath
startServer outputPath env
serverOptions :: Opts.Parser ServerOptions
serverOptions =
ServerOptions
<$> optional (Opts.strOption (Opts.long "directory" `mappend` Opts.short 'd'))
<*> Opts.strOption (Opts.long "output-directory" `mappend` Opts.value "output/")
startServer outputPath env = do
code <- Lsp.main outputPath env
exitWith
( case code of
0 -> ExitSuccess
_ -> ExitFailure code
)