on master help sign in
Add --ide flag (#1668)
9529592Neil Mitchell
haskell-ide-core.cabal+8
@@ -22,10 +22,12 @@ library
22 default-language: Haskell2010
22 default-language: Haskell2010
23 build-depends:
23 build-depends:
24 aeson,
24 aeson,
25+ async,
25 base == 4.*,
26 base == 4.*,
26 binary,
27 binary,
27 bytestring,
28 bytestring,
28 containers,
29 containers,
30+ data-default,
29 deepseq,
31 deepseq,
30 directory,
32 directory,
31 either,
33 either,
@@ -38,6 +40,7 @@ library
38 haskell-lsp,
40 haskell-lsp,
39 haskell-lsp-types,
41 haskell-lsp-types,
40 mtl,
42 mtl,
43+ network-uri,
41 pretty,
44 pretty,
42 rope-utf16-splay,
45 rope-utf16-splay,
43 safe-exceptions,
46 safe-exceptions,
@@ -87,6 +90,11 @@ library
87 Development.IDE.State.FileStore
90 Development.IDE.State.FileStore
88 Development.IDE.State.Rules
91 Development.IDE.State.Rules
89 Development.IDE.Compat
92 Development.IDE.Compat
93+ Development.IDE.LSP.LanguageServer
94+ Development.IDE.LSP.Definition
95+ Development.IDE.LSP.Hover
96+ Development.IDE.LSP.Protocol
97+ Development.IDE.LSP.Server
90 Development.IDE.Types.Options
98 Development.IDE.Types.Options
91 Development.IDE.State.RuleTypes
99 Development.IDE.State.RuleTypes
92 Development.IDE.State.Service
100 Development.IDE.State.Service
test/Demo.hs+9−6
@@ -36,7 +36,7 @@ import GHC.Paths
36
36
37main :: IO ()
37main :: IO ()
38main = do
38main = do
39− (ghcOptions, map toNormalizedFilePath -> files) <- getCmdLine
39+ (ghcOptions, map toNormalizedFilePath -> files, isIde) <- getCmdLine
40
40
41 -- lock to avoid overlapping output on stdout
41 -- lock to avoid overlapping output on stdout
42 lock <- newLock
42 lock <- newLock
@@ -52,8 +52,10 @@ main = do
52 ,optShakeProfiling = Nothing -- Just "output.html"
52 ,optShakeProfiling = Nothing -- Just "output.html"
53 }
53 }
54
54
55− if null files then
55+ if isIde then do
56+ putStrLn "Starting IDE server"
56− runLanguageServer logger $ \event vfs ->
57+ runLanguageServer logger $ \event vfs -> do
58+ putStrLn "Server started"
57 initialise mainRule event logger options vfs
59 initialise mainRule event logger options vfs
58 else do
60 else do
59 vfs <- makeVFSHandle
61 vfs <- makeVFSHandle
@@ -92,16 +94,17 @@ newSession flags = runGhc (Just libdir) $ do
92
94
93
95
94-- | Convert the command line into GHC options and files to load.
96-- | Convert the command line into GHC options and files to load.
95−getCmdLine :: IO ([String], [FilePath])
97+getCmdLine :: IO ([String], [FilePath], Bool)
96getCmdLine = do
98getCmdLine = do
97 args <- getArgs
99 args <- getArgs
100+ let isIde = "--ide" `elem` args
98− args <- return $ if null args then [".ghci"] else args
101+ args <- return $ delete "--ide" $ if null args then [".ghci"] else args
99 let (flags, files) = partition ("-" `isPrefixOf`) args
102 let (flags, files) = partition ("-" `isPrefixOf`) args
100 let (ghci, hs) = partition ((==) ".ghci" . takeExtension) files
103 let (ghci, hs) = partition ((==) ".ghci" . takeExtension) files
101 (flags, files) <- both concat . unzip . ((flags,hs):) <$> mapM readGhci ghci
104 (flags, files) <- both concat . unzip . ((flags,hs):) <$> mapM readGhci ghci
102 when (null files) $
105 when (null files) $
103 fail "Expected some files to load, but didn't find any"
106 fail "Expected some files to load, but didn't find any"
104− return (flags, files)
107+ return (flags, files, isIde)
105
108
106readGhci :: FilePath -> IO ([String], [FilePath])
109readGhci :: FilePath -> IO ([String], [FilePath])
107readGhci file = do
110readGhci file = do