-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Hi, we added recently hlint support in haskell-language-server, including the apply of refactorings usgins appy-refact, via applyRefactorings
The actual integration could be improved if the api would expose a function to apply them to an already parsed module.
Now we have to use a temporary file and ask apply-refact to parse it again:
res <- liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do
hClose h
writeFileUTF8NoNewLineTranslation temp oldContent
(Right <$> applyRefactorings Nothing commands temp) `catches`
[ Handler $ \e -> return (Left (show (e :: IOException)))
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
]As we are using ghc-lib to parse for ghc < 8.10 and the real ghc for 8.10, following hlint, maybe only we can take advantage in the latter path, but i think it still will worth it.
Refact.Internal.runRefactoring is exposed but maybe a higher endpoint, closer to applyRefactorings would be handy for downstream packages.
For ghc < 8.10 we will continue to need delegate the parsing to apply-refact. In that case it would be handy be able to inform the parser option, to, for example, pass custom language extensions not included in the module as pragmas.
Let me know if you think that should be in another issue.
//cc @ndmitchell @alanz