Add --ide flag (#1668)

* Add --ide flag to the Demo

* Fix things in the .cabal file

* Add tracing messages to Demo.hs
This commit is contained in:
Neil Mitchell 2019-06-14 14:26:25 +02:00 committed by GitHub
parent aa84930061
commit dfc1c48f4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -22,10 +22,12 @@ library
default-language: Haskell2010
build-depends:
aeson,
async,
base == 4.*,
binary,
bytestring,
containers,
data-default,
deepseq,
directory,
either,
@ -38,6 +40,7 @@ library
haskell-lsp,
haskell-lsp-types,
mtl,
network-uri,
pretty,
rope-utf16-splay,
safe-exceptions,
@ -87,6 +90,11 @@ library
Development.IDE.State.FileStore
Development.IDE.State.Rules
Development.IDE.Compat
Development.IDE.LSP.LanguageServer
Development.IDE.LSP.Definition
Development.IDE.LSP.Hover
Development.IDE.LSP.Protocol
Development.IDE.LSP.Server
Development.IDE.Types.Options
Development.IDE.State.RuleTypes
Development.IDE.State.Service

View File

@ -36,7 +36,7 @@ import GHC.Paths
main :: IO ()
main = do
(ghcOptions, map toNormalizedFilePath -> files) <- getCmdLine
(ghcOptions, map toNormalizedFilePath -> files, isIde) <- getCmdLine
-- lock to avoid overlapping output on stdout
lock <- newLock
@ -52,8 +52,10 @@ main = do
,optShakeProfiling = Nothing -- Just "output.html"
}
if null files then
runLanguageServer logger $ \event vfs ->
if isIde then do
putStrLn "Starting IDE server"
runLanguageServer logger $ \event vfs -> do
putStrLn "Server started"
initialise mainRule event logger options vfs
else do
vfs <- makeVFSHandle
@ -92,16 +94,17 @@ newSession flags = runGhc (Just libdir) $ do
-- | Convert the command line into GHC options and files to load.
getCmdLine :: IO ([String], [FilePath])
getCmdLine :: IO ([String], [FilePath], Bool)
getCmdLine = do
args <- getArgs
args <- return $ if null args then [".ghci"] else args
let isIde = "--ide" `elem` args
args <- return $ delete "--ide" $ if null args then [".ghci"] else args
let (flags, files) = partition ("-" `isPrefixOf`) args
let (ghci, hs) = partition ((==) ".ghci" . takeExtension) files
(flags, files) <- both concat . unzip . ((flags,hs):) <$> mapM readGhci ghci
when (null files) $
fail "Expected some files to load, but didn't find any"
return (flags, files)
return (flags, files, isIde)
readGhci :: FilePath -> IO ([String], [FilePath])
readGhci file = do