@@ -50,8 +50,10 @@ import Development.IDE.Types.Logger (Logger (Logger),
50
50
Priority (Info ),
51
51
Recorder (logger_ ),
52
52
WithPriority (WithPriority ),
53
+ Doc ,
53
54
cmapWithPrio ,
54
- makeDefaultStderrRecorder )
55
+ makeDefaultStderrRecorder ,
56
+ toCologActionWithPrio )
55
57
import GHC.Stack.Types (emptyCallStack )
56
58
import Ide.Plugin.Config (Config )
57
59
import Ide.Types (IdePlugins (IdePlugins ))
@@ -74,6 +76,7 @@ main = do
74
76
args <- getArguments " haskell-language-server-wrapper" mempty
75
77
76
78
hlsVer <- haskellLanguageServerVersion
79
+ recorder <- makeDefaultStderrRecorder Nothing Info
77
80
case args of
78
81
ProbeToolsMode -> do
79
82
programsOfInterest <- findProgramVersions
@@ -82,7 +85,7 @@ main = do
82
85
putStrLn $ showProgramVersionOfInterest programsOfInterest
83
86
putStrLn " Tool versions in your project"
84
87
cradle <- findProjectCradle' False
85
- ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle
88
+ ghcVersion <- runExceptT $ getRuntimeGhcVersion' recorder cradle
86
89
putStrLn $ showProgramVersion " ghc" $ mkVersion =<< eitherToMaybe ghcVersion
87
90
88
91
VersionMode PrintVersion ->
@@ -95,18 +98,18 @@ main = do
95
98
print =<< findProjectCradle
96
99
PrintLibDir -> do
97
100
cradle <- findProjectCradle' False
98
- (CradleSuccess libdir) <- HieBios. getRuntimeGhcLibDir cradle
101
+ (CradleSuccess libdir) <- HieBios. getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
99
102
putStr libdir
100
- _ -> launchHaskellLanguageServer args >>= \ case
103
+ _ -> launchHaskellLanguageServer recorder args >>= \ case
101
104
Right () -> pure ()
102
105
Left err -> do
103
106
T. hPutStrLn stderr (prettyError err NoShorten )
104
107
case args of
105
- Ghcide _ -> launchErrorLSP (prettyError err Shorten )
108
+ Ghcide _ -> launchErrorLSP recorder (prettyError err Shorten )
106
109
_ -> pure ()
107
110
108
- launchHaskellLanguageServer :: Arguments -> IO (Either WrapperSetupError () )
109
- launchHaskellLanguageServer parsedArgs = do
111
+ launchHaskellLanguageServer :: Recorder ( WithPriority ( Doc () )) -> Arguments -> IO (Either WrapperSetupError () )
112
+ launchHaskellLanguageServer recorder parsedArgs = do
110
113
case parsedArgs of
111
114
Ghcide GhcideArguments {.. } -> whenJust argsCwd setCurrentDirectory
112
115
_ -> pure ()
@@ -122,7 +125,7 @@ launchHaskellLanguageServer parsedArgs = do
122
125
case parsedArgs of
123
126
Ghcide GhcideArguments {.. } ->
124
127
when argsProjectGhcVersion $ do
125
- runExceptT (getRuntimeGhcVersion' cradle) >>= \ case
128
+ runExceptT (getRuntimeGhcVersion' recorder cradle) >>= \ case
126
129
Right ghcVersion -> putStrLn ghcVersion >> exitSuccess
127
130
Left err -> T. putStrLn (prettyError err NoShorten ) >> exitFailure
128
131
_ -> pure ()
@@ -145,7 +148,7 @@ launchHaskellLanguageServer parsedArgs = do
145
148
hPutStrLn stderr " Consulting the cradle to get project GHC version..."
146
149
147
150
runExceptT $ do
148
- ghcVersion <- getRuntimeGhcVersion' cradle
151
+ ghcVersion <- getRuntimeGhcVersion' recorder cradle
149
152
liftIO $ hPutStrLn stderr $ " Project GHC version: " ++ ghcVersion
150
153
151
154
let
@@ -170,10 +173,10 @@ launchHaskellLanguageServer parsedArgs = do
170
173
171
174
let cradleName = actionName (cradleOptsProg cradle)
172
175
-- we need to be compatible with NoImplicitPrelude
173
- ghcBinary <- liftIO (fmap trim <$> runGhcCmd [" -v0" , " -package-env=-" , " -ignore-dot-ghci" , " -e" , " Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)" ])
176
+ ghcBinary <- liftIO (fmap trim <$> runGhcCmd (toCologActionWithPrio (cmapWithPrio pretty recorder)) [" -v0" , " -package-env=-" , " -ignore-dot-ghci" , " -e" , " Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)" ])
174
177
>>= cradleResult cradleName
175
178
176
- libdir <- liftIO (HieBios. getRuntimeGhcLibDir cradle)
179
+ libdir <- liftIO (HieBios. getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle)
177
180
>>= cradleResult cradleName
178
181
179
182
env <- Map. fromList <$> liftIO getEnvironment
@@ -190,8 +193,8 @@ cradleResult cradleName CradleNone = throwE $ NoneCradleGhcVersion cradleName
190
193
191
194
-- | Version of 'getRuntimeGhcVersion' that dies if we can't get it, and also
192
195
-- checks to see if the tool is missing if it is one of
193
- getRuntimeGhcVersion' :: Cradle Void -> ExceptT WrapperSetupError IO String
194
- getRuntimeGhcVersion' cradle = do
196
+ getRuntimeGhcVersion' :: Recorder ( WithPriority ( Doc () )) -> Cradle Void -> ExceptT WrapperSetupError IO String
197
+ getRuntimeGhcVersion' recorder cradle = do
195
198
let cradleName = actionName (cradleOptsProg cradle)
196
199
197
200
-- See if the tool is installed
@@ -202,7 +205,7 @@ getRuntimeGhcVersion' cradle = do
202
205
Direct -> checkToolExists " ghc"
203
206
_ -> pure ()
204
207
205
- ghcVersionRes <- liftIO $ HieBios. getRuntimeGhcVersion cradle
208
+ ghcVersionRes <- liftIO $ HieBios. getRuntimeGhcVersion (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
206
209
cradleResult cradleName ghcVersionRes
207
210
208
211
where
@@ -271,10 +274,8 @@ newtype ErrorLSPM c a = ErrorLSPM { unErrorLSPM :: (LspM c) a }
271
274
272
275
-- | Launches a LSP that displays an error and presents the user with a request
273
276
-- to shut down the LSP.
274
- launchErrorLSP :: T. Text -> IO ()
275
- launchErrorLSP errorMsg = do
276
- recorder <- makeDefaultStderrRecorder Nothing Info
277
-
277
+ launchErrorLSP :: Recorder (WithPriority (Doc () )) -> T. Text -> IO ()
278
+ launchErrorLSP recorder errorMsg = do
278
279
let logger = Logger $ \ p m -> logger_ recorder (WithPriority p emptyCallStack (pretty m))
279
280
280
281
let defaultArguments = Main. defaultArguments (cmapWithPrio pretty recorder) logger (IdePlugins [] )
0 commit comments