@@ -18,6 +18,7 @@ import Data.Foldable
18
18
import Data.Monoid
19
19
#endif
20
20
import qualified Data.Text as T
21
+ import qualified Data.Text.IO as T
21
22
import Exception
22
23
import GHC.Generics (Generic )
23
24
import Haskell.Ide.Engine.ArtifactMap
@@ -213,16 +214,21 @@ makeRefactorResult changedFiles = do
213
214
uri <- canonicalizeUri $ filePathToUri fp
214
215
mvf <- getVirtualFile uri
215
216
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
226
232
-- TODO: remove this logging once we are sure we have a working solution
227
233
logm $ " makeRefactorResult:groupedDiff = " ++ show (getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
228
234
logm $ " makeRefactorResult:diffops = " ++ show (diffToLineRanges $ getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
0 commit comments