-
Notifications
You must be signed in to change notification settings - Fork 205
Deduplicate main for hie/hie-wrapper #1610
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
{-# LANGUAGE CPP #-} | ||
module Haskell.Ide.Engine.Options where | ||
|
||
#if __GLASGOW_HASKELL__ < 804 | ||
import Data.Semigroup | ||
#endif | ||
#if __GLASGOW_HASKELL__ < 808 | ||
import Data.Monoid ((<>)) | ||
#endif | ||
import Data.Version (showVersion) | ||
import Haskell.Ide.Engine.Version | ||
import qualified Language.Haskell.LSP.Core as Core | ||
import Options.Applicative.Simple | ||
import qualified Paths_haskell_ide_engine as Meta | ||
import System.Directory | ||
import System.IO | ||
import qualified System.Log.Logger as L | ||
import Data.Foldable | ||
|
||
data GlobalOpts = GlobalOpts | ||
{ optDebugOn :: Bool | ||
|
@@ -15,6 +29,27 @@ data GlobalOpts = GlobalOpts | |
, optFiles :: [FilePath] | ||
} deriving (Show) | ||
|
||
initApp :: String -> IO GlobalOpts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is now happening out of context, it would be nice if there was some documentation what this function does, e.g. initialises logger, searches for some project root, etc... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe instead reestablish context, such as by saying in a comment that this is the common prefix of hie and hie-wrapper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense, too. Still, what it roughly does to set-up the application would be nice as well. |
||
initApp namedesc = do | ||
hSetBuffering stderr LineBuffering | ||
let numericVersion :: Parser (a -> a) | ||
numericVersion = infoOption (showVersion Meta.version) | ||
(long "numeric-version" <> help "Show only version number") | ||
compiler :: Parser (a -> a) | ||
compiler = infoOption hieGhcDisplayVersion | ||
(long "compiler" <> help "Show only compiler and version supported") | ||
-- Parse the options and run | ||
(opts, ()) <- simpleOptions | ||
hieVersion | ||
namedesc | ||
"" | ||
(numericVersion <*> compiler <*> globalOptsParser) | ||
empty | ||
Core.setupLogger (optLogFile opts) ["hie", "hie-bios"] | ||
$ if optDebugOn opts then L.DEBUG else L.INFO | ||
traverse_ setCurrentDirectory $ projectRoot opts | ||
return opts | ||
|
||
globalOptsParser :: Parser GlobalOpts | ||
globalOptsParser = GlobalOpts | ||
<$> switch | ||
|
Uh oh!
There was an error while loading. Please reload this page.