@@ -4,7 +4,6 @@ import Control.Exception.Safe (
44 Exception (displayException ),
55 catchAny ,
66 )
7- import Control.Lens ((^.) )
87import Control.Monad.Extra (concatMapM , unless , when )
98import qualified Data.Aeson as J
109import Data.Default (Default (def ))
@@ -47,18 +46,13 @@ import Development.IDE.Core.Shake (
4746 )
4847import Development.IDE.Core.Tracing (measureMemory )
4948import Development.IDE.LSP.LanguageServer (runLanguageServer )
50- import Development.IDE.LSP.Protocol
5149import Development.IDE.Plugin (
52- Plugin (pluginHandler , pluginRules ),
50+ Plugin (pluginHandlers , pluginRules ),
5351 )
5452import Development.IDE.Plugin.HLS (asGhcIdePlugin )
5553import Development.IDE.Session (SessionLoadingOptions , defaultLoadingOptions , loadSessionWithOptions , setInitialDynFlags )
56- import Development.IDE.Types.Diagnostics (
57- ShowDiagnostic (ShowDiag ),
58- showDiagnosticsColored ,
59- )
6054import Development.IDE.Types.Location (toNormalizedFilePath' )
61- import Development.IDE.Types.Logger (Logger , logInfo )
55+ import Development.IDE.Types.Logger (Logger )
6256import Development.IDE.Types.Options (
6357 IdeGhcSession ,
6458 IdeOptions (optCheckParents , optCheckProject , optReportProgress ),
@@ -71,14 +65,7 @@ import HIE.Bios.Cradle (findCradle)
7165import Ide.Plugin.Config (CheckParents (NeverCheck ), Config )
7266import Ide.PluginUtils (allLspCmdIds' , getProcessID , pluginDescToIdePlugins )
7367import Ide.Types (IdePlugins )
74- import qualified Language.Haskell.LSP.Core as LSP
75- import Language.Haskell.LSP.Messages (FromServerMessage )
76- import Language.Haskell.LSP.Types (
77- DidChangeConfigurationNotification ,
78- InitializeRequest ,
79- LspId (IdInt ),
80- )
81- import Language.Haskell.LSP.Types.Lens (initializationOptions , params )
68+ import qualified Language.LSP.Server as LSP
8269import qualified System.Directory.Extra as IO
8370import System.Exit (ExitCode (ExitFailure ), exitWith )
8471import System.FilePath (takeExtension , takeFileName )
@@ -99,8 +86,7 @@ data Arguments = Arguments
9986 , argsSessionLoadingOptions :: SessionLoadingOptions
10087 , argsIdeOptions :: Maybe Config -> Action IdeGhcSession -> IdeOptions
10188 , argsLspOptions :: LSP. Options
102- , argsGetInitialConfig :: InitializeRequest -> Either T. Text Config
103- , argsOnConfigChange :: DidChangeConfigurationNotification -> Either T. Text Config
89+ , argsOnConfigChange :: IdeState -> J. Value -> IO (Either T. Text Config )
10490 }
10591
10692defArguments :: HieDb -> IndexQueue -> Arguments
@@ -117,12 +103,9 @@ defArguments hiedb hiechan =
117103 , argsSessionLoadingOptions = defaultLoadingOptions
118104 , argsIdeOptions = const defaultIdeOptions
119105 , argsLspOptions = def {LSP. completionTriggerCharacters = Just " ." }
120- , argsOnConfigChange = const $ Left " Updating Not supported"
121- , argsGetInitialConfig = \ x -> case x ^. params . initializationOptions of
122- Nothing -> Right def
123- Just v -> case J. fromJSON v of
124- J. Error err -> Left $ T. pack err
125- J. Success a -> Right a
106+ , argsOnConfigChange = \ _ide v -> pure $ case J. fromJSON v of
107+ J. Error err -> Left $ T. pack err
108+ J. Success a -> Right a
126109 }
127110
128111defaultMain :: Arguments -> IO ()
@@ -140,7 +123,7 @@ defaultMain Arguments{..} = do
140123 t <- offsetTime
141124 hPutStrLn stderr " Starting LSP server..."
142125 hPutStrLn stderr " If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
143- runLanguageServer options (pluginHandler plugins) argsGetInitialConfig argsOnConfigChange $ \ getLspId event vfs caps wProg wIndefProg getConfig rootPath -> do
126+ runLanguageServer options argsOnConfigChange (pluginHandlers plugins) $ \ env vfs rootPath -> do
144127 t <- t
145128 hPutStrLn stderr $ " Started LSP server in " ++ showDuration t
146129
@@ -153,19 +136,16 @@ defaultMain Arguments{..} = do
153136 `catchAny` (\ e -> (hPutStrLn stderr $ " setInitialDynFlags: " ++ displayException e) >> pure Nothing )
154137
155138 sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions $ fromMaybe dir rootPath
156- config <- getConfig
139+ config <- LSP. runLspT env LSP. getConfig
157140 let options = (argsIdeOptions config sessionLoader)
158141 { optReportProgress = clientSupportsProgress caps
159142 }
160143 rules = argsRules >> pluginRules plugins
144+ caps = LSP. resClientCapabilities env
161145 debouncer <- newAsyncDebouncer
162146 initialise
163- caps
164147 rules
165- getLspId
166- event
167- wProg
168- wIndefProg
148+ (Just env)
169149 argsLogger
170150 debouncer
171151 options
@@ -195,13 +175,12 @@ defaultMain Arguments{..} = do
195175 putStrLn " \n Step 3/4: Initializing the IDE"
196176 vfs <- makeVFSHandle
197177 debouncer <- newAsyncDebouncer
198- let dummyWithProg _ _ f = f (const (pure () ))
199178 sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions dir
200179 let options = (argsIdeOptions Nothing sessionLoader)
201- { optCheckParents = NeverCheck
202- , optCheckProject = False
180+ { optCheckParents = pure NeverCheck
181+ , optCheckProject = pure False
203182 }
204- ide <- initialise def mainRule ( pure $ IdInt 0 ) (showEvent argsLogger) dummyWithProg ( const ( const id )) argsLogger debouncer options vfs argsHiedb argsHieChan
183+ ide <- initialise mainRule Nothing argsLogger debouncer options vfs argsHiedb argsHieChan
205184
206185 putStrLn " \n Step 4/4: Type checking the files"
207186 setFilesOfInterest ide $ HashMap. fromList $ map ((,OnDisk ) . toNormalizedFilePath') files
@@ -246,10 +225,3 @@ expandFiles = concatMapM $ \x -> do
246225 when (null files) $
247226 fail $ " Couldn't find any .hs/.lhs files inside directory: " ++ x
248227 return files
249-
250- -- | Print an LSP event.
251- showEvent :: Logger -> FromServerMessage -> IO ()
252- showEvent _ (EventFileDiagnostics _ [] ) = return ()
253- showEvent argsLogger (EventFileDiagnostics (toNormalizedFilePath' -> file) diags) =
254- logInfo argsLogger $ showDiagnosticsColored $ map (file,ShowDiag ,) diags
255- showEvent argsLogger e = logInfo argsLogger $ T. pack $ show e
0 commit comments