mirror of
https://github.com/haskell/ghcide.git
synced 2024-10-26 05:58:45 +03:00
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:
parent
28946c2115
commit
952959293f
@ -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
|
||||
|
15
test/Demo.hs
15
test/Demo.hs
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user