Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write interface to disk if no errors were found #81

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Curry/LanguageServer/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import qualified Curry.Frontend.Modules as CMD
import qualified Curry.Frontend.Transformations as CT
import qualified Text.PrettyPrint as PP

import Control.Monad (join)
import Control.Monad (join, when)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Reader (ReaderT (..))
import Control.Monad.Trans.State (StateT (..))
import Control.Monad.Trans.Maybe (MaybeT (..))
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Reader.Class (asks)
import Control.Monad.State.Class (modify)
import Control.Monad.State.Class (modify, gets)
import qualified Curry.LanguageServer.Config as CFG
import Curry.LanguageServer.Utils.Convert (ppToText)
import Curry.LanguageServer.Utils.General ((<.$>))
Expand Down Expand Up @@ -145,13 +145,15 @@ compileCurryModule opts outDirPath m fp = do
liftToCM $ debugM $ "Compiling module " <> T.pack (takeFileName fp)
-- Parse and check the module
mdl <- loadAndCheckCurryModule opts m fp
-- Generate and store an on-disk interface file
mdl' <- CC.expandExports opts mdl
interf <- liftCYIO $ uncurry (CEX.exportInterface opts) $ CT.qual mdl'
let interfFilePath = outDirPath </> CFN.interfName (CFN.moduleNameToFile m)
generated = PP.render $ CS.pPrint interf
liftToCM $ debugM $ "Writing interface file to " <> T.pack interfFilePath
liftIO $ CF.writeModule interfFilePath generated
errs <- gets (.errors)
when (null errs) $ do
-- Generate and store an on-disk interface file
mdl' <- CC.expandExports opts mdl
interf <- liftCYIO $ uncurry (CEX.exportInterface opts) $ CT.qual mdl'
let interfFilePath = outDirPath </> CFN.interfName (CFN.moduleNameToFile m)
generated = PP.render $ CS.pPrint interf
liftToCM $ debugM $ "Writing interface file to " <> T.pack interfFilePath
liftIO $ CF.writeModule interfFilePath generated
return [(fp, mdl)]

-- The following functions partially reimplement
Expand All @@ -167,7 +169,7 @@ compileCurryModule opts outDirPath m fp = do
-- 2018 Kai-Oliver Prott

-- | Loads a single module and performs checks.
loadAndCheckCurryModule :: MonadIO m => CO.Options -> CI.ModuleIdent -> FilePath -> CMT m (CE.CompEnv ModuleAST)
loadAndCheckCurryModule :: (MonadIO m, MonadLsp CFG.Config m) => CO.Options -> CI.ModuleIdent -> FilePath -> CMT m (CE.CompEnv ModuleAST)
loadAndCheckCurryModule opts m fp = do
-- Read source file (possibly from VFS)
fl <- asks (.fileLoader)
Expand Down
Loading