Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 15037a4

Browse files
authored
Try to fix makeRefactorResult again
1 parent dd9cbdd commit 15037a4

File tree

1 file changed

+16
-10
lines changed
  • src/Haskell/Ide/Engine/Plugin

1 file changed

+16
-10
lines changed

src/Haskell/Ide/Engine/Plugin/HaRe.hs

+16-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Data.Foldable
1818
import Data.Monoid
1919
#endif
2020
import qualified Data.Text as T
21+
import qualified Data.Text.IO as T
2122
import Exception
2223
import GHC.Generics (Generic)
2324
import Haskell.Ide.Engine.ArtifactMap
@@ -213,16 +214,21 @@ makeRefactorResult changedFiles = do
213214
uri <- canonicalizeUri $ filePathToUri fp
214215
mvf <- getVirtualFile uri
215216

216-
case mvf of
217-
Nothing ->
218-
-- if there is no virtual file, dont try to persist it!
219-
return $ IdeResultFail
220-
(IdeError PluginError
221-
(T.pack "makeRefactorResult: no access to the persisted file.")
222-
Null
223-
)
224-
Just vf -> do
225-
let origText = Rope.toText $ _text vf
217+
origTextResult <- case mvf of
218+
Nothing -> do
219+
let resultFail = return $ IdeResultFail
220+
(IdeError PluginError
221+
(T.pack "makeRefactorResult: no access to the persisted file.")
222+
Null
223+
)
224+
withMappedFile fp resultFail (fmap IdeResultOk . liftIO . T.readFile)
225+
Just vf -> return $ IdeResultOk $ Rope.toText $ _text vf
226+
227+
case origTextResult of
228+
IdeResultFail err -> do
229+
logm "makeRefactorResult:could not retrieve original text"
230+
return $ IdeResultFail err
231+
IdeResultOk origText -> do
226232
-- TODO: remove this logging once we are sure we have a working solution
227233
logm $ "makeRefactorResult:groupedDiff = " ++ show (getGroupedDiff (lines $ T.unpack origText) (lines $ T.unpack newText))
228234
logm $ "makeRefactorResult:diffops = " ++ show (diffToLineRanges $ getGroupedDiff (lines $ T.unpack origText) (lines $ T.unpack newText))

0 commit comments

Comments
 (0)