@@ -18,7 +18,6 @@ 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
22
21
import Exception
23
22
import GHC.Generics (Generic )
24
23
import Haskell.Ide.Engine.ArtifactMap
@@ -206,27 +205,34 @@ getRefactorResult = map getNewFile . filter fileModified
206
205
where fileModified ((_,m),_) = m == RefacModified
207
206
getNewFile ((file,_),(ann, parsed)) = (file, T. pack $ exactPrint parsed ann)
208
207
209
- makeRefactorResult :: [(FilePath ,T. Text )] -> IdeGhcM WorkspaceEdit
208
+ makeRefactorResult :: [(FilePath ,T. Text )] -> IdeGhcM ( IdeResult WorkspaceEdit )
210
209
makeRefactorResult changedFiles = do
211
210
let
212
- diffOne :: (FilePath , T. Text ) -> IdeGhcM WorkspaceEdit
211
+ diffOne :: (FilePath , T. Text ) -> IdeGhcM ( IdeResult WorkspaceEdit )
213
212
diffOne (fp, newText) = do
214
213
uri <- canonicalizeUri $ filePathToUri fp
215
214
mvf <- getVirtualFile uri
216
- let resultFail = return $ IdeResultFail
217
- (IdeError PluginError
218
- (T. pack " makeRefactorResult: no access to the persisted file." )
219
- Null
220
- )
221
- origText <- case mvf of
222
- Nothing -> withMappedFile fp resultFail $ liftIO . T. readFile
223
- Just vf -> pure (Rope. toText $ _text vf)
224
- -- TODO: remove this logging once we are sure we have a working solution
225
- logm $ " makeRefactorResult:groupedDiff = " ++ show (getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
226
- logm $ " makeRefactorResult:diffops = " ++ show (diffToLineRanges $ getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
227
- liftToGhc $ diffText (filePathToUri fp, origText) newText IncludeDeletions
228
- diffs <- mapM diffOne changedFiles
229
- return $ Core. reverseSortEdit $ fold diffs
215
+
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
226
+ -- TODO: remove this logging once we are sure we have a working solution
227
+ logm $ " makeRefactorResult:groupedDiff = " ++ show (getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
228
+ logm $ " makeRefactorResult:diffops = " ++ show (diffToLineRanges $ getGroupedDiff (lines $ T. unpack origText) (lines $ T. unpack newText))
229
+ liftToGhc $ IdeResultOk <$> diffText (filePathToUri fp, origText) newText IncludeDeletions
230
+
231
+ diffResults <- mapM diffOne changedFiles
232
+ let diffs = sequenceA diffResults
233
+ case diffs of
234
+ IdeResultOk diffs' -> return $ IdeResultOk $ Core. reverseSortEdit $ fold diffs'
235
+ IdeResultFail err -> return $ IdeResultFail err
230
236
231
237
-- ---------------------------------------------------------------------
232
238
@@ -242,8 +248,7 @@ runHareCommand name cmd = do
242
248
Null ))
243
249
Right res -> do
244
250
let changes = getRefactorResult res
245
- refactRes <- makeRefactorResult changes
246
- pure (IdeResultOk refactRes)
251
+ makeRefactorResult changes
247
252
248
253
-- ---------------------------------------------------------------------
249
254
0 commit comments