@@ -41,6 +41,7 @@ import Network.Socket hiding (PortNumber, Type,
41import Options.Applicative (ParseError (..))
41import Options.Applicative (ParseError (..))
42import qualified Options.Applicative as Opts
42import qualified Options.Applicative as Opts
43import System.Directory
43import System.Directory
44+import System.Info as SysInfo
44import System.FilePath
45import System.FilePath
45import System.IO hiding (putStrLn, print)
46import System.IO hiding (putStrLn, print)
46import System.IO.Error (isEOFError)
47import System.IO.Error (isEOFError)
@@ -66,12 +67,14 @@ data Options = Options
66 , optionsOutputPath :: FilePath
67 , optionsOutputPath :: FilePath
67 , optionsPort :: PortNumber
68 , optionsPort :: PortNumber
68 , optionsNoWatch :: Bool
69 , optionsNoWatch :: Bool
70+ , optionsPolling :: Bool
69 , optionsDebug :: Bool
71 , optionsDebug :: Bool
70− }
72+ } deriving (Show)
72main :: IO ()
74main :: IO ()
74− Options dir globs outputPath port noWatch debug <- Opts.execParser opts
76+ opts'@(Options dir globs outputPath port noWatch polling debug) <- Opts.execParser opts
77+ when debug (putText "Parsed Options:" *> print opts')
75 maybe (pure ()) setCurrentDirectory dir
78 maybe (pure ()) setCurrentDirectory dir
76 ideState <- newTVarIO emptyIdeState
79 ideState <- newTVarIO emptyIdeState
77 cwd <- getCurrentDirectory
80 cwd <- getCurrentDirectory
@@ -84,7 +87,7 @@ main = do
84 putText "psc-ide needs you to compile your project (for example by running pulp build)"
87 putText "psc-ide needs you to compile your project (for example by running pulp build)"
86 unless noWatch $
89 unless noWatch $
87− void (forkFinally (watcher ideState fullOutputPath) print)
90+ void (forkFinally (watcher polling ideState fullOutputPath) print)
89 let conf = Configuration {confDebug = debug, confOutputPath = outputPath, confGlobs = globs}
92 let conf = Configuration {confDebug = debug, confOutputPath = outputPath, confGlobs = globs}
90 env = IdeEnvironment {ideStateVar = ideState, ideConfiguration = conf}
93 env = IdeEnvironment {ideStateVar = ideState, ideConfiguration = conf}
@@ -98,12 +101,17 @@ main = do
98 <*> (fromIntegral <$>
101 <*> (fromIntegral <$>
99 Opts.option Opts.auto (Opts.long "port" `mappend` Opts.short 'p' `mappend` Opts.value (4242 :: Integer)))
102 Opts.option Opts.auto (Opts.long "port" `mappend` Opts.short 'p' `mappend` Opts.value (4242 :: Integer)))
100 <*> Opts.switch (Opts.long "no-watch")
103 <*> Opts.switch (Opts.long "no-watch")
104+ <*> flipIfWindows (Opts.switch (Opts.long "polling"))
101 <*> Opts.switch (Opts.long "debug")
105 <*> Opts.switch (Opts.long "debug")
102 opts = Opts.info (version <*> Opts.helper <*> parser) mempty
106 opts = Opts.info (version <*> Opts.helper <*> parser) mempty
103 version = Opts.abortOption
107 version = Opts.abortOption
104 (InfoMsg (showVersion Paths.version))
108 (InfoMsg (showVersion Paths.version))
105 (Opts.long "version" `mappend` Opts.help "Show the version number")
109 (Opts.long "version" `mappend` Opts.help "Show the version number")
111+ -- polling is the default on Windows and the flag turns it off. See
112+ -- #2209 and #2414 for explanations
113+ flipIfWindows = map (if SysInfo.os == "mingw32" then not else identity)
107startServer :: PortNumber -> IdeEnvironment -> IO ()
115startServer :: PortNumber -> IdeEnvironment -> IO ()
108startServer port env = withSocketsDo $ do
116startServer port env = withSocketsDo $ do
109 sock <- listenOnLocalhost port
117 sock <- listenOnLocalhost port