git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2414 from kRITZCREEK/psc-ide-polling

[psc-ide] Polling option for psc-ide-server

commit5f0dd05515b5f3b048dbf1ed3e193e1eb33df652 authorPhil Freeman <paf31@cantab.net> dateWed 7 Dec 2016, 01:50 (10 years ago) parent6954b06460e8cb
3 files changed+23−10
psc-ide-server/Main.hs+11−3 psc-ide-server/README.md+2 src/Language/PureScript/Ide/Watcher.hs+10−7
psc-ide-server/Main.hs+11−3
@@ -41,6 +41,7 @@ import Network.Socket hiding (PortNumber, Type,
4141import Options.Applicative (ParseError (..))
4242import qualified Options.Applicative as Opts
4343import System.Directory
44+import System.Info as SysInfo
4445import System.FilePath
4546import System.IO hiding (putStrLn, print)
4647import System.IO.Error (isEOFError)
@@ -66,12 +67,14 @@ data Options = Options
6667 , optionsOutputPath :: FilePath
6768 , optionsPort :: PortNumber
6869 , optionsNoWatch :: Bool
70+ , optionsPolling :: Bool
6971 , optionsDebug :: Bool
70− }
72+ } deriving (Show)
7173
7274main :: IO ()
7375main = do
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')
7578 maybe (pure ()) setCurrentDirectory dir
7679 ideState <- newTVarIO emptyIdeState
7780 cwd <- getCurrentDirectory
@@ -84,7 +87,7 @@ main = do
8487 putText "psc-ide needs you to compile your project (for example by running pulp build)"
8588
8689 unless noWatch $
87− void (forkFinally (watcher ideState fullOutputPath) print)
90+ void (forkFinally (watcher polling ideState fullOutputPath) print)
8891
8992 let conf = Configuration {confDebug = debug, confOutputPath = outputPath, confGlobs = globs}
9093 env = IdeEnvironment {ideStateVar = ideState, ideConfiguration = conf}
@@ -98,12 +101,17 @@ main = do
98101 <*> (fromIntegral <$>
99102 Opts.option Opts.auto (Opts.long "port" `mappend` Opts.short 'p' `mappend` Opts.value (4242 :: Integer)))
100103 <*> Opts.switch (Opts.long "no-watch")
104+ <*> flipIfWindows (Opts.switch (Opts.long "polling"))
101105 <*> Opts.switch (Opts.long "debug")
102106 opts = Opts.info (version <*> Opts.helper <*> parser) mempty
103107 version = Opts.abortOption
104108 (InfoMsg (showVersion Paths.version))
105109 (Opts.long "version" `mappend` Opts.help "Show the version number")
106110
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)
114+
107115startServer :: PortNumber -> IdeEnvironment -> IO ()
108116startServer port env = withSocketsDo $ do
109117 sock <- listenOnLocalhost port
psc-ide-server/README.md+2
@@ -23,6 +23,8 @@ It supports the following options:
2323 project directory. Defaults to `output/`, relative to either the current
2424 directory or the directory specified by `-d`.
2525- `--debug`: Enables some logging meant for debugging
26+- `--polling`: Uses polling instead of file system events to watch the externs
27+ files. This flag is reversed on Windows and polling is the default.
2628- `--no-watch`: Disables the filewatcher
2729- `--version`: Output psc-ide version
2830
src/Language/PureScript/Ide/Watcher.hs+10−7
@@ -40,10 +40,13 @@ reloadFile ref ev = do
4040
4141-- | Installs filewatchers for the given directory and reloads ExternsFiles when
4242-- they change on disc
43−watcher :: TVar IdeState -> FilePath -> IO ()
44−watcher stateVar fp =
45− withManagerConf (defaultConfig { confDebounce = NoDebounce }) $ \mgr -> do
46− _ <- watchTree mgr fp
47− (\ev -> takeFileName (eventPath ev) == "externs.json")
48− (reloadFile stateVar)
49− forever (threadDelay 100000)
43+watcher :: Bool -> TVar IdeState -> FilePath -> IO ()
44+watcher polling stateVar fp =
45+ withManagerConf
46+ (defaultConfig { confDebounce = NoDebounce
47+ , confUsePolling = polling
48+ }) $ \mgr -> do
49+ _ <- watchTree mgr fp
50+ (\ev -> takeFileName (eventPath ev) == "externs.json")
51+ (reloadFile stateVar)
52+ forever (threadDelay 100000)