Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make hie-core outside an IDE work better #1895

Merged
merged 9 commits into from
Jun 26, 2019
Prev Previous commit
Next Next commit
Split the command line parsing into a separate module
  • Loading branch information
ndmitchell committed Jun 26, 2019
commit d3a464f0f5875729f4e685e1761a05cb09341e38
25 changes: 25 additions & 0 deletions compiler/hie-core/exe/Arguments.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

module Arguments(Arguments(..), getArguments) where

import Options.Applicative


data Arguments = Arguments
{argLSP :: Bool
,argFiles :: [FilePath]
}

getArguments :: IO Arguments
getArguments = execParser opts
where
opts = info (arguments <**> helper)
( fullDesc
<> progDesc "Used as a test bed to check your IDE will work"
<> header "hie-core - the core of a Haskell IDE")

arguments :: Parser Arguments
arguments = Arguments
<$> switch (long "lsp" <> help "Start talking to an LSP server")
<*> many (argument str (metavar "FILES..."))
7 changes: 4 additions & 3 deletions compiler/hie-core/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Main(main) where

import Arguments
import Data.Maybe
import Control.Concurrent.Extra
import Control.Monad
Expand Down Expand Up @@ -45,7 +46,7 @@ main = do
-- WARNING: If you write to stdout before runLanguageServer
-- then the language server will not work
hPutStrLn stderr "Starting hie-core Demo"
args <- getArgs
Arguments{..} <- getArguments
-- lock to avoid overlapping output on stdout
lock <- newLock
let logger = makeOneLogger $ withLock lock . T.putStrLn
Expand All @@ -57,13 +58,13 @@ main = do

let options = defaultIdeOptions $ liftIO $ newSession' cradle

if "--lsp" `elem` args then do
if argLSP then do
hPutStrLn stderr "Starting IDE server"
runLanguageServer def def $ \event vfs -> do
hPutStrLn stderr "Server started"
initialise (mainRule >> action kick) event logger options vfs
else do
let files = map toNormalizedFilePath $ filter (/= "--lsp") args
let files = map toNormalizedFilePath argFiles
vfs <- makeVFSHandle
ide <- initialise mainRule (showEvent lock) logger options vfs
setFilesOfInterest ide $ Set.fromList files
Expand Down
3 changes: 3 additions & 0 deletions compiler/hie-core/hie-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ executable hie-core
base == 4.*,
containers,
directory,
optparse-applicative,
hie-bios,
shake,
data-default,
Expand All @@ -118,6 +119,8 @@ executable hie-core
haskell-lsp,
text,
hie-core
other-modules:
Arguments

default-extensions:
TupleSections
Expand Down