on master help sign in
Move the ofInterest kicking around in the IDE (#1669)

* Move getFilesOfInterest into the IDE, and OfInterest out into DAML * Have the IDE mode kick all active files each time * Add a missing .cabal dependency * Add a missing dependencies * Use the right thing, if any files have parse errors, then don't worry * Print messages to stderr rather than stdout * Add a big warning that writing to stdout is a bad plan

commite2e158a85dd289f4a2414f314ea72b5254ab7bf0 authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateFri 14 Jun 2019, 16:23 (7 years ago) parent0058173
5 files changed+35−10
BUILD.bazel+1 haskell-ide-core.cabal+1 src/Development/IDE/State/RuleTypes.hs+8−6 src/Development/IDE/State/Rules.hs+12 test/Demo.hs+13−4
BUILD.bazel+1
@@ -35,6 +35,7 @@ depends = [
3535 "transformers",
3636 "uniplate",
3737 "unordered-containers",
38+ "utf8-string",
3839 "uri-encode",
3940]
4041
haskell-ide-core.cabal+1
@@ -55,6 +55,7 @@ library
5555 transformers,
5656 uniplate,
5757 unordered-containers,
58+ utf8-string,
5859 uri-encode
5960
6061 cpp-options: -DGHC_STABLE
src/Development/IDE/State/RuleTypes.hs+8−6
@@ -19,6 +19,8 @@ import Development.IDE.Functions.FindImports (Import(..))
1919import Development.IDE.Functions.DependencyInformation
2020import Data.Hashable
2121import Data.Typeable
22+import Development.IDE.Types.Diagnostics
23+import Data.Set(Set)
2224import Development.Shake hiding (Env, newCache)
2325import GHC.Generics (Generic)
2426
@@ -33,9 +35,6 @@ import Development.IDE.Types.SpanInfo
3335-- Foo+ means Foo for the dependencies
3436-- Foo* means Foo for me and Foo+
3537
36−-- | Kick off things
37−type instance RuleResult OfInterest = ()
38−
3938-- | The parse tree for the file using GetFileContents
4039type instance RuleResult GetParsedModule = ParsedModule
4140
@@ -73,10 +72,13 @@ type instance RuleResult ReportImportCycles = ()
7372type instance RuleResult GetHieFile = HieFile
7473
7574
76−data OfInterest = OfInterest
75+type instance RuleResult GetFilesOfInterest = Set NormalizedFilePath
76+
77+
78+data GetFilesOfInterest = GetFilesOfInterest
7779 deriving (Eq, Show, Typeable, Generic)
78−instance Hashable OfInterest
79−instance NFData OfInterest
80+instance Hashable GetFilesOfInterest
81+instance NFData GetFilesOfInterest
8082
8183data GetParsedModule = GetParsedModule
8284 deriving (Eq, Show, Typeable, Generic)
src/Development/IDE/State/Rules.hs+12
@@ -31,6 +31,9 @@ import Development.IDE.Functions.DependencyInformation
3131import Development.IDE.Functions.FindImports
3232import Development.IDE.State.FileStore
3333import Development.IDE.Types.Diagnostics as Base
34+import qualified Data.ByteString.UTF8 as BS
35+import Control.Exception
36+import Control.Concurrent.Extra
3437import Data.Bifunctor
3538import Data.Either.Extra
3639import Data.Maybe
@@ -72,6 +75,14 @@ defineNoFile f = define $ \k file -> do
7275------------------------------------------------------------
7376-- Exposed API
7477
78+getFilesOfInterestRule :: Rules ()
79+getFilesOfInterestRule = do
80+ defineEarlyCutoff $ \GetFilesOfInterest _file -> assert (null $ fromNormalizedFilePath _file) $ do
81+ alwaysRerun
82+ Env{..} <- getServiceEnv
83+ filesOfInterest <- liftIO $ readVar envOfInterestVar
84+ pure (Just $ BS.fromString $ show filesOfInterest, ([], Just filesOfInterest))
85+
7586
7687-- | Get GHC Core for the supplied file.
7788getGhcCore :: NormalizedFilePath -> Action (Maybe [CoreModule])
@@ -318,6 +329,7 @@ mainRule = do
318329 generateCoreRule
319330 loadGhcSession
320331 getHieFileRule
332+ getFilesOfInterestRule
321333
322334------------------------------------------------------------
323335
test/Demo.hs+13−4
@@ -11,6 +11,7 @@ import Development.IDE.State.Service
1111import Development.IDE.State.Rules
1212import Development.IDE.State.Shake
1313import Development.IDE.State.RuleTypes
14+import Data.String
1415import Development.IDE.Types.Diagnostics
1516import Development.IDE.Types.Options
1617import Development.IDE.Logger
@@ -39,6 +40,9 @@ getLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"
3940
4041main :: IO ()
4142main = do
43+ -- WARNING: If you write to stdout before runLanguageServer
44+ -- then the language server will not work
45+ hPutStrLn stderr "Starting haskell-ide-core Demo"
4246 (ghcOptions, map toNormalizedFilePath -> files, isIde) <- getCmdLine
4347
4448 -- lock to avoid overlapping output on stdout
@@ -56,21 +60,26 @@ main = do
5660 }
5761
5862 if isIde then do
59− putStrLn "Starting IDE server"
63+ hPutStrLn stderr "Starting running the IDE server"
6064 runLanguageServer logger $ \event vfs -> do
61− putStrLn "Server started"
62− initialise mainRule event logger options vfs
65+ hPutStrLn stderr "Server started"
66+ initialise (mainRule >> action kick) event logger options vfs
6367 else do
6468 vfs <- makeVFSHandle
6569 ide <- initialise mainRule (showEvent lock) logger options vfs
6670 setFilesOfInterest ide $ Set.fromList files
67− _ <- runAction ide $ uses_ TypeCheck files
71+ runAction ide kick
6872 -- shake now writes an async message that it is completed with timing info,
6973 -- so we sleep briefly to wait for it to have been written
7074 sleep 0.01
7175 putStrLn "Done"
7276
7377
78+kick :: Action ()
79+kick = do
80+ files <- use_ GetFilesOfInterest $ fromString ""
81+ void $ uses TypeCheck $ Set.toList files
82+
7483-- | Print an LSP event.
7584showEvent :: Lock -> FromServerMessage -> IO ()
7685showEvent _ (EventFileDiagnostics _ []) = return ()