@@ -14,40 +14,66 @@ import System.IO
1414import qualified System.Log.Logger as L
1515import Data.Foldable
1616
17+ data ProjectLoadingOpts = ProjectLoadingOpts
18+ { optDryRun :: Bool
19+ , optFiles :: [FilePath ]
20+ } deriving (Show , Eq )
21+
22+ data RunMode = LspMode | ProjectLoadingMode ProjectLoadingOpts
23+ deriving (Show , Eq )
24+
1725data GlobalOpts = GlobalOpts
1826 { optDebugOn :: Bool
1927 , optLogFile :: Maybe String
20- , optLsp :: Bool
2128 , projectRoot :: Maybe String
2229 , optBiosVerbose :: Bool
2330 , optCaptureFile :: Maybe FilePath
2431 , optExamplePlugin :: Bool
25- , optDryRun :: Bool
26- , optFiles :: [FilePath ]
27- } deriving (Show )
32+ , optMode :: RunMode
33+ } deriving (Show , Eq )
2834
2935-- | Introduced as the common prefix of app/HieWrapper.hs/main and app/MainHie.hs/main
3036initApp :: String -> IO GlobalOpts
3137initApp namedesc = do
3238 hSetBuffering stderr LineBuffering
33- let numericVersion :: Parser (a -> a )
34- numericVersion = infoOption (showVersion Meta. version)
35- (long " numeric-version" <> help " Show only version number" )
36- compiler :: Parser (a -> a )
37- compiler = infoOption hieGhcDisplayVersion
38- (long " compiler" <> help " Show only compiler and version supported" )
3939 -- Parse the options and run
4040 (opts, () ) <- simpleOptions
4141 hieVersion
4242 namedesc
4343 " "
44- (numericVersion <*> compiler <*> globalOptsParser)
44+ optionParser
4545 empty
4646 Core. setupLogger (optLogFile opts) [" hie" , " hie-bios" ]
4747 $ if optDebugOn opts then L. DEBUG else L. INFO
4848 traverse_ setCurrentDirectory $ projectRoot opts
4949 return opts
5050
51+ optionParser :: Parser GlobalOpts
52+ optionParser = numericVersion <*> compiler <*> globalOptsParser
53+
54+ numericVersion :: Parser (a -> a )
55+ numericVersion = infoOption (showVersion Meta. version)
56+ (long " numeric-version" <> help " Show only version number" )
57+
58+ compiler :: Parser (a -> a )
59+ compiler = infoOption hieGhcDisplayVersion
60+ (long " compiler" <> help " Show only compiler and version supported" )
61+
62+ projectLoadingModeParser :: Parser RunMode
63+ projectLoadingModeParser =
64+ ProjectLoadingMode
65+ <$> (ProjectLoadingOpts
66+ <$> flag False True
67+ ( long " dry-run"
68+ <> help " Perform a dry-run of loading files. Only searches for Haskell source files to load. Does nothing if run as LSP server."
69+ )
70+ <*> many
71+ ( argument str
72+ ( metavar " FILES..."
73+ <> help " Directories and Filepaths to load. Does nothing if run as LSP server." )
74+ )
75+ )
76+
5177globalOptsParser :: Parser GlobalOpts
5278globalOptsParser = GlobalOpts
5379 <$> switch
@@ -61,9 +87,6 @@ globalOptsParser = GlobalOpts
6187 <> metavar " LOGFILE"
6288 <> help " File to log to, defaults to stdout"
6389 ))
64- <*> flag False True
65- ( long " lsp"
66- <> help " Start HIE as an LSP server. Otherwise it dumps debug info to stdout" )
6790 <*> optional (strOption
6891 ( long " project-root"
6992 <> short ' r'
@@ -88,13 +111,9 @@ globalOptsParser = GlobalOpts
88111 <*> switch
89112 ( long " example"
90113 <> help " Enable Example2 plugin. Useful for developers only" )
91- <*> flag False True
92- ( long " dry-run"
93- <> help " Perform a dry-run of loading files. Only searches for Haskell source files to load. Does nothing if run as LSP server."
94- )
95- <*> many
96- ( argument str
97- ( metavar " FILES..."
98- <> help " Directories and Filepaths to load. Does nothing if run as LSP server." )
99- )
100-
114+ <*> (flag' LspMode
115+ ( long " lsp"
116+ <> help " Start HIE as an LSP server. Otherwise it dumps debug info to stdout" )
117+ <|>
118+ projectLoadingModeParser
119+ )
0 commit comments