@@ -81,6 +81,7 @@ import PrelNames (pRELUDE)
81
81
import System.FilePath
82
82
import System.IO (hClose )
83
83
import System.IO.Temp
84
+ import Data.Maybe (catMaybes )
84
85
85
86
descriptor :: PluginId -> PluginDescriptor
86
87
descriptor plId =
@@ -179,7 +180,10 @@ with all the dependencies. Unfortunately, the ModSummary objects that
179
180
GhcSessionDeps puts in the GHC session are not suitable for reuse since they
180
181
clear out the timestamps; this is done to avoid internal ghcide bugs and
181
182
can probably be relaxed so that plugins like Eval can reuse them. Once that's
182
- done, we want to switch back to GhcSessionDeps
183
+ done, we want to switch back to GhcSessionDeps:
184
+
185
+ -- https://github.com/digital-asset/ghcide/pull/694
186
+
183
187
-}
184
188
session <-
185
189
liftIO $
@@ -240,6 +244,7 @@ done, we want to switch back to GhcSessionDeps
240
244
let eval (stmt, l)
241
245
| isStmt df stmt = do
242
246
-- set up a custom interactive print function
247
+ liftIO $ writeFile temp " "
243
248
ctxt <- getContext
244
249
setContext [IIDecl (simpleImportDecl $ moduleName pRELUDE)]
245
250
let printFun = " let ghcideCustomShow x = Prelude.writeFile " <> show temp <> " (Prelude.show x)"
@@ -256,29 +261,29 @@ done, we want to switch back to GhcSessionDeps
256
261
execLineNumber = l
257
262
}
258
263
res <- execStmt stmt opts
259
- str <- case res of
260
- ExecComplete (Left err) _ -> pure $ pad $ show err
264
+ case res of
265
+ ExecComplete (Left err) _ -> return $ Just $ T. pack $ pad $ show err
261
266
ExecComplete (Right _) _ -> do
262
267
out <- liftIO $ pad <$> readFile temp
263
- let forceIt = length out
264
- return $! forceIt `seq` out
265
- ExecBreak {} -> pure $ pad " breakpoints are not supported"
268
+ -- Important to take the length in order to read the file eagerly
269
+ return $! if length out == 0 then Nothing else Just ( T. pack out)
270
+ ExecBreak {} -> return $ Just $ T. pack $ pad " breakpoints are not supported"
266
271
267
- let changes = [TextEdit editTarget $ T. pack str]
268
- return changes
269
272
| isImport df stmt = do
270
273
ctxt <- getContext
271
274
idecl <- parseImportDecl stmt
272
275
setContext $ IIDecl idecl : ctxt
273
- return []
276
+ return Nothing
274
277
| otherwise = do
275
278
void $ runDecls stmt
276
- return []
279
+ return Nothing
277
280
278
281
edits <- liftIO $ evalGhcEnv hscEnv' $ traverse (eval . first T. unpack) statements
279
282
280
- let workspaceEditsMap = Map. fromList [(_uri, List $ concat edits)]
281
- let workspaceEdits = WorkspaceEdit (Just workspaceEditsMap) Nothing
283
+
284
+ let workspaceEditsMap = Map. fromList [(_uri, List [evalEdit])]
285
+ workspaceEdits = WorkspaceEdit (Just workspaceEditsMap) Nothing
286
+ evalEdit = TextEdit editTarget (T. intercalate " \n " $ catMaybes edits)
282
287
283
288
return (WorkspaceApplyEdit , ApplyWorkspaceEditParams workspaceEdits)
284
289
0 commit comments